#include <iostream>
using namespace std;
/* run this program using the console pauser or add your own getch, system("pause") or input loop */
int main() // start of main function
{
const float KM_PER_MILE=1.609; //1.609 km in a mile
float miles, //input: distance in miles
kms; //output: distance in kilometer
//get the distance in miles
//convert the distance to kilometes
//distance in kilometers in 1.609*distance in miles.
//display the distance in kilometers
return 0;
}
3.2
#include <iostream>
using namespace std;
int main(){
const float PI = 3.14159;
float radius; //input: radius of cicle
float area; //output: area of circle
float circum; //output: circumferense of circle
//get the circle radius.
cout<<"Enter the circle radius : ";
cin>>radius;
//compute area of circle
area=PI*radius*radius;
//compute circumference of circle
circum=2*PI*radius;
//display area and circumference
cout<<"the area of the circle is " <<area<<endl;
cout<<"the circumference of the circle is "<<circum<<endl;
return 0;
}
3.5
#include <iostream>
using namespace std;
int main()
{
const float PI = 3.14159;
float holeDiameter; //input-diameter of hole
float edgeDiameter; //input-diameter of outer edge
float thickness; //input-diameter of washer
float density; //input-thickness of material used
float quantity; //input-density of washer made
float weight; //input-number of weight of washer batch
float holeRadius; //radius of hole
float edgeRadius; //radius of outer edge
float rimArea; //area of rim
float unitWeight; //weight of 1 washer
// Get the inner diameter, outer diameter, and thickness.
cout << "Inner diameter in centimeters: ";
cin >> holeDiameter;
cout << "Outer diameter in centimeters: ";
cin >> edgeDiameter;
cout << "Thickness in centimeters: ";
cin >> thickness;
// Get the material density and quantity manufactured.
cout << "Material density in grams per cubic centimeter: ";
cin >> density;
cout << "Quantity in batch: ";
cin >> quantity;
// Compute the rim area.
holeRadius = holeDiameter / 2.0;
edgeRadius = edgeDiameter / 2.0;
rimArea = PI*edgeRadius*edgeRadius -
PI*holeRadius*holeRadius;
// Compute the weight of a flat washer.
unitWeight = rimArea * thickness * density;
// Compute the weight of the batch of washers.
weight = unitWeight * quantity;
// Display the weight of the batch of washers.
cout<<"The expected weight of the batch is "<<weight<<"grams"<<endl;
return 0;
}
3.7
#include <cmath>
#include <iostream>
using namespace std;
int main()
{
float first; //input: one of two data values
float second; //input: second of two data values
float answer; //output: a square root value
//get first number and display its square root.
cout << "Enter the first number: ";
cin >> first;
answer= sqrt(first);
cout << "The square root of the first number is "
<< answer << endl;
// Get second number and display its square root.
cout << "Enter the second number: ";
cin >> second;
answer= sqrt(second);
cout << "The square root of the second number is "
<< answer << endl;
// Display the square root of the sum of first and second.
answer= sqrt(first +second);
cout << "The square root of the sum of both numbers is "
<< answer << endl;
return 0;
}
0 comments:
Posting Komentar