Thursday, December 13, 2018

handprint

#include <iostream>
#include <cmath>
using namespace std;
#define FILENAME "handprint.txt"

int main(void)
{
const int N=20;
int k=0, npts=N;
double y[N];
//Declare and initialize variables.
//double unknown[5]={5.4,7.2,7.9,7.4,5.1},
double known[5]={6.2,7.0,8.0,7.4,5.8},
//test[5]={};
double distance(double hand_1[5],double hand_2[5]);
ifstream handprint;
// Open file, read data into an array.
handprint.open(FILENAME);
if (handprint.fail())
cout << "Error opening input file." << endl;
else
{
while (!handprint.eof())
{
handprint >> y[k];
k++;
}
npts = k;
// Find and print the maximum value.

// Compute and print distance.
cout << "Enter distances for each digit starting with the thumb:" << endl;
/*for (int i = 0; i < 5; i++)
{cin >> test[i];}*/

cout << "Distance: " << distance(y,known) << endl;
// 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;
}

No comments:

Post a Comment