I am an introduction course to c++ and we haven't learned much yet but we have a homework assignment I have no clue how to do. Can anyone help get me started at least.
the assignment is
This assignment is a very first introduction to programming in C++. It involves some very simple problem-solving and calculation, and designing a complete program.
PROGRAM BACKGROUND
Some common formulae involving motion and deceleration are these:
When an object moves at constant velocity,
x = v t
where x = distance traveled, v = velocity, and t = time
when an object's movement is affected by a constant force (such as gravity),
x = v t - (1/2) g t²
where x = net altitude, v = initial velocity, t = time,
and g = downward effect due to gravity
The horizontal displacement can be approximated by assuming the horizontal velocity is constant (i.e. wind and air resistance are negligible).
PROBLEM DESCRIPTION
The Angry Birds have been at war with the pigs for years now, and their original tactics of launching themselves from slingshots have taken their toll due to injury. And so, they have decided finally to try launching other things, like rocks.
Last year, they hired someone to build a catapult for them, but decided that the device was much too slow and cumbersome. And so, this year they are doing the more old-fashioned ploy of just dropping the rocks from the skies themselves.
Unfortunately, the pigs have also been beefing up their defenses, so it is dangerous to actually fly directly over the pig encampment. Fortunately, the laws of physics do allow for the rocks to have a horizontal component in their velocity while they fall.
Since nobody has actually measured the gravity on the planet where the Angry Birds live, that value for g above is unknown. Also, nobody truly knows the airspeed velocity of a fully-laden Angry Bird. Both of these values can be determined by an initial test. These calculated values will then be used for other calculations.
PROGRAM SPECIFICATIONS
Write a program that will make some particular calculations. It will do the following:
Input the following values from a test flight at a height of 10 meters:
-- the horizontal distance the rock traveled after it was released, in meters
-- the time until the rock hit the ground, in seconds
(Do not expect these two inputs to be whole numbers).
The most powerful birds are able to maintain their cruising speeds at a height of 1000 meters (beyond which the air is a little thin)
Determine how far into the pig encampment the rock would land if released at this height. This is the maximum range available with this method.
HINT: If you play around with your algebra, you should discover a way to solve this using only +, -, *, and or / operations. The numbers chosen for Steps 1 and 2 were specifically chosen to help this.
Suppose the time has come to take the fight to the pigs. Input a value representing the distance to a target from the nearest safe point of approach (this should be less than the maximum range). From this value, compute the altitude at which a bird must fly such that the rock will hit that target at ground level.
Be sure to include appropriate details in the user interface so that the person running it would not need to know anything about the program to be able to use it successfully.
For example, the program interface might look like this:
How far (in meters) did the rock fly when launched at 10 meters? 12.3
How much time (in seconds) did it take to get there? 1.1
The maximum range from 1000 meters seems to be 122 meters.
How far is the actual target? 75.3
You will need to fly at a height of 372.5 meters to hit that accurately.
NOTE: No real calculations were performed to produce the numbers above, so do not assume that they are accurate! Let your program design itself answer for the accuracy of its results!
DOCUMENTATION SPECIFICATIONS
This program (and all programs) should at minimum include the following:
The purpose of the program
The name of the programmer who wrote it
The date at which the program was completed
In addition, insert comments throughout the program that would explain the program to any casual reader. Anyone with comparable programming experience to you (in many cases, none) should be able to skim the program from top to bottom and understand what it is doing well enough to believe it is correct.
Also, declare constants for values that might not be otherwise obvious to your reader. They will help to clarify the meaning of the computations, and would also facilitate modifying the program to solve related problems.
REGARDING REAL NUMBERS
Evaluation of this assignment will be primarily based on the quality of your code, the usability of your interface, and the correctness of your results. After all, those are the items specifically taught in class.
But one item which is less important is the number of decimal places you display in your results. If we wanted to print the value of one-third, it could show up as 0.33 or 0.333 or 0.333333333. All of these are necessarily inexact (it is a non-terminating decimal), but they all pretty well describe the value we are looking at.
C++ will generally try to display as many digits as it can show accurately, but sometimes showing too many digits may interfere with the interface. We humans tend not to worry about the 4th or 5th decimal place when talking about traveling speeds or distances in feet. We can actually tell the C++ program to show us only as much as we really care about.
There are two steps involved in this:
-- insert #include <iomanip> after the existing #include <iostream>
-- before doing any output of real numbers, cout << fixed << setprecision(2);
The presence or absence of these two lines will not affect your grade -- but they may help serve to make the results a little more meaningful.
How can gravity be calculated? The rock has a initial velocity of 0 when it's 10m above the ground. Using that information I got g= -20 / t^2 . What do I do after that?
Before you can start programming do the math and a test run on paper. If you algorithms give correct results start the coding. Also the beginners forum is mainly for syntax questions, and other beginner related posts.
@engr
No, gravity is not fixed. First, its 9.8m/s/s (more commonly, 9.8ms-2), but that just happens to be the standard gravitational force exerted (on average) on the face of the Earth.