# programming project involving physics of golf (Don't know how to start HELP please)

• 02-15-2011
taker328
programming project involving physics of golf (Don't know how to start HELP please)
I am new to this forum and I am pretty new to C++ programming just started this semester and have never been exposed to it before. I felt like I was getting a grasp in the beginning but now everything is moving so fast and I feel like I'm loosing that grasp quickly. My professors and TA's don't seem to help even though I go to office hours and this is my last hope for understanding this. Of course I don't expect people to write my program and that would be wrong, but I just need the push in the right direction of where i need to go with this problem and this forum might one of my last hopes. Anyway, here is the problem statement and I really hope someone out there can help me.

-------------------------------------------------------------------------------------------------------------------
This program will determine how far a golf ball will travel when struck with a given club and with a given swing strength.

Write a C++ program that does the following:

a. Asks the user for the distance to the pin and the depth of the green (both in yards). (Note: The pin is the hole in the green, and the depth is the diameter of the green, assuming it is circular.)

b. Asks the user for an integer club number from 2 to 10, where 10 is the pitching wedge. If the user enters an invalid club number, the program prints a warning and asks for the club number again.

c. Asks the user for a swing type, from 1 to 4, where 4 is a full swing, 3 is a three-quarters swing, 2 is a half swing, and 1 is a quarter swing. It would be nice if you checked to make sure the swing is a valid number, but it is not required.

d. Reads from a data file (right click here for the data file golf.txt) . The file contains six numbers— a1, b1, a2, b2, a3, and b3—that are constants for the following equations:

clubangle(degrees) = a1 + b1*0.85*clubnumber; (see figure at right)

clublength(inches) = a2 + b2*1.05*clubnumber; (see figure at right)

clubspeed(yards/s) = 1.1*(a3 + b3*swingnumber)*(clublength(inches)/40)2;

e. Determines the distance the ball travels, how far it lands from the hole on the green (the "pin"), and whether it hits on the green. You can assume that the ball travels perfectly straight, there is no wind resistance, and the pin is in the center of the green. To determine distance the ball travels use the following equation:

distance = (club speed)2 * sin(2*club angle in radians)/g

(g = 32.2 ft/s2 is the acceleration of gravity in English units—make sure you convert your units correctly to get distance in yards).

f. The program reports to the screen, in a well-formatted table: the club used, the swing number, the distance the ball travels, the distance from the pin that the ball hits the ground (i.e., the error), and "Yes" if the ball hits on the green, or else "No". Assume that the ball does not roll after hitting the ground. Make sure the table has appropriate labels.

g. If the ball does not hit the green, the program continues to ask the user for another club number and swing speed. If the ball does hit the green, the program automatically ends.

h. If the club number entered is 99, the program ends without prompting for a club number,and without printing the results table.
• 02-16-2011
iMalc
Start by making a project with an empty main function and compiling it. I'm serious... this is always the first step, and you can't get anywhere else until you can do that. If you need help there then ask about that.

Next, work your way through from 'a' to 'h' in that order. Whether you get stuck on 'a', 'd', or 'g' doesn't matter. The main thing is that you make a start, have a go doing whatever bits you can do, and then come back with some slightly more technical questions.

We can't really do anything else for you until you've made a real attempt.
• 02-16-2011
kittykitty
You might try this as a start. The output and behavior will probably be off because I couldn't understand parts of the problem statement given here.

With a golf.txt that looks like:
Code:

```\$ cat golf.txt 1 2 3 4 5 6```
This program will produce output like:
Code:

```\$ ./golfproject Distance (in yards): 50 Depth (in yards): 4 Club number (2-10): 11 Please enter a number between 2 and 10. Club number (2-10): 3 Swing type (1-4): 0 Please enter a number between 1 and 4. Swing type (1-4): 3 Club #  Swing #  Distance(y) Error(y) Hit? ----------------------------------------------     3        3        0.09    3.91  No Distance (in yards): 0 Depth (in yards): 0 Club number (2-10): 99```