In: Computer Science
Program 3.5 - Conversion Program - NOW using cin statements to gather input from user
Concepts Covered: Chapter 2 – cout , math, data types, Chapter 3 , gathering both numeric & string input from user
Programs 2-21, 2-22, 2-23, 2-28 should help with math and programs 3.5, 3.17 and 3.19 should help you with the new concepts introduced with this program.
Program Purpose: To help you understand the concept of using both proper numeric variables and string variables. To give you practice using the C++ math operators. To give you practice getting both numeric input and string input from a user. To give you practice overriding the default behavior of C++ for numeric formatting. Lastly, to appreciate the flexibility of the cout object by passing it string variables, string literals, and numeric variables.
Background: Your instructor is an avid (some would say obsessed) bicyclist. Rides of 40 to 50 miles are not uncommon. Your instructor also uses an indoor training program called Zwift. It uses the metric system which is kilometers biked (instead of miles), and meters climbed (instead of feet). You need to help out your metrically challenged professor and write a conversion program that converts kilometers to miles and meters to feet.
For example, if I told some of my non-biking friends that I rode 40 kilometers, many of them would be impressed. Well, in miles that is only 24.8 miles. Conversely, if I told them I climbed 1000 meters they may not be impressed. But, 1000 meters is 3,280 feet which is not too shabby here in the Midwest.
Oh, did I mention, this also applies to runners, especially in terms of kilometers.
So your job commission is to write a C++ program which will convert kilometers to miles and meters to feet.
PROGRAM SPECIFICATIONS:
Insert program heading with your name, course, section, program name, AS WELL AS brief documentation of program purpose at the top of your program.
Create your c++ code.
INPUT SECTION
Create 4 numeric variables to hold the following: meters, feet, kilometers, and miles.
Create 2 string variables: one to hold the activity type: biking or running and the other to hold a person’s name.
Prompt the user for their name. You should get the user's full name! Example Jimmy C or John Bonham
Prompt the user (using their name) for which activity they did. - biking or running
Prompt the user for how many kilometers
Prompt the user for how many meters they climbed
PROCESSING SECTION
Perform the necessary math operations to convert kilometers to miles and meters to feet.
Kilometers to miles formula:
1 kilometer is equal to 0.621371 miles (often shortened to .62). 1 mile is equal to 1.609344 kilometers. Thus, to convert kilometers to miles, simply multiply the number of kilometers by 0.62137.
Meters to feet formula:
Multiply any meter measurement by 3.28 to convert to feet. Since one meter = 3.28 feet, you can convert any meter measurement into feet by multiplying it by 3.28.
1 meter x 3.28 = 3.28 feet
5 meters x 3.28 = 16.4 feet
2.7 meters x 3.28 = 8.856 feet
OUTPUT SECTION
Using cout statements, display the output listing name, activity, kilometers, miles, meters and feet. For formatting of numeric variables, use 2 digits of precision to right of decimal point.with values shown above.
Thanks for the question.
Below is the code you will be needing Let me know if you have
any doubts or if you need anything to change.
Thank You !!
===========================================================================
#include<iostream>
#include<iomanip>
#include<string>
using namespace std;
int main(){
double meters, feet , kilometers , miles ;
string activity_type, person_name;
cout<<"Enter your full name: ";
getline(cin,person_name);
cout<<"Enter activity type (biking or running):
";
cin>>activity_type;
cout<<"How many kilometers: ";
cin>>kilometers;
cout<<"How many meters they climbed: ";
cin>>meters;
miles = kilometers*0.62137;
feet = meters*3.28;
cout<<"Listing Name:
"<<person_name<<endl;
cout<<"Activity Type:
"<<activity_type<<endl;
cout<<fixed<<showpoint<<setprecision(2);
cout<<kilometers<<"
km(s)"<<endl
<<miles<<"
miles"<<endl
<<meters<<"
meter(s)"<<endl
<<feet<<"
feet(s)"<<endl;
}