Question
CSC 211 Intermediate Programming Lab9: Structures and Classes Problem 1. (max 60 points) (1) Design a Ball class which models a moving ball containing the
CSC 211 Intermediate Programming Lab9: Structures and Classes Problem 1. (max 60 points) (1) Design a Ball class which models a moving ball containing the private data members x, y, xSpeed and ySpeed Only the four ger() functions are defined inside of the class. For the rest of the functions include only their prototypes in the class Ball but define them outside of the class. Follow the details below: Four private data members x, y, xSpeed and ySpeed (all of them of double type) to maintain the position and speed of the ball. Public section: Include a default constructor without parameters, one constructor initializer with four parameters; two functions set specified below and four functions ger). A function setXY...), which sets the position of the ball and setXY Speed... ) to set the speed of the ball. A function move( no parameters), which increases x and y by xSpeed and ySpeed, respectively. A function print(), which prints the values stored in private data members of class Ball to 2 decimal places (max 10 points) (2) Write the definitions of all member functions outside of Ball class (exclude the definitions of four ger functions which should be defined inside of the class). (max 20 points) (3) In main() create two objects of class Ball using different constructors. Create two pointers to class Ball, and one reference varable to Ball class. Use dot operator, arrow operator and dereference pointer combined with dot operator and write statements which implement the member functions of Ball class. (max 20 points) (4) Continuation of main(): Create two anonymous objects of class Ball using both pointers created in (3) and write statements demonstrating memory leaks as well as dangling pointers and statements of how to avoid them. (max 10 points)
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