Lab 23/ HW 23
Lab/HW 23 (C++ Fingerprint):
#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 <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;
}
Comments
Post a Comment