Below is my problem...
Here is my code...
#include<iostream>
#include<iomanip> //allows me to use setflags/showpoint and set precision
#include <stdlib.h> //for exit(1)
#include <fstream>
# include <stdlib.h>
# include <cstdlib>
using namespace std;
int main()
{
double s1, s2, s3;
ifstream inf;
inf.open ("C:\\CS201HWASSGN6INPUTFILE.txt", ios::in);
ifstream infile("C:\\CS201HWASSGN6INPUTFILE.txt", ios::in);
//Input file open and use
if(!infile)
{
cerr<<"Input file could not be opened"<<endl;
// Error Trap - end program if input file does not open
exit(1);
}
ofstream outfile("c:\\CS201HWASSGN6OUTPUTFILE.txt", ios::out);
//Output file
if ( ! outfile )
{
cerr << "Output file could not be opened" << endl;
//Error Trap - end program if output file does not open
exit(1);
}
outfile << setiosflags(ios::fixed | ios::showpoint);
outfile << setprecision(3);
cout<<setiosflags(ios::fixed |ios::showpoint);
cout<<setprecision(3);
//set precision 3 means the
//output will show 3 places after the dpoint 18.000
infile>>s1; s2; s3;
{cout<<setw(25)<<"Sides: "<< setw(35)
<<"Triangle? "<< setw(40)
<<"Perimeter: "<<setw(45)
<<"Area "<< endl<< endl;
cout<<setw(10) <<s1<< s2<<s3<<endl;}
{outfile <<setw(10)<<"Sides: "<< setw(20)
<<"Triangle? "<< setw(30)
<<"Perimeter: "<<setw(40)
<<"Area "<< endl<< endl;
outfile<<setw(10) <<s1<< s2<<s3<<endl;}
system("\t\t\tPAUSE"); //this allows my screen to pause
infile.close();
outfile.close();
return 0;
}
Write a C++ program which will read an undetermined number of real number triplets from an external data file. These triplets represent the 3 possible sides of a triangle.
Your program will:
1. Determine if the sides do in fact form a triangle.
** The sum of any two sides must be greater
than the third side
2. If the triangle is possible, then calculate the perimeter correct to 3
decimal places.
** perim = a + b + c
3. If the triangle is possible then calculate the area, correct to 3 decimal
places, using Heron's formula:
** area = sqrt(s * (s - a) * (s - b) * (s - c))
where s = (a + b + c) / 2
Include the <math.h> or <cmath> library in order to have access to the sqrt() function (which has an argument and return type of double).
The output should be in tabular form. For example:
Sides Triangle? Perimeter Area
1.000 2.000 3.000 false
3.000 4.000 5.000 true 12.000 6.000
You must include four programmer defined functions whose prototypes are:
bool isATriangle(const double s1, const double s2, const double s3),
double semiPerimeter(const double s1, const double s2, const double s3)
double perimeter(const double s1, const double s2, const double s3)
double area(const double s1, const double s2, const double s3)
The function area() should call the function semiPerimeter() .The sides, perimeter and area should be correct to 3 decimal places. Please show the decimal values even
if they are zeros. Use the stream manipulators setw(), setprecision() and setiosflags() in order to align and guarantee the correct number of decimal places in your output and also use the manipulator boolalpha in order to print true/false in the Triangle? column.
You may include additional functions if you desire. You may want to include the
following code segment to control the while loop:
while (inf>>side1>>side2>>side3)
{ <body of loop> }
where inf is the programmer defined external input file object.
Create an external formatted data file containing the following data set:
3.0 4.0 5.0
1.0 2.0 3.0
2.0 2.0 3.9
5.12 6.33 10.69
3.45 2.91 6.77
8.0 12.0 13.0
2.9 2.9 2.9
9 10 2