day 21 Hw
#include <iostream>
#include <cmath>
#include<fstream>
#include<string>
using namespace std;
int main(void)
{
// fstream unknownf;
// unknownf.open("unknownf.txt",ios::in | ios::out);
//
// if (!unknownf.is_open())
// {
// cout << " File didn't open";
// }
//else
//{
// char word[50];
// unknownf << word;
// while(unknownf.good())
// {
//
// }
//
//
//unknownf.close();
//}
//Declare and initialize variables.
int n;
double unknown[5],
known[5]={6.2,7.0,8.0,7.4,5.8};
double distance(double hand_1[5],double hand_2[5]);
// Compute and print distance.
for(n=0;n<5;n++)
{
cout << "Enter elements:" << endl;
cin >> unknown[n];
}
fstream unknownf;
unknownf.open("unknownf.txt",ios::in | ios::out);
if (!unknownf.is_open())
{
cout << " File didn't open";
}
else
{
char word[50];
unknownf << word;
int i=0;
while(unknownf.good())
{
known[i];
i++;
cout <<"HI;";
}
unknownf.close();
}
cout << "Distance: " << distance(unknown,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;
}
#include <cmath>
#include<fstream>
#include<string>
using namespace std;
int main(void)
{
// fstream unknownf;
// unknownf.open("unknownf.txt",ios::in | ios::out);
//
// if (!unknownf.is_open())
// {
// cout << " File didn't open";
// }
//else
//{
// char word[50];
// unknownf << word;
// while(unknownf.good())
// {
//
// }
//
//
//unknownf.close();
//}
//Declare and initialize variables.
int n;
double unknown[5],
known[5]={6.2,7.0,8.0,7.4,5.8};
double distance(double hand_1[5],double hand_2[5]);
// Compute and print distance.
for(n=0;n<5;n++)
{
cout << "Enter elements:" << endl;
cin >> unknown[n];
}
fstream unknownf;
unknownf.open("unknownf.txt",ios::in | ios::out);
if (!unknownf.is_open())
{
cout << " File didn't open";
}
else
{
char word[50];
unknownf << word;
int i=0;
while(unknownf.good())
{
known[i];
i++;
cout <<"HI;";
}
unknownf.close();
}
cout << "Distance: " << distance(unknown,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;
}
Comments
Post a Comment