Solved Assignment Problems in C++ - Part2: 1 - Ngineers Utor
Solved Assignment Problems in C++ - Part2: 1 - Ngineers Utor
Q1. Design a program to find the circumference of a circle. Use the formula: C=2πr, where π is
approximately equivalent 3.1416.
Sol: #include<iostream>
using namespace std;
#define pi 3.1416
int main()
{
//we need to give only one input to program i.e., radius of circle r
int r;
float Circum;
cout<<"Enter radius of circle r:"<<endl;
cin>>r;
Circum = 2*pi*r;
cout<<"circumference of circle is:"<<Circum;
return 0;
}
Q2. Write a program that takes as input the purchase price of an item (P), its expected number of years of
service (Y) and its expected salvage value (S). Then outputs the yearly depreciation for the item (D). Use
the formula: D = (P - S) Y
int main()
{
//we need to give 3 inputs to the program i.e., P, S, Y
float P, S, Y;
float D;
printf("Enter purchase price of an item P:\n");
scanf("%f", &P);
D = (P-S)*Y;
Sol: #include<iostream>
using namespace std;
int main()
{
//we need to give 2 inputs: x and y;
int x, y;
return 0;
}
Q4. Write a program to compute the radius of a circle. Derive your formula from the given equation: A=πr²,
then display the output.
int main()
{
//we need to give only one input to program i.e., area of circle A
int A;
float r;
cout<<"Enter area of circle A:"<<endl;
cin>>A;
r = sqrt(A/pi);
cout<<"Radius of circle is:"<<r;
return 0;
}
int main()
{
//we need to give 3 inputs to the program i.e., P, S, Y
float R, S, I;
float EOQ;
cout<<"Enter total yearly production R:"<<endl;
cin>>R;
EOQ = (2*R*S)/I;