

Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
Material Type: Lab; Class: INTRO-COMPUTER CONCEPTS; Subject: Computer Science & Engineering; University: University of South Carolina - Columbia; Term: Spring 2008;
Typology: Lab Reports
1 / 2
This page cannot be seen from the preview
Don't miss anything!


Programming Lab 7 Spring Break is approaching fast. You have decided to drive to West Palm Beach to spend the week with your friends. As a part of your planning, you need to determine how long it will take you to get there and how much you will need to spend on gas. The distance between Columbia and West Palm Beach is approximately 575 miles and the current price of gas is $2.89 per gallon. Declare four floating point variable called Cost, Time, Speed, and MPG float Cost, Time, Speed, MPG; Write an input statement for Speed and then (at the prompt) enter the value representing the average speed at which you drive on interstate highways cin >> Speed; Write an input statement for MPG and then (at the prompt) enter the value representing the average highway gas mileage for your car Calculate the total amount of time required for your trip Time = 575/Speed; Calculate the cost of gas for your trip Cost = (575/MPG)*2.89; Output the total trip time and gas cost values cout << “Your trip will take: ” << Time << “ hrs” << endl; cout << “The total cost of gas for your trip is: $” << Cost << endl; Using the program mode Open Notepad The first line must be a comment statement. Include your name in the comment. Look at the tutorial for this. Go to the file menu and select “save as.” In the top dropdown box select your H drive. Save your file directly onto the H drive, do not put it inside any folders. Choose “all files” in the type dropdown menu (just like we did to save html files.) Finally, give your file a .ch extension (just like we gave our html files a .html extension.) Click save. Remember to save your file often. Type the include statement that is needed to facilitate input/output capabilities. Look at the tutorial for this. The beginning of your code starts with the following statement: main ( ) { Enter your code after the opening curly bracket. Your code should contain the statements to do the following. Remember to close each line of code below with a semicolon. o Declare four floating point variable called Cost, Time, Speed, and MPG. o Output a short phrase asking for the user’s average driving speed on interstate highways.
o Input the speed. o Output a short phrase asking for the average highway gas mileage of the user’s car. o Input the gas mileage. o Calculate the total trip time and cost of gas based on the formulas provided above. o Output the computed trip time and cost of gas. End your program code with the closing curly bracket. Save the file. To execute your program, type ./filename in the Ch program window (Dot forward-slash filename; the ch extension is not needed here) If you have error messages, note the cause of error indicated in each message and change your code to fix the problem(s). To make changes to your program, move back into Notepad, change the code, and save the file. To run the program again, move back to the Ch window and use the up-arrow key to move the command ./filename to the current line.