Question: Ice Cream class c++ Create a new project. You will be implementing an IceCream class 1. You will be implementing an IceCream class. For the
Ice Cream class c++
Create a new project. You will be implementing an IceCream class
1. You will be implementing an IceCream class. For the class attributes, lets stick to flavor, number of scoops, and price (in cents). Note that the price per scoop of any flavor is 99 cents. Therefore, allow the flavor and scoops to be set directly, but not the price! The price should be set automatically based on the number of scoops entered. Some other requirements:
i. A default constructor and a constructor with parameters for your flavor and number of scoops member variables. You should also include setters and getters for these private member variables. However, make sure that the setter for price is private! You dont want anyone outside the class modifying price.
ii. Your constructor needs to call a set method which allows you to set the two member variables, thus takes two arguments. In turn, the set method will call the individual setters for each member variable.
iii. You number of scoops setter needs to throw an exception if a valid number for scoops is not used (only positive numbers should work). This means that back in your main, you will also have a try...catch block to catch this exception. Dont forget to include the stdexcept library. Use a general run-time exception like shown before: if(some condition) do some stuff; else throw runtime_error( This is not a valid number of scoops.); Which means the catch should be catching a runtime_error object.
iv. You will also make use of the const keyword to indicate which methods are not modifying the object.
v. Demonstrate the use of your IceCream class by creating objects of your class type, setting them to different values, and then printing out their information. Make sure to also show an example of an incorrect value being assigned to a member variable, and the program throwing an exception.
Potential sample run: 1 scoop(s) of vanilla ice cream costs 99 cents. 2 scoop(s) of cookie dough ice cream costs 198 cents.
Lab 6 Error: This is not a valid number of scoops. 2 scoop(s) of strawberry ice cream costs 198 cents.
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
