For this program, is it possible to set the output of distance to the precision of 5 decimal places and meanwhile set the output of other values to the precision of 1 decimal place?
#include
#include
#include
#include
using namespace std;
struct point{
double X;
double Y;
};
double dist(struct point A, struct point B)
{
return sqrt(pow((A.X-B.X),2) + pow((A.Y-B.Y),2));
}
int main(){
ifstream input_file;
ofstream output_file;
input_file.open("D:\Qianhui\Value.txt");
output_file.open("output.txt");
if(input_file)
{
cout << "Mo error in reading file.nn";
}
else
{
cout << "Stream error.Can not read the filenn";
exit(1);
}
struct point P1, P2;
int lines = 8;
output_file << "X1tY1tX2tY2tDistance" << endl;
while (lines-- > 0)
{
input_file >> P1.X >> P1.Y >> P2.X >> P2.Y;
output_file << P1.X << "t" << P1.Y << "t" << P2.X << "t" << P2.Y << "t" << dist(P1,P2) << endl;
}
input_file.close();
output_file.close();
return 0;
}