[go: up one dir, main page]

0% found this document useful (0 votes)
33 views2 pages

Assignment. Objects and Classes

Assignment

Uploaded by

amidmans1980
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
33 views2 pages

Assignment. Objects and Classes

Assignment

Uploaded by

amidmans1980
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 2

#include <iostream>

#include <cmath>

using namespace std;

class GeometryCalculator {

public:

// Function to calculate the area of a trapezium

double calculateTrapeziumArea(double base1, double base2, double height) {

return 0.5 * (base1 + base2) * height;

// Function to calculate the average of five values

double calculateAverage(int value1, int value2, int value3, int value4, int value5) {

return static_cast<double>(value1 + value2 + value3 + value4 + value5) / 5.0;

// Function to calculate the area of a triangle

double calculateTriangleArea(double base, double height) {

return 0.5 * base * height;

};

int main() {

GeometryCalculator calculator;

// a. Calculate the area of a trapezium

double trapeziumArea = calculator.calculateTrapeziumArea(8.5, 12.3, 4.7);

cout << "Area of Trapezium: " << trapeziumArea << " square units" << endl;
// b. Calculate the average of five values

double average = calculator.calculateAverage(15, 8, 18, 24, 32);

cout << "Average of five values: " << average << endl;

// c. Calculate the area of a triangle

double triangleArea = calculator.calculateTriangleArea(6.2, 9.4);

cout << "Area of Triangle: " << triangleArea << " square units" << endl;

return 0;

You might also like