//preprocessor directives #include #include // needed for using abs() function using namespace std; // function prototypes double ComputeTriangleArea (double length, double width); void OutputComputeAbsoluteDifference (double area1, double area2); // main function int main() { // Parameter Declarations double width1, width2, length1, length2; double area1, area2; // LOGO cout << "----------------------------------------------------------" << endl; cout << " CS135 Lab Quiz 2: Area Difference Computation " << endl; cout << " By Chang Jia " << endl; cout << "----------------------------------------------------------" << endl; cout << endl; // Get Inputs cout << "Please enter the length of the first triangle: "; cin >> length1; cout << "Please enter the width of the first triangle: "; cin >> width1; cout << "Please enter the length of the second trianle: "; cin >> length2; cout << "Please enter the width of the second trianle: "; cin >> width2; cout << endl; // Do computations by calling functions area1 = ComputeTriangleArea(length1, width1); area2 = ComputeTriangleArea(length2, width2); // Print Outputs cout << "The area of the first triangle is: " << area1 << endl; cout << "The area of the second trianle is: " << area2 << endl; cout << "The absolute difference of the two triangles is: "; OutputComputeAbsoluteDifference (area1, area2); cout << endl; system("PAUSE"); return 0; } //function bodies //function to compute area of triangle double ComputeTriangleArea (double length, double width) { double area_of_triange; area_of_triange = length * width / 2.0; return area_of_triange; } //funtion to compute absolute difference of the two areas void OutputComputeAbsoluteDifference (double area1, double area2) { double difference; // Use abs() function difference = abs(area1 - area2); cout << difference; return; } /* Test Run: ---------------------------------------------------------- CS135 Lab Quiz 2: Area Difference Computation By Chang Jia ---------------------------------------------------------- Please enter the length of the first triangle: 3 Please enter the width of the first triangle: 4 Please enter the length of the second trianle: 5 Please enter the width of the second trianle: 5 The area of the first triangle is: 6 The area of the second trianle is: 12.5 The absolute difference of the two triangles is: 6.5 Press any key to continue . . . */