Task: Write a C++ Program To Calculate Circle Area or Circumference according to the User choice.
The Source Code of C++ Circle Program
// Write a program that uses two user defined functions // for calculating area and circumference of a circle. //The program will input radius and asks the user // to enter a choice 1 or 2. //If the user enters 1, it will display area // if the user eneters 2 then circumference //of the circle will be the output #include<iostream> using namespace std; void area(float); void circumference(float); int main() { float radius; int choice; cout<<"Enter Radius of Circle: "; cin>>radius; cout<<"Enter Your Choice 1 for Area and 2 for Circumference:"; cin>>choice; if(choice==1) area(radius); else if(choice==2) circumference(radius); else cout<<"Wrong choice!"; return 0; } void area(float r) { cout<<"Area of Circle="<<(3.1415 * r* r); } void circumference(float r) { cout<<"Circumferenceb of Circle="<<(2.0 * 3.1415 * r); }
Output of the C++ Circle Program Calculations
Enter Radius of Circle: 2.5
Enter Your Choice 1 for Area and 2 for Circumference:1
Area of Circle=19.6344
——————————–
Process exited after 18.92 seconds with return value 0
Press any key to continue . . .
Enter Radius of Circle: 2.5
Enter Your Choice 1 for Area and 2 for Circumference:2
Circumferenceb of Circle=15.7075
——————————–
Process exited after 21.03 seconds with return value 0
Press any key to continue . . .
Enter Radius of Circle: 5.26
Enter Your Choice 1 for Area and 2 for Circumference:1
Area of Circle=86.9178
——————————–
Process exited after 11.3 seconds with return value 0
Press any key to continue . . .
Enter Radius of Circle: 10.67
Enter Your Choice 1 for Area and 2 for Circumference:2
Circumferenceb of Circle=67.0396
——————————–
Process exited after 17.52 seconds with return value 0
Press any key to continue . . .