Answered step by step
Verified Expert Solution
Question
1 Approved Answer
1. Create a new project named lab6_1. You will be implementing an IceCream class. For the class attributes, let's stick to flavor, number of scoops,
1. Create a new project named lab6_1. You will be implementing an IceCream class. For the class attributes, let's 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 pric e should be set automatically based on the number of scoops entered. Som e other require ments 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 priv outside the class modifying price ate! You don't want anyone ii. Your constructor needs to call a set method which allows you to set the two member variables, thus takes wo arguments. In turn, the set method will call the individual setters for each member variable iii. Younumber 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. Don't 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
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