0% found this document useful (0 votes)
62 views

Discussion 1 Computer Programming Overview

The document discusses 8 computer programming activities or exercises involving calculations using common formulas. The activities cover calculating the volume of a sphere, converting between Celsius and Fahrenheit temperatures, calculating the area of a triangle using Heron's formula, finding the circumference of a circle, calculating yearly depreciation, determining the side of a cube given its volume, calculating economic order quantity, and converting between kilograms and pounds. Sample C++ code is provided for each activity to demonstrate how to write a program to perform the given calculation.

Uploaded by

Cyrus Lim
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
62 views

Discussion 1 Computer Programming Overview

The document discusses 8 computer programming activities or exercises involving calculations using common formulas. The activities cover calculating the volume of a sphere, converting between Celsius and Fahrenheit temperatures, calculating the area of a triangle using Heron's formula, finding the circumference of a circle, calculating yearly depreciation, determining the side of a cube given its volume, calculating economic order quantity, and converting between kilograms and pounds. Sample C++ code is provided for each activity to demonstrate how to write a program to perform the given calculation.

Uploaded by

Cyrus Lim
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 10

TECHNOLOGICAL INSTITUTE OF THE PHILIPPINES

College of Information Technology Education


Computer Science Department
ITE 001 – Computer Programming 1

Activity: Discussion 1.1 Computer Programming Overview

The following activity supports the attainment of these outcomes:


1. Apply appropriate computing, science, and mathematics theories and principles as applied in
computer programming using C/C++ language;
2. Analyze machine problem and identify and define computer programming requirements
appropriate to its solution using C/C++ language;
3. Use standard techniques, skills, and tools in computer programming practice using C/C++
language;
4. Design and develop a computer program using C/C++ language; and
5. Reflect on personal transformation along the TIP Graduate Attributes.

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;

cout<<" Input the radius of a sphere : ";


cin>>radius;
volsph=(4*3.14*radius*radius*radius)/3;
cout<<" The volume of a sphere is : ";
cout << fixed << setprecision(2) << volsph;
return 0;
}
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

#include <iostream>
using namespace std;

int main() {
float fahrenn, celsius;

cout << "Enter the temperature in celsius\n";


cin >> celsius;

/*Multiply by 9, then divide by 5, then add 32*/


fahrenn =(9.0/5.0) * celsius + 32;

cout << celsius <<"Celsius is equal to " << fahrenn <<"Fahrenheit";

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;

side = pow(cubeVolume, 1/3.);


cout << "The length of the side of a Cube is ";
cout << fixed << setprecision(2) << side;
}
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

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

}
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() {

const double pi = 3.1416;


double circleRadius, circumCircle;
cout << "Enter radius of the Circle: " ;
cin >> circleRadius;

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()
{

/*we need to give 3 inputs to the program i.e., R, S, I*/


double R, S, I;
double 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:"<< 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;

cout<<"Enter the Person's weight in Kilograms:";


cin>>weightKg;

weightPounds = 2.2 * weightKg;


cout<<fixed<<setprecision(2);

cout<<"Weight in Kilograms:" <<weightKg<<endl;


cout<<"weight in Pounds:" <<weightPounds<<endl;

system("pause");
return 0;

You might also like