Professional Documents
Culture Documents
Write a short program that asks for your height in integer inches and
then converts your
height to feet and inches. Have the program use the underscore
character to indicate
where to type the response. Also, use a const symbolic constant to
represent the conversion
factor.
My Answer:
1
2
3 #include <iostream>
4 int main()
5{
6 const int convFeetoInches = 12;
7 using namespace std;
8 cout.setf(ios_base::fixed, ios_base::floatfield); // fixed-point
9
1 int inches = 0;
0
cout << "Enter your height in inches here: ";
1
cin >> inches; cout << endl;
1
cout << "Your heght is " << int (inches) / int (convFeetoInches) << " feet and "
1
<< inches % convFeetoInches << " inches.";
2
1
3 cin.get();
1 cin.get();
4
return 0;
1
}
5
1
6
2.
JHub says:
November 19, 2012 at 12:11 pm
Use this code to add the underscore to the cout statement.
Original cout << "Enter your height in inches here: ";
Underscore cout << "Enter your height in inches here:____\b\b\b\b ";
Reply
3.
buzz says:
4.
buzz says:
August 17, 2013 at 6:23 am
#include //OMG Please delete my first comment
int main()
{
using namespace std;
#include <iostream>
int main()
4
5
8
9
10
11
12
int feet = 0;
13
cout << "Enter your height [feet]: "; cin >> feet; cout << endl;
14
int inches = 0;
15
cout << "Enter your height [inches]: "; cin >> inches; cout << endl;
16
int weight = 0;
17
cout << "Enter your weight [pounds]: "; cin >> weight; cout << endl;
18
19
20
21
22
23
24
25
cin.get();
26
cin.get();
27
return 0;
28
3. Write a program that asks the user to enter a latitude in degrees, minutes, and
seconds
and that then displays the latitude in decimal format. There are 60 seconds of arc
to a
minute and 60 minutes of arc to a degree; represent these values with symbolic
constants.
You should use a separate variable for each input value. A sample run should
look like this:
Enter a latitude in degrees, minutes, and seconds:
First, enter the degrees: 37
Next, enter the minutes of arc: 51
Finally, enter the seconds of arc: 19
37 degrees, 51 minutes, 19 seconds = 37.8553 degrees
My Answer:
#include <iostream>
int main()
4
5
7
8
cout << "Enter a latitude in degrees, minutes, and seconds:" << endl;
int degrees;
1
0
cout << "First enter the degrees: "; cin >> degrees; cout << endl;
int minutes;
11
cout << "Next enter the minutes of arc: "; cin >> minutes; cout << endl;
1
2
int seconds;
1
3
cout << "Finally, enter the seconds of arc: "; cin >> seconds; cout <<
endl;
1
4
cout << degrees << " degrees, " << minutes << " minutes, " << seconds
<< " seconds = ";
1
5
1
6
1
7
1
8
cin.get();
cin.get();
1
9
2
0
return 0;
}
2
1
2
2
2
3
4. Write a program that asks the user to enter the number of seconds as an
integer value (use type long) and that then displays the equivalent time in days,
hours, minutes, and seconds. Use symbolic constants to represent the number of
hours in the day, the number of minutes in an hour, and the number of seconds
in a minute. The output should look like this:
Enter the number of seconds: 31600000
31600000 seconds = 365 days, 46 minutes, 40 seconds
My Answer:
1
#include <iostream>
int main()
4
5
8
9
1
0
11
cout << "Enter the number of seconds: ";
1
2
1
1
4
1
5
1
6
1
7
1
8
1
9
2
0
cout << Minutes << " minutes, " << SecondsLast << " seconds.";
2
1
2
2
cin.get();
2
3
2
4
2
5
2
6
2
7
2
8
2
cin.get();
return 0;
}
9
5. Write a program that asks how many miles you have driven and how many
gallons of
gasoline you have used and then reports the miles per gallon your car has gotten.
Or, if
you prefer, the program can request distance in kilometers and petrol in liters
and then
report the result European style, in liters per 100 kilometers.
My Answer:
1
#include <iostream>
int main()
4
5
7
8
int miles;
int gallons;
10
11
12
13
14
15
16
float MPG;
17
18
19
20
21
cin.get();
22
cin.get();
23
return 0;
24
#include <iostream>
int main()
4
5
9
10
11
double LtrKM;
12
13
14
15
cout << "The US equivalent MPG - " << USMPG << endl;
16
17
18
cin.get();
19
cin.get();
20
return 0;
21
Matthew says:
December 27, 2011 at 7:01 am
Hey, In this code you wrote wrong const. GallLT should be 3.875, not 3.785. It should be
something like this:
#include
#include
using namespace std;
const float PETROL = 62.14f;
int main()
{
// variables //
float petrol(0.f);
///////////////
cout << "LT / 100km:" << endl;
cout <> petrol;
cout << endl;
//float finalResult = petrol / petrol;
float secondResult = PETROL / petrol;
//finalResult=3.875f;
secondResult *= 3.875f;
cout << "Final result: " << secondResult << " MPG";
_getch();
}