Assignment purpose: simple i/o in C++, simple math in C++, simple loop, data types string, double, and int, formatting output in C++, predefined functions, programmer defined functions, call by reference and call by value.
Write a program that will calculate the area and perimeter of a triangle and the area and perimeter of a rectangle
Here is the main function:
int main()
{
double area = 0.0;
double perimeter;
string quit;
string name;
cout << "Welcome to the area and perimeter calculator, what is your first name? ";
cin >> name;
cout.setf(ios::fixed);
cout.setf(ios::showpoint);
cout.precision(3); //display the area to 3 decimal places
MenuChoices(name, quit);
ProcessChoice(quit, area, perimeter);
while (quit != "Q" && quit != "q")
{
cout << "\nThe area (displayed in the main function) is " << area << endl;
cout << "\nThe perimeter (displayed in the main function) is " << perimeter << endl;
MenuChoices(name, quit);
ProcessChoice(quit, area, perimeter);
}
cout << "\nGoodbye " << name << ", Have a great day! ";
return 0;
}
Additional instructions:
Write the algorithm before implementing the program
Be sure to test throughout the code development
Follow all style rules and include all necessary documentation
The area of an arbitrary triangle can be computed using the following formula:
area =sqrt(s(s - a)(s - b)(s - c))
Where a, b, and c are the lengths of the sides and s is the semiperimeter.
s = (a + b + c) / 2
Note that not all combinations of a, b, and c produce a triangle.
NOTE: The perimeter is NOT the same as the semiperimeter
Here is sample output
Welcome to the area and perimeter calculator, what is your first name? Tami
----------------------------------------------
Tami, please enter a T, R, or Q.
To calculate:
The area and perimeter of a triangle, enter T
The area and perimeter of a rectangle, enter R
----------------------------------------------
Enter Q to quit: w
That input is not recognized
The area (displayed in the main function) is 0.000
The perimeter (displayed in the main function) is 0.000
----------------------------------------------
Tami, please enter a T, R, or Q.
To calculate:
The area and perimeter of a triangle, enter T
The area and perimeter of a rectangle, enter R
----------------------------------------------
Enter Q to quit: t
*********************************************
Enter the length of side one: 9.21
Enter the length of side two: 3.3
Enter the length of side three: 2.76
Not a valid triangle
The area (displayed in the main function) is 0.000
The perimeter (displayed in the main function) is 0.000
----------------------------------------------
Tami, please enter a T, R, or Q.
To calculate:
The area and perimeter of a triangle, enter T
The area and perimeter of a rectangle, enter R
----------------------------------------------
Enter Q to quit: t
*********************************************
Enter the length of side one: 3.78
Enter the length of side two: 2.43
Enter the length of side three: 4.12
------------------------------------
Side A Side B Side C
3.8 2.4 4.1
The area (displayed in the main function) is 4.522
The perimeter (displayed in the main function) is 10.330
----------------------------------------------
Tami, please enter a T, R, or Q.
To calculate:
The area and perimeter of a triangle, enter T
The area and perimeter of a rectangle, enter R
----------------------------------------------
Enter Q to quit: r
Enter the length of side one: 1.345
Enter the length of side two: 82.911
------------------------------------
Side X Side Y
1.3 82.9
The area (displayed in the main function) is 111.515
The perimeter (displayed in the main function) is 168.512
----------------------------------------------
Tami, please enter a T, R, or Q.
To calculate:
The area and perimeter of a triangle, enter T
The area and perimeter of a rectangle, enter R
----------------------------------------------
Enter Q to quit: q
Goodbye Tami, Have a great day!