DOC PREVIEW
Cal Poly CPE 101 - lab 2

This preview shows page 1-2 out of 7 pages.

Save
View full document
View full document
Premium Document
Do you want full access? Go Premium and unlock all 7 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 7 pages.
Access to all documents
Download any document
Ad free experience
Premium Document
Do you want full access? Go Premium and unlock all 7 pages.
Access to all documents
Download any document
Ad free experience

Unformatted text preview:

. .Fall 2009 CPE 101: Fundamentals of Computer Science I Zo¨e Wood. .Lab 2: Prepare for a Moon Landing. . .Due date: Friday, October 2, 11:59pm.Assignment PreparationLab type. This is an pair programming lab. The pairs will be designatedby the instructor at the beginning of the lab. Please ask the instructor if youare not clear on how to do this.Collaboration. Students work in pairs, and it is considered cheating, if mem-bers of the team (pair) do not work together. Communication between pairsduring lab time is allowed, but no direct sharing of code is allowed.1 PurposeTo write a program requiring use of variable declarations, reading values into andwriting the values stored in variables, assignment statements and conditionalstatements.2 Program DescriptionIn this project you will start implementing a version of one of the oldest knowncomputer games: Moon Landing. In Program 2 you will be expected to imple-ment the entire game.Imagine that you are piloting a one-man spaceship to the Moon. Your space-ship carries a certain amount of fuel and gives you certain milage for each gallonof fuel spent. Obviously you want to have some information at any moment oftime about how far from the Moon you are and how much fuel you have left.The only information you have is• Amount of fuel at the beginning of the flight• Fuel Milage (miles/gallon)• The velocity of your spaceship1• Distance you have to travelUsing this information you write a program that can compute how much fuelyou have left and how far from the Moon you are right now (and can even giveyou an ETA).There is a number of simplifying assumptions we are making here. One ofthem is that your spaceship travels with constant velocity. Another simplifica-tion is in the fact that we assume that the fuel milage does not depend on thevelocity the ship is travelling with. We also do not take into account the loss ofmass the ship is experiencing while burning fuel.3 Program SpecificationsWrite a small C program which produces several lines of output, as follows (seethe sample execution in Section ??). Note that I suggest you develop this labin two parts. The first part is mandatory and should include:MLP1. The first output line shall contain the text "Prototype Moon LandingProgram."MLP2. The second output line shall contain your and your partner’s fullnames.MLP3. The next few lines will contain input prompts.MLP3-1. The first prompt shall beEnter the distance to the Moon (miles):The program shall read in the distance to the Moon from the startingpoint of the space ship.MLP3-2. The second prompt shall beEnter current velocity (miles/sec):The program shall read in the current velocity of the ship.MLP3-3. The third and final prompt shall beEnter the time in flight (mins):The program shall read in the time in flight for which the computationsshall be made.MLP4. Distance to the Moon and current velocity are floating point numbers.Time in flight is an integer.2MLP5. Each value, as it is read from input shall be tested for conformance tothe rules specified below. If the value falls outside the prescribed feasible rangeof values, the program shall produce an error message:Input Error: Incorrect <Parameter>: <Value>Here, <Parameter> is one of "distance",, "velocity" and "time in flight",corresponding to the parameter that was incorrectly entered. <Value> is theincorrectly entered value.The feasible range of values for the parameters is defined as follows:distance to the Moon (distance) 0.0 ≤ distance ≤ 253560.00current velocity (velocity) 7.0 ≤ velocity ≤ 385.9375time in flight (time) 0 ≤ time ≤distancevelocityNotes: 253560.00 miles is the distance from Earth to the Moon at the apogee,7.0 miles/sec is the escape velocity of the Earth, 385.9375 miles/sec is the escapevelocity of the Sun.Note: Your program shall test each value as soon as it is read. If an incorrectvalue is given, then your program should prompt the user to input another value.If the second value is incorrect, your program should automatically assign a validvalue (the maximum value in the range except for time in flight which is set tozero) and report this to the user. For example:Input Error: Incorrect <Parameter>, Valid value <Value>, assigned!Where <Parameter> and <Value> are as specified above.MLP6. After all the values are read, and established to be in their respectivefeasible ranges, your program shall compute and output the following informa-tion:1. The distance the spaceship has travelled in the time provided to it;2. The remaining distance to the Moon;For the exact format of the output, please consult Section 5MLP7. The last line of your program’s output should contain the phrase‘‘Good Luck’’. After this line is printed, your program shall stop.MLP-optional Once you complete the above portion of the lab, you can thenadd the following prompts and reports. These additional prompts and reportswill help you with Program 2. They are not required and are suggested here toassist in preparing you for Program 2. Add prompts which ask:MLP3-4-opt. The fourth prompt shall beEnter the initial amount of fuel (gallons):The program shall read in the initial amount of fuel the ship has.MLP3-5-opt. The fifth prompt shall beEnter the fuel efficiency of the spaceship (miles/gallon):The program shall read in the fuel efficiency of the ship.3MLP4-optional. Amount of fuel and fuel efficiency are floating point num-bers.MLP5-optional. Again test the validity of input and print the same er-ror message but with <Parameter> values of "amount of fuel" and "fuelefficiency" where appropriate.The feasible range of values for the parameters is defined as follows:initial amount of fuel (fuel) 0.0 ≤ fuel ≤ 40000.00fuel efficiency (efficiency)distancefuel≤ fuel ≤ 4 ×distancefuelYou should again only allow the user two chances to enter the correct valuesfor the input and then assign the maximum range value to the variable.MLP6-optional. After all the values are read, and established to be in theirrespective feasible ranges, your program shall now also compute and output thefollowing information:1. The amount of fuel used during the flight so far;2. The amount of fuel left;3. The estimated time of arrival (in hours and minutes)General NotesMath. You are responsible for the program design for this program. In par-ticular, you are responsible for coming up with the correct math (physics) tocompute the outputs of the program based on the inputs.Program name. Name your


View Full Document

Cal Poly CPE 101 - lab 2

Documents in this Course
Load more
Download lab 2
Our administrator received your request to download this document. We will send you the file to your email shortly.
Loading Unlocking...
Login

Join to view lab 2 and access 3M+ class-specific study document.

or
We will never post anything without your permission.
Don't have an account?
Sign Up

Join to view lab 2 2 2 and access 3M+ class-specific study document.

or

By creating an account you agree to our Privacy Policy and Terms Of Use

Already a member?