0% found this document useful (0 votes)
93 views3 pages

Solved Assignment Problems in C++ - Part2: 1 - Ngineers Utor

The document contains solutions to 5 programming problems in C++. Problem 1 calculates the circumference of a circle given the radius. Problem 2 calculates the yearly depreciation of an item given its purchase price, salvage value, and years of service. Problem 3 swaps the values of two variables without using a third variable. Problem 4 calculates the radius of a circle given its area. Problem 5 calculates the economic order quantity of products in inventory given yearly requirements, setup costs, and carrying costs.

Uploaded by

Cyrus Lim
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
93 views3 pages

Solved Assignment Problems in C++ - Part2: 1 - Ngineers Utor

The document contains solutions to 5 programming problems in C++. Problem 1 calculates the circumference of a circle given the radius. Problem 2 calculates the yearly depreciation of an item given its purchase price, salvage value, and years of service. Problem 3 swaps the values of two variables without using a third variable. Problem 4 calculates the radius of a circle given its area. Problem 5 calculates the economic order quantity of products in inventory given yearly requirements, setup costs, and carrying costs.

Uploaded by

Cyrus Lim
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

Solved Assignment Problems in C++ – Part2

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

Sol: //P = purchase price of an item


//S = expected salvage value
//Y = expected number of years of service
//D = yearly depreciation for the item
#include<iostream>
using namespace std;

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);

printf("Enter expected salvage value S:\n");


scanf("%f", &S);

printf("Enter expected number of years of service Y:\n");


scanf("%f", &Y);

D = (P-S)*Y;

printf("Product depreciation is: %f", D);


return 0;
}

1|Page Youtube.com/EngineersTutor www.EngineersTutor.com


Q3. Swapping of 2 variables without using temporary (or 3rd variable)

Sol: #include<iostream>
using namespace std;

int main()
{
//we need to give 2 inputs: x and y;
int x, y;

cout<<"Enter values of x and y:"<<endl;


cin>>x>>y;

cout<<"Before swapping, values of x and y are:"<<x<<"\t"<<y;


cout<<endl;

x = x+y; //suppose x = 10, y = 20, then x = 10+20 = 30


y = x-y; //y = x-y = 30 - 20 = 10
x = x-y; //x = x - y = 30 - 10 = 20

cout<<"After swapping, values of x and y are:"<<x<<"\t"<<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.

Sol: //r² = A/pi and r = sqrt(A/pi)


#include<iostream>
#include<math.h>
#define pi 3.1416
using namespace std;

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;
}

2|Page Youtube.com/EngineersTutor www.EngineersTutor.com


Q5. Determine the most economical quantity to be stocked for each product that a manufacturing company
has in its inventory: This quantity, called economic order quantity (EOQ) is calculated as follows:
EOQ=2rs/1 where: R= total yearly production requirement S=set up cost per order I=inventory carrying
cost per unit

Sol: //EOQ = economic order quantity


//R= total yearly production requirement
//S=set up cost per order
//I=inventory carrying cost per unit
#include<iostream>
using namespace std;

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;

cout<<"Enter set up cost S:"<<endl;


cin>>S;

cout<<"Enter inventory cost I:"<<endl;


cin>>I;

EOQ = (2*R*S)/I;

cout<<"economic order quantity EOQ is:"<<EOQ;


return 0;
}

3|Page Youtube.com/EngineersTutor www.EngineersTutor.com

You might also like