Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Answer and explain the following problems. Also, how do you do the 1 and 2 requirements? Design a class Cannonball to model a cannonball that
Answer and explain the following problems. Also, how do you do the 1 and 2 requirements?
Design a class Cannonball to model a cannonball that is fired into the air. A ball hasA flight time after fired. An x- and a y-position. An x- and a y-velocity. Supply the following member functions: A constructor with the appropriate variables initialized. Assume the cannonball starts at the origin (0,0). A member function move(double sec) that moves the ball to the next position for a given time increment (sec). Using the projectile motion formula and assuming negligible air resistance. Considering the gravitational acceleration of -9.81 m/sec. 1. First compute the distance traveled in seconds, using the current velocities, then update the x- and y-positions. 2. Then update the y-velocity; the x-velocity is unchanged. 3. Move should not print anything to the console. A member function shoot whose parameters are the angle a and initial velocity v 1. Compute the x-velocity as v*cos(a) and the y-velocity as v*sin(a). 2. Then keep calling move with a time interval of 0.1 seconds until the y-position is s 0 3. Display the (x, y) position and flight time after every 10 moves and when the ball hits the ground. Use setw(8) and setprecision(2) to format the positions; Use setw(4) and setprecision(1) to format the times. Use this class in a program that prompts the user for the starting angle and the initial velocity. Then call shoot. Requirements: 1. You must submit three c++ files: 1. one header (.h) file containing the declaration of the class, 2. one .cpp file containing the member functions, 3. one .cpp file containing the main function. 2. Both move and shoot should be void functions. The only input to either should be (double sec) to move. 3. Return a termination message when the ball hits the ground 4. Please test for an angle of 30" and 100 m/sec launch velocity. All units can be assumed to be metric. Ex: Please enter the starting angle: 30 Please enter the initial velocity of the cannonball: 108 The x and y positions are: 86. 60m and 45.09m, respectively, after 1.0s The x and y positions are: 173. 21m and 80.38m, respectively, after 2.0s The x and y positions are: 259. 81m and 105.85m, respectively, after 3.0s The x and y positions are: 346. 41m and 121.52m, respectively, after 4.0s The x and y positions are: 433.01m and 127.37m, respectively, after 5.0s The x and y positions are: 519.62m and 123.42m, respectively, after 6.0s The x and y positions are: 606. 22m and 109.65m, respectively, after 7.0s The x and y positions are: 692.82m and 86.08m, respectively, after 8.0s The x and y positions are: 779. 42m and 52.69m, respectively, after 9.0s The x and y positions are: 866. 83m and 9.50m, respectively, after 10.0s The x and y positions are: 883. 35m and -0.32m, respectively, after 10.2s BME303_Lab6_P4_Cannonball impact! Ending simulation! Process finished with exit code 0\fTips: Change your CMakeList.txt this way to make sure the codes can be executed normally. cmake_minimum_required (VERSION 3.21) 2 project (keys) 4 set (CMAKE_CXX_STANDARD 14) Includes all your header files and source files in one executable. add_executable (P4 BME303_Lab6_P4 . cpp For the main function 8 BME303_Lab6_P4_Cannonball. cppStep 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