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 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77
|
#include <iostream>
#include <iomanip> //using setprecision(1)
#include <math.h>
using namespace std;
//functions
double findArea(double sideOne, double sideTwo);
double findPerimeter(double sideOne, double sideTwo);
double findDiagonal(double sideOne, double sideTwo);
void display(double sideOne, double sideTwo, double area, double perimeter, double diagonal);
//Main
int main()
{ //Variables
double sideOne, sideTwo;
//Gathering the number for boths sides from the user
cout << "Please enter the length of side one." << endl;
cin >> sideOne;
cout << "\nPlease enter the length of the side two." << endl;
cin >> sideTwo;
//Validating that the values are greater than zero
if (sideOne <=0 || sideTwo <= 0)
{
cout << "Both values for the length need to be greater than zero." << endl;
exit(0);
}
//setting precision to one decimal place
cout << fixed << setprecision(1);
// Declaring the variable area and invoking the findArea function to calculate and assign the value
double area = findArea(sideOne,sideTwo);
//Invoking the perimeter function and outputting value
double perimeter = findPerimeter(sideOne,sideTwo);
//Invoking diagnal function
double diagonal = findDiagonal(sideOne,sideTwo);
void display(area, perimeter, diagonal);
{
cout << area << endl; // this line is just here for testing. Definitely wrong.
}
return 0;
}
//Calculating Area
double findArea( double sideOne, double sideTwo)
{
double area = sideOne * sideTwo;
return area;
}
//Calculating Perimeter
double findPerimeter(double sideOne, double sideTwo)
{
double perimeter = ((sideOne * 2) + (sideTwo * 2));
return perimeter;
}
//Calculating diagnal
double findDiagonal(double sideOne, double sideTwo)
{
double diagonalTotal = ((sideOne *sideOne) + (sideTwo*sideTwo));
double diagonal = pow(diagonalTotal,0.5);
return diagonal;
}
void display(double sideOne, double sideTwo, double area, double perimeter, double diagonal)
{
cout << "The area is: " << area << endl << endl;
cout << "The perimeter is: " << perimeter << endl<< endl;
cout << "The diagonal is: " << diagonal << endl;
}
|