$30
CS 159 – HW #03
10 Points Possible
Problem: Given as input the initial height, velocity, and angle (to the horizontal) of a projectile being launched calculate
the time to reach maximum height, the maximum height reached, the time to hit the ground, and the total distance
traveled. All values input and output are of the double data type. A good use of user-defined functions is a requirement
of this and all future programming assignments.
Time to reach max height:
timemax height=
initial velocity∗sin(θ)
9.8
Maximum height reached:
height=initial velocity∗sin(θ)∗time−
1
2
g∗timemax height
2
Time to hit ground:
−height=initial velocity∗sin (θ)∗time hit ground−
1
2
g∗timehit ground
2
Assumptions:
1. The acceleration due to gravity is 9.8 m/s2
is
downward and constant over the range of
motion.
2. Air resistance/friction is not to be
considered, making the horizontal component
of acceleration constant.
3. Earth's rotation does not affect the motion.
Total distance traveled:
distance=initial velocity∗cos(θ)∗timehit ground
Example Execution #1:
Enter height of launch [m] -> 100
Enter initial velocity [m/s] -> 74.5
Enter angle to the horizontal [degrees] -> 30
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
Time to max height: 3.80 s
Maximum height reached: 170.79 m
Time to hit ground: 9.70 s
Total distance traveled: 626.15 m
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
Example Execution #2:
Enter height of launch [m] -> 100
Enter initial velocity [m/s] -> 75.15
Enter angle to the horizontal [degrees] -> 60
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
Time to max height: 6.64 s
Maximum height reached: 316.10 m
Time to hit ground: 14.67 s
Total distance traveled: 551.33 m
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
Example Execution #3:
Enter height of launch [m] -> 0
Enter initial velocity [m/s] -> 135
Enter angle to the horizontal [degrees] -> 45
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
Time to max height: 9.74 s
Maximum height reached: 464.92 m
Time to hit ground: 19.48 s
Total distance traveled: 1859.69 m
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
All course programming and
documentation standards are in
effect for this and each assignment
this semester. Please review this
document!
Academic Integrity Reminder:
• Please review the policies of the course
as they relate to academic integrity. The
assignment you submit should be your
own original work. You are to be
consulting only course staff regarding
your specific algorithm for assistance.
Collaboration is not permitted on
individual homework assignments.
Additional Requirements:
1. Add the homework assignment header file to the top of your program. A description of your program will need to
be included in the assignment header. This particular header can be added to your file by entering hhw while in
command mode in vi.
2. Each of the example executions provided for your reference represents a single execution of the program.
Your program must accept input and produce output exactly as demonstrated in the example executions, do not
add any “bonus” features not demonstrated in the example executions. Your program will be tested with the data
seen in the example executions and an unknown number of additional tests making use of meaningful data.
◦ All data input, output, or generated in the process of calculating the results displayed are assumed to be of the
double data type.
3. For this assignment you will be required to implement the user-defined functions (from chapter 4). Failing to
follow course standards as they relate to good user-defined function use will result in a zero for this assignment.
4. Revisit course standards as it relates what makes for good use of user-defined functions, what is acceptable
to retain in the main function, and when passing parameters by address is appropriate.
◦ In many cases user-defined function use should result in a main function that only declares variables and
makes function calls.
5. Course standards prohibit the use of programming concepts not yet introduced in lecture. For this assignment
you can consider all material in the first four chapters of the book, notes, and lectures to be acceptable for use.
6. A program MUST compile to be considered for partial credit. The submission script will reject the submission of
any file that does not successfully compile on the guru server. The name of the source code file you attempt to
submit must be hw03.c, no variation is permitted.
Course Programming and Documentation Standards Reminders:
• Use the course function header (head_fx vi shortcut hfx while in command mode) for every user-defined
function in your program.
◦ List and comment all parameters to a function, one per line, in the course function header.
◦ All function declarations will appear in the global declaration section of your program.
◦ The user-defined function definitions will appear in your program after the main function.
• Indent all code found within the main function exactly two spaces.
• Place a single space between all operators and operands.
• Comment all variables to the right of each declaration. Declare only one variable per line.
• In general it is acceptable to initialize a variable declared in the local declaration section of a function. If the
expression used to initialize the variable is more complex than a constant assignment then it is
best to give the variable its first value inside of the executable statement section of the function.
• Notice that several programs (see program 2-9 on pages 74-75) in the programming text use a single line
comment to indicate the start of the local declaration and executable statement sections of the main function.
◦ At no point during the semester should these two sections ever overlap.
• Select meaningful identifiers (names) for all variables in your program.
• Do not single (or double) space the entire program, use blank lines when appropriate.
When you submit... only the final successful submission is kept for grading. All other submissions are over-written and
cannot be recovered. You may make multiple submissions but only the last attempt is retained and graded.
• Verify in the confirmation e-mail sent to you by the course that you have submitted the correct file (must be
named hw03.c), to the correct assignment (hw03), and to the correct section.
• Leave time prior to the due date to seek assistance should you experience difficulties completing or submitting
this assignment. All attempts to submit via a method other than through the guru server as set up in the Account
Configuration Activity will be denied consideration.
Assignment deadlines... are firm and the electronic submission will disable promptly as advertised. We can only grade
what you submit as expected prior to the assignment deadline.
Auto-Grade Tool
• We have implemented what is being referred to as the auto-grade tool. At the time of a successful assignment
submission you may receive some feedback on your program in regards to course programming and
documentation standards. This feedback may include a potential deduction that you will receive once your
assignment is reviewed by your grader.
• It is expected that graders verify those notes identified by this tool to ensure that they are indeed applicable and
reasonable to the submission. Graders may make additional deductions for those standards not identified by the
new tool.
• We hope that this feedback helps with the enforcement of course standards, consistency in grading across
sections, and to encourage students to revise their work when problems are identified before the assignment
deadline passes. It is possible to resubmit an assignment for grading up to the advertised deadline. Only the final
successful submission is retained and evaluated.