Professional Documents
Culture Documents
Activity No. 5: Create A C++ Program
Activity No. 5: Create A C++ Program
Create a C++ program that will accept the height and radius of a cone and then display the
volume of a cone. Run the program with sample input.
#include <iostream>
using namespace std;
int main(){
const float pi=3.1416, w =0.33333333333333 ;
float height, radius, volume;
//enter the height and raius of a cone
cout <<"Enter the radius and height of a cone (seperate by using a space): ";
cin >> radius>>height;
cout << "The cone's raius is " << radius << " and cone's height is " << height;
radius= radius*radius ;
volume= height * radius;
volume= w * volume * pi ;
cout<< "\nThe volume of cone " << volume;
return 0;
}}
Filename: activity_5
Sample run:
Activity No. 5: Create a C++ program.
Create a C++ program that will accept time in seconds and then display in hour, minutes, second
format.
Filename: activity_6
Sample output (bold number is user input):
#include <iostream>
using namespace std;
int main (){
int time = 0;
int hour = 0;
int min =0;
int sec =0;
cout<< "Enter a time in seconds: ";
cin>> time;
hour= time/3600;
time= time%3600;
min = time/60;
time= time%60;
sec= time;
cout<<"The time in H:M:S format is: " <<hour<< " hour(s)," <<min<< "minute(s), " <<sec<< "second(s), " ;
}
Sample run: