case 1. how to create the area of a circle using a c++ program
case 2. area of a triangle
case 3. area of square
case 4. area of a cylinder
case 5. payroll calculator
case 6. bmi calculator
case 7. currency convertor
case 8. grading system
case 9. the almighty formula
#include <iostream>
#include <cmath>
using namespace std;
int main()
{
int num;
cout<<"enter number from 1 to 9 \n";
cin>>num;
switch(num){
case 1:
float radius;
float area_circle;
cout<<"enter the radius of the circle: ";
cin>>radius;
area_circle = 3.14*radius*radius;
cout<<"Area of circle: " <<area_circle <<endl;
break;
OUTPUT
enter number from 1 to 9
1
enter the radius of the circle: 10
Area of circle: 314
case 2:
int height;
int base;
float ans;
cout<<"enter height \n";
cin>>height;
cout<<"enter base: \n";
cin>>base;
ans =(0.5)*height*base;
cout<<"Area of triangle is: " <<ans <<endl;
break;
OUTPUT
enter number from 1 to 9
2
enter height
10
enter base:
5
Area of triangle is: 25
case 3:
int length;
int width;
cout<<"enter length";
cin>>length;
cout<<"enter width";
cin>>width;
ans = length * width;
cout<<"Area of square: " <<ans <<endl;
break;
OUTPUT
enter number from 1 to 9
3
enter length10
enter width10
Area of square: 100
case 4:
cout<<"enter height";
cin>>height;
cout<<"enter radius";
cin>>radius;
ans = 2*3.14*radius*(height+radius);
cout<<"Area of cylinder is: " <<ans <<endl;
break;
OUTPUT
enter number from 1 to 9
4 enter height5
enter radius5
Area of cylinder is: 314
case 5:
int hours;
int rate;
int pay;
cout<<"enter hours of work";
cin>>hours;
cout<<"enter rate";
cin>>rate;
pay = hours *rate; if(10 < hours) {pay += (hours - 10)* (rate/2)
cout<<"your pay is: " <<pay <<endl;
break;
OUTPUT
enter number from 1 to 9
5
enter hours of work10
enter rate100
your pay is: 1000
case 6:
double weight_pounds;
double height_inches;
double bmi;
cout<<"enter your weight in inches: ";
cin>>weight_pounds;
cout<<"enter your height in pounds ";
cin>>height_inches;
bmi = (weight_pounds/(pow(height_inches,2)))*703;
cout<<"your Bmi is: "<<bmi <<endl;
break;
OUTPUT
enter number from 1 to 9
6
enter your weight in inches: 10
enter your height in pounds 100
your Bmi is: 0.703
case 7 :
double dollar;
double Pounds;
Pounds =(1/1.48)
cout<<"enter the amount of dollar you want to change: ";
cin>>dollar;
cout<<"british pounds:" <<Pounds*dollar <<endl;
break;
OUTPUT
enter number from 1 to 9
7
enter the amount of dollar you want to change: 1000
british pounds:675.676
case 8 :
int value;
cout<<"enter value: "
cin>>value; if(value<=50){
cout<<"you had F"; }
else if(value>50 && value <55){
cout<<"you had E "; }
else if(value>55 && value <60){
cout<<"you had D "; }
else if(value>60 && value <70){
cout<<"you had C "; }
else if(value>70 && value <80){
cout<<"you had B"; }
else if(value>80 && value <100){
cout<<"you had A"; }
break;
OUTPUT
enter number from 1 to 9
8 enter value: 90
you had A
case 9 :
double disc;
double a, b, c, x1, x2;
cout << "Enter the values of a, b, and c: ";
cin >> a >> b >> c;
disc = b * b - 4 * a * c;
if (disc < 0) { cout << "The equation has no roots." << endl; }
else if (disc == 0) {( x1 = -b / (2 * a));
cout << "The equation has one root: x = " << x1 << endl;
} else { x1 = (-b + sqrt(disc)) / (2 * a); x2 = (-b - sqrt(disc)) / (2 * a);
cout << "The quadratic roots has two roots: x1 = " << x1 << ", x2 = " << x2 << endl; }
cout<<"Choose from the options";
break;
OUTPUT
enter number from 1 to 9
9 Enter the values of a, b, and c:
4 The equation has no roots. Choose from the options }
return 0;
}
No comments:
Post a Comment