Discussion 1 Computer Programming Overview
Discussion 1 Computer Programming Overview
4 3
1. Create a program to compute the volume of a sphere. Use the formula V = π r where π is
3
equal to 3.1416 approximately. The r is the radius. Display the result in two decimal places.
2. Write a program that converts the input Celsius degree into its equivalent Fahrenheit degree.
9
Use the formula: F= C +32. Round off the answer into 3 decimal places.
5
3. In geometry, Heron's formula (sometimes called Hero's formula), named after Hero of
Alexandria, gives the area of a triangle when the length of all three sides are known. Create a
program that will compute and display for the area of the triangle applying the said idea.
4. Write a program to find the circumference of a circle. Round off the answer into 4 decimal
places.
5. 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
P−S
the item (D). Use the formula: D=
Y
6. Create a program that will compute and display for the side of a perfect cube when its volume
is entered by the user.
7. Determine the most economical quantity (in 4 decimal places) to be stocked for each product
that a manufacturing company has in its inventory. This quantity, called economic order quantity
2 RS
(EOQ) is calculated as follows: EOQ=
√ I
where:
R= total yearly production requirement
S= set up cost per order
I= inventory carrying cost per unit
8. Write a program that prompts the user to enter the weight of a person in kilograms and outputs
the equivalent weight in pounds. Output both the weights rounded to two decimal places. (Note
that 1 kilogram = 2.2pounds.) Format your output with two decimal places.
4 3
1. Create a program to compute the volume of a sphere. Use the formula V = π r where π is
3
equal to 3.1416 approximately. The r is the radius. Display the result in two decimal places.
#include <iostream>
#include <iomanip>
using namespace std;
int main()
{
int radius;
float volsph;
cout << "Calculate the volume of a sphere :"<< endl;
#include <iostream>
using namespace std;
int main() {
float fahrenn, celsius;
return 0;
}
3. In geometry, Heron's formula (sometimes called Hero's formula), named after Hero of
Alexandria, gives the area of a triangle when the length of all three sides are known. Create a
program that will compute and display for the area of the triangle applying the said idea.
#include <iostream>
#include <math.h>
using namespace std;
main() {
float side1, side2, side3, area, s;
cout<<" Input the length of 1st side of the triangle : ";
cin>>side1;
cout<<" Input the length of 2nd side of the triangle : ";
cin>>side2;
cout<<" Input the length of 3rd side of the triangle : ";
cin>>side3;
s = (side1+side2+side3)/2;
area = sqrt(s*(s-side1)*(s-side2)*(s-side3));
cout<<" The area of the Triangle is : "<< area;
}
4. Write a program to find the circumference of a circle. Round off the answer into 4 decimal
places.
#include <iostream>
#include <iomanip>
#include <cmath>
using namespace std;
main() {
float cubeVolume, side;
cout << "Enter the volume of the Cube: ";
cin >> cubeVolume;
#include<iostream>
using namespace std;
int main()
D = (P-S)/Y;
return 0;
}
6. Create a program that will compute and display for the side of a perfect cube when its volume
is entered by the user.
#include <iostream>
#include <iomanip>
#include <cmath>
using namespace std;
int main() {
circumCircle = 2*pi*circleRadius;
cout << "The circumference of the Circle is ";
cout << fixed << setprecision(4) << circumCircle;
}
7. Determine the most economical quantity (in 4 decimal places) to be stocked for each product
that a manufacturing company has in its inventory. This quantity, called economic order quantity
2 RS
(EOQ) is calculated as follows: EOQ=
√ I
where:
R= total yearly production requirement
S= set up cost per order
I= inventory carrying cost per unit
#include<iostream>
#include <cmath>
#include <iomanip>
using namespace std;
int main()
{
EOQ = (2*R*S)/I;
cout<<"economic order quantity EOQ is:"<< sqrt(EOQ);
return 0;
}
8. Write a program that prompts the user to enter the weight of a person in kilograms and outputs
the equivalent weight in pounds. Output both the weights rounded to two decimal places. (Note
that 1 kilogram = 2.2pounds.) Format your output with two decimal places.
#include<iostream>
#include<iomanip>
using namespace std;
int main()
{
double weightKg, weightPounds;
system("pause");
return 0;