please solve this C++ program Assignment 3 Write a C+t program to do the followi
ID: 3700232 • Letter: P
Question
please solve this C++ program
Explanation / Answer
Please find below code for your problem
--------------------------------
#include<iostream>
using namespace std;
void DisplayMenue()
{
cout << "1 - Circle" << endl;
cout << "2 - Sphere " << endl;
cout << "3 - Cylinder" << endl;
cout << "4 - Calculator " << endl;
cout << "0 - Exit" << endl;
cout << "Please Select an item: ";
}
void Circle(double &area, double &perimeter)
{
const double Pi = 3.14159;
double radius;
cout << "Please enter circle radius: ";
cin >> radius;
area = Pi * radius * radius;
perimeter = 2 * Pi * radius;
}
double Sphere()
{
const double Pi = 3.14159;
double area, radius;
cout << "Please enter sphere radius: ";
cin >> radius;
area = 4 * Pi * radius*radius;
return area;
}
void Cylinder(double radius, double height)
{
const double Pi = 3.14159;
double Area = 2 * Pi * radius * height + 2 * Pi * radius * radius;
double Volume = Pi * radius * radius * height;
cout << "The cylinder area is: " << Area << endl;
cout << "The cylinder volume is: " << Volume << endl;
}
int Calculator()
{
int randNum1 = rand() % (9 - 2 + 1) + 2;
int randNum2 = rand() % (9 - 2 + 1) + 2;
cout << "Number 1 :" << randNum1 <<endl;
cout << "Number 2 :" << randNum2 << endl;
cout << "Please enter sum of two number displayed: ";
int rightAns = 0;
int inputAns;
cin >> inputAns;
if (inputAns == randNum1 + randNum2)
{
cout << " Congratulation !" << endl;
rightAns++;
}
else
{
cout << "Sorry the correct answer is : " << randNum1 + randNum2 << endl;
}
cout << "Please enter diffrence of two number displayed: ";
cin >> inputAns;
if (inputAns == randNum1 - randNum2)
{
cout << " Congratulation !" << endl;
rightAns++;
}
else
{
cout << "Sorry the correct answer is : " << randNum1 - randNum2 << endl;
}
cout << "Please enter product of two number displayed: ";
cin >> inputAns;
if (inputAns == randNum1 * randNum2)
{
cout << " Congratulation !" << endl;
rightAns++;
}
else
{
cout << "Sorry the correct answer is : " << randNum1 * randNum2 << endl;
}
return rightAns;
}
void main()
{
int inputNumber;
double area, perimeter;
int rightAns = 0;
do
{
DisplayMenue();
cin >> inputNumber;
switch (inputNumber)
{
case 1:
Circle(area, perimeter);
cout << "The circle area is: " << area << endl;
cout << "The circle perimeter is: " << perimeter << endl;
break;
case 2:
area = Sphere();
cout << "The sphere area is: " << area << endl;
break;
case 3:
double radius, height;
cout << "Please enter cylinder radius: ";
cin >> radius;
cout <<endl << "Please enter cylinder height: ";
cin >> height;
Cylinder(radius, height);
break;
case 4:
rightAns = Calculator();
cout << endl << "You have answred "<< rightAns << " question correctly out of 3 questions" <<endl;
break;
case 0:
break;
default:
break;
}
} while (inputNumber != 0);
DisplayMenue();
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.