Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Programming Project 2 The physics of golf Problem statement: Interestingly, golf involves a lot of physics. This program will determine how far a ball will
Programming Project 2 The physics of golf Problem statement: Interestingly, golf involves a lot of physics. This program will determine how far a ball will travel when struck with a given club and with a given swing strength. This program will use material covered through Chapter 5. 189 yards Time = 5.940 sec Vzere= 45 yards / sec Program specifics: 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 "golf.txt". You can make this file by creating it with these values: 10.2 3.27 53.5 -1.75 19.6 4.89 The file contains six numbers-a1, b1, a2, b2, a3, and b3that 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; club length club angle e. Determines the distance the ball travels, how far it lands from the hole that is on the green (the "pin"), and whether it hits on the green. You can assume 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/s is the acceleration of gravity in English unitsmake 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 or accuracy), and "Yes" if the ball hits on the green, or else "No". Assume that the ball does not roll after hitting the ground (really wet ground). g. The table must have appropriate labels. h. If the ball does not hit the green, the program continues to ask the user for another club number and swing speed. i. If the club number entered is 99, the program ends without prompting for a club number and without printing the results table. One possible output for the program would look like this: CA C: Documents and Settings\crs1.000 y Documents MyWebSites Stengerands... - OX Input the distance to the pin in yards: 150 In put the depth of the green in yards: 10 Input a club number from 2 to 10 hit green? No Input a club number from 2 to 10 error(yds> hit green? 8 No Input a club number from 2 to 10 hit green? distance(yds) 149 Yes Press any key to continue ... golf.txt 10.2 3.27 53.5 -1.75 19.6 4.89 Programming Project 2 The physics of golf Problem statement: Interestingly, golf involves a lot of physics. This program will determine how far a ball will travel when struck with a given club and with a given swing strength. This program will use material covered through Chapter 5. 189 yards Time = 5.940 sec Vzere= 45 yards / sec Program specifics: 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 "golf.txt". You can make this file by creating it with these values: 10.2 3.27 53.5 -1.75 19.6 4.89 The file contains six numbers-a1, b1, a2, b2, a3, and b3that 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; club length club angle e. Determines the distance the ball travels, how far it lands from the hole that is on the green (the "pin"), and whether it hits on the green. You can assume 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/s is the acceleration of gravity in English unitsmake 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 or accuracy), and "Yes" if the ball hits on the green, or else "No". Assume that the ball does not roll after hitting the ground (really wet ground). g. The table must have appropriate labels. h. If the ball does not hit the green, the program continues to ask the user for another club number and swing speed. i. If the club number entered is 99, the program ends without prompting for a club number and without printing the results table. One possible output for the program would look like this: CA C: Documents and Settings\crs1.000 y Documents MyWebSites Stengerands... - OX Input the distance to the pin in yards: 150 In put the depth of the green in yards: 10 Input a club number from 2 to 10 hit green? No Input a club number from 2 to 10 error(yds> hit green? 8 No Input a club number from 2 to 10 hit green? distance(yds) 149 Yes Press any key to continue ... golf.txt 10.2 3.27 53.5 -1.75 19.6 4.89
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started