Lab 24/ HW 24
Lab 24 (MPU):
#include <iostream>
#include <cmath>
#include <fstream>
#define FILENAME "fingerprints.txt"
using namespace std;
int main(void)
{
//Declare and initialize variables.
int k = 0, min_num = 0;
float min_dist = 100.0;
string hand[5] = {"Thumb", "Index Finger", "Middle Finger", "Ring Finger", "Pinky Finger"};
double unknown[5], known[5];
cout << "Enter distance of thumb" << endl;
cin >> unknown[0];
cout << "Enter distance of index finger" << endl;
cin >> unknown[1];
cout << "Enter distance of middle finger" << endl;
cin >> unknown[2];
cout << "Enter distance of ring finger" << endl;
cin >> unknown[3];
cout << "Enter distance of pinky finger" << endl;
cin >> unknown[4];
ifstream prints;
prints.open(FILENAME);
if (prints.fail())
{
cout << "Error opening input file." << endl;
}
else
{
while (!prints.eof()) //while not at the end of file
{
prints >> known[k];
cout << "Known and Unknown " << hand[k] << " measurements: " << known[k] << " cm" << " & "
<< unknown[k] << " cm" << endl;
cout << hand[k] << " difference: " << fabs(known[k] - unknown[k]) << " cm" << endl;
if ((fabs(known[k] - unknown[k])) < min_dist)
{
min_dist = (fabs(known[k] - unknown[k]));
min_num = k;
}
k++;
}
cout << endl << hand[min_num] << "s have the best match." << endl;
cout << "Minimum Distance: " << min_dist << " cm" << endl;
}
double distance(double hand_1[5],double hand_2[5]);
// Compute and print distance.
cout << "Sum Distance: " << distance(unknown,known) << " cm" << endl;
//close text file
prints.close();
// Exit program.
return 0
;
}
//-----------------------------------------------------------------
// This function computes the distance between two hand measurements.
double distance(double hand_1[5],double hand_2[5])
{
// Declare variables.
int k;
double sum=0;
// Compute sum of absolute value differences.
for (k=0; k<=4; k++)
sum = sum + fabs(hand_1[k]-hand_2[k]);
// Return distance value.
return sum;
}
#include <cmath>
#include <fstream>
#define FILENAME "fingerprints.txt"
using namespace std;
int main(void)
{
//Declare and initialize variables.
int k = 0, min_num = 0;
float min_dist = 100.0;
string hand[5] = {"Thumb", "Index Finger", "Middle Finger", "Ring Finger", "Pinky Finger"};
double unknown[5], known[5];
cout << "Enter distance of thumb" << endl;
cin >> unknown[0];
cout << "Enter distance of index finger" << endl;
cin >> unknown[1];
cout << "Enter distance of middle finger" << endl;
cin >> unknown[2];
cout << "Enter distance of ring finger" << endl;
cin >> unknown[3];
cout << "Enter distance of pinky finger" << endl;
cin >> unknown[4];
ifstream prints;
prints.open(FILENAME);
if (prints.fail())
{
cout << "Error opening input file." << endl;
}
else
{
while (!prints.eof()) //while not at the end of file
{
prints >> known[k];
cout << "Known and Unknown " << hand[k] << " measurements: " << known[k] << " cm" << " & "
<< unknown[k] << " cm" << endl;
cout << hand[k] << " difference: " << fabs(known[k] - unknown[k]) << " cm" << endl;
if ((fabs(known[k] - unknown[k])) < min_dist)
{
min_dist = (fabs(known[k] - unknown[k]));
min_num = k;
}
k++;
}
cout << endl << hand[min_num] << "s have the best match." << endl;
cout << "Minimum Distance: " << min_dist << " cm" << endl;
}
double distance(double hand_1[5],double hand_2[5]);
// Compute and print distance.
cout << "Sum Distance: " << distance(unknown,known) << " cm" << endl;
//close text file
prints.close();
// Exit program.
return 0
;
}
//-----------------------------------------------------------------
// This function computes the distance between two hand measurements.
double distance(double hand_1[5],double hand_2[5])
{
// Declare variables.
int k;
double sum=0;
// Compute sum of absolute value differences.
for (k=0; k<=4; k++)
sum = sum + fabs(hand_1[k]-hand_2[k]);
// Return distance value.
return sum;
}
HW 24 (C++ Classes):
#ifndef DATE_H
#define DATE_H
class Date
{
public:
void setDate(int setmonth, int setday, int setyear);
void printDate();
void printStringDate();
private:
int month;
int day;
int year;
};
#endif // DATE_H
#define DATE_H
class Date
{
public:
void setDate(int setmonth, int setday, int setyear);
void printDate();
void printStringDate();
private:
int month;
int day;
int year;
};
#endif // DATE_H
#include <iostream>
using namespace std;
void Date::setDate(int setmonth, int setday, int setyear)
{
month = setmonth;
day = setday;
year = setyear;
}
void Date::printDate()
{
cout << "(" << month << "/" << day << "/" << year << ")" << endl;
}
void Date::printStringDate()
{
string months[12] = {"January","February","March","April","May","June",
"July","August","September","October","November","December"};
cout << "(" << months[month - 1] << "/" << day << "/" << year << ")" << endl;
}
#include <iostream>
#include "Date.h"
using namespace std;
int main()
{
Date date;
int month, day, year;
cout << "Enter Month:" << endl;
cin >> month;
cout << "Enter Day of Month:" << endl;
cin >> day;
cout << "Enter Year:" << endl;
cin >> year;
date.setDate(month, day, year);
date.printDate();
date.printStringDate();
return 0;
}
Comments
Post a Comment