My assignment: "Write a C++ program to do the following: The main program reads in three integers,
representing the degree measurement of three angles of a triangle and sends them to a function.
If the function says that the three integers form a valid triangle, the main program calls
another function to classify the triangle. After repeating this process for the entire set of
data, the main program prints out how many groups formed valid triangles and how many formed
invalid ones.
The first function, which checks for validity, uses the following rule: The three angles form
a valid triangle if they add up to 180 and each one is greater than 0. For example 70, 60 and 50
is valid while 120, 80, and -20 is invalid.
The classification function calls two additional functions. One of them determines if the
triangle is equiangular (all three angles are equal), isosceles (exactly two angles are equal),
or scalene (all three angles different). The other function determines if the triangle is right
has one angle with 90 degrees), obtuse (one angle above 90), or acute (all three below 90).
Be sure to cover all the possible combinations and to include some invalid triangles as well.
Make sure your name appears on the printout.
You should create a well formatted report indicating whether or not the set of angles is valid
or not. If they are valid then classify the triangles as to whether it is equiangular, isosceles
or scalene, and whether it has an obtuse angle, right angle or is acute."
Right now, the main problem I'm aware of is that in the bolded part, "validity" is incorrect because "no instance of overloaded function 'validity' matches the argument list."
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61
|
#include <iostream>
#include <fstream>
#include <string>
#include <iomanip>
using namespace std;
ifstream infile;
ofstream outfile;
int classify(ofstream&, int, int, int);
int validity(ofstream&, int, int, int);
void type();
void kind();
int main()
{
int angle1;
int angle2;
int angle3;
int validtriangles;
int invalidtriangles;
string valid;
string type;
string kind;
infile.open("infile.txt");
outfile.open("outfile.txt");
if (!infile)
{
cout << "Cannot open." << endl;
}
outfile << "Angle 1 Angle 2 Angle 3 Status Type Kind" << endl;
while (!infile.eof())
{
infile >> angle1 >> angle2 >> angle3;
return angle1;
return angle2;
return angle3;
classify();
outfile << " " << angle1 << " " << angle2 << " " << angle3 << " " << valid << " " << type << " " << kind << endl;
}
validtriangles = validity();
invalidtriangles = validity();
outfile << endl;
outfile << validtriangles << " valid triangles." << endl;
outfile << invalidtriangles << " invalid triangles" << endl;
infile.close();
outfile.close();
return 0;
}
|