0% found this document useful (0 votes)
4 views

Program Assignment

The document contains multiple C++ programs that perform various mathematical calculations, including the surface area and volume of a rectangular box, sum and average of integers, volume of a cylinder, temperature conversion, work done by a force, electric power consumption, area and circumference of a circle, and square root of a number. Each program prompts the user for input, performs the calculation, and outputs the result. Example outputs for each program are also provided.

Uploaded by

catoskt1
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views

Program Assignment

The document contains multiple C++ programs that perform various mathematical calculations, including the surface area and volume of a rectangular box, sum and average of integers, volume of a cylinder, temperature conversion, work done by a force, electric power consumption, area and circumference of a circle, and square root of a number. Each program prompts the user for input, performs the calculation, and outputs the result. Example outputs for each program are also provided.

Uploaded by

catoskt1
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 8

1.

Surface Area and Volume of a Rectangular Box

#include <iostream>

using namespace std;

int main() {

double a, b, c;

cout << "Enter the sides of the rectangular box (a, b, c): ";

cin >> a >> b >> c;

double surfaceArea = 2 * (a * b + b * c + c * a);

double volume = a * b * c;

cout << "Surface Area: " << surfaceArea << endl;

cout << "Volume: " << volume << endl;

return 0;

1_Output:

Enter the sides of the rectangular box (a, b, c): 2

Surface Area: 52

Volume: 24
2. Sum and Average of 10 Integers

#include <iostream>

using namespace std;

int main() {

int numbers[10], sum = 0;

cout << "Enter 10 integers: ";

for (int i = 0; i < 10; i++) {

cin >> numbers[i];

sum += numbers[i];

double average = sum / 10.0;

cout << "Sum: " << sum << endl;

cout << "Average: " << average << endl;

return 0;

2_Output:

Enter 10 integers: 1

5
6

Sum: 51

Average: 5.1

3. Volume of a Cylinder

#include <iostream>

#include <cmath>

using namespace std;

int main() {

double radius, height;

cout << "Enter the radius and height of the cylinder: ";

cin >> radius >> height;

double volume = M_PI * radius * radius * height;

cout << "Volume: " << volume << endl;

return 0;

}
3_Output :

Enter the radius and height of the cylinder: 4

Volume: 251.327

4. Fahrenheit to Celsius Conversion

#include <iostream>

using namespace std;

int main() {

double fahrenheit;

cout << "Enter temperature in Fahrenheit: ";

cin >> fahrenheit;

double celsius = (fahrenheit - 32) * 5 / 9;

cout << "Temperature in Celsius: " << celsius << endl;

return 0;

4_Output:

Enter temperature in Fahrenheit: 98

Temperature in Celsius: 36.6667


5. Work Done by a Force

#include <iostream>

using namespace std;

int main() {

double force, displacement;

cout << "Enter the force and displacement: ";

cin >> force >> displacement;

double work = force * displacement;

cout << "Work Done: " << work << endl;

return 0;

5_Output:

Enter the force and displacement: 12

30

Work Done: 360

6. Electric Power Consumption

#include <iostream>

using namespace std;


int main() {

double voltage, current;

cout << "Enter the voltage and current: ";

cin >> voltage >> current;

double power = voltage * current;

cout << "Electric Power: " << power << endl;

return 0;

6_Output:

Enter the voltage and current: 10

15

Electric Power: 150

7. Area and Circumference of a Circle

#include <iostream>

#include <cmath>

using namespace std;

int main() {

double radius;
cout << "Enter the radius of the circle: ";

cin >> radius;

double area = M_PI * radius * radius;

double circumference = 2 * M_PI * radius;

cout << "Area: " << area << endl;

cout << "Circumference: " << circumference << endl;

return 0;

7_Output:

Enter the radius of the circle: 20

Area: 1256.64

Circumference: 125.664

8. Square Root of a Number

#include <iostream>

#include <cmath>

using namespace std;

int main() {

double number;
cout << "Enter a number: ";

cin >> number;

double squareRoot = sqrt(number);

cout << "Square Root: " << squareRoot << endl;

return 0;

8_Output:

Enter a number: 5

Square Root: 2.23607

You might also like