Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

It C++ 2.1 Three Candies Written for you is a Candy class and a Chocolate sub-class (of Candy). You should add two more subclasses, for

image text in transcribed

image text in transcribed

image text in transcribed

image text in transcribed

image text in transcribed

image text in transcribed

It C++

2.1 Three Candies Written for you is a Candy class and a Chocolate sub-class (of Candy). You should add two more subclasses, for SoftCandy and HardCandy. HardCandy has a property (member variable for transparency, SoftCandy has a property of flavor. Adjust the constructor of each to ask for these just like Chocolate's percent property). Also set up dot-h files and destructors. The test code just creates and destroys a candy (one test for each of the 3 sub-types) LAB ACTIVITY 2.1.1: Three Candies 0/3 Current file: main.cpp Load default template... 1 /I ThreeCandies 2 // lab for ITP-165 3 // Nathan and Ray and Barry 2018, 2019 4/*It asks the use for a type of candy, then asks for 5 information about that candy (some of which is for 6 all candies, some for just this type Display info 7 and then destruct - should see the destructor in two 8 stages (the sub-type of candy first, then Candy) 10 1* 11 Choose from one of the following: 12 1. Chocolate 13 2. Hard Candy 14 3. Soft Candy 15 Please Choose: 16 1 17 Name: 18 Hershey Bar 19 Calories 20 250 41 Name: Life Savers 42 calories: 18 43 Transparency: 85 44 Destroying Hard Candy 45 Destroying candy! 46 47 Choose from one of the following: 481. Chocolate 49 2. Hard Candy 50 3. Soft Candy 51 Please Choose: 52 3 53 Name: 54 Gumdrops 55 Calories: 56 35 57 Flavor 58 lemon 59 Name: Gumdrops 60 calories: 35 61 Flavor: 1emon 62 Destroying Soft Candy 63 Destroying candy! 64. 65 66 / 67 68 //#include "stdafx.h" 69 #1 nclude "chocolate . h" 70 #include "HardCandy.h" 71 #include "SoftCandy.h" 72 73 #includedstream 74 #include 75 using namespace std; 76 77 int main() 79 Candy myCandy nullptr; /I to hold the test object 80 3 2 int choice - 0; /1 1-3 based on choice below 81 82 83 84 85 86 87 do std::cout > choice; while (choice-1 && choice-2 && choice -3); 89 90 91 92 93 94 95 96 97 98 I construct the type of candy all questions about the // particulars are in the constructors switch (choice) case 1: myCandy new Chocolate(); break; //case 2: myCandy-new HardCandy ); break; /I put these back in when //case 3: myCandy-new SoftCandy); break; // you are ready myCandy->display; // make sure info is in there right 100 delete myCandy; /I test the destructors 11 myCandy nullptr; I/ clear pointer, good form 102 103 1041 return 0; 2.1 Three Candies Written for you is a Candy class and a Chocolate sub-class (of Candy). You should add two more subclasses, for SoftCandy and HardCandy. HardCandy has a property (member variable for transparency, SoftCandy has a property of flavor. Adjust the constructor of each to ask for these just like Chocolate's percent property). Also set up dot-h files and destructors. The test code just creates and destroys a candy (one test for each of the 3 sub-types) LAB ACTIVITY 2.1.1: Three Candies 0/3 Current file: main.cpp Load default template... 1 /I ThreeCandies 2 // lab for ITP-165 3 // Nathan and Ray and Barry 2018, 2019 4/*It asks the use for a type of candy, then asks for 5 information about that candy (some of which is for 6 all candies, some for just this type Display info 7 and then destruct - should see the destructor in two 8 stages (the sub-type of candy first, then Candy) 10 1* 11 Choose from one of the following: 12 1. Chocolate 13 2. Hard Candy 14 3. Soft Candy 15 Please Choose: 16 1 17 Name: 18 Hershey Bar 19 Calories 20 250 41 Name: Life Savers 42 calories: 18 43 Transparency: 85 44 Destroying Hard Candy 45 Destroying candy! 46 47 Choose from one of the following: 481. Chocolate 49 2. Hard Candy 50 3. Soft Candy 51 Please Choose: 52 3 53 Name: 54 Gumdrops 55 Calories: 56 35 57 Flavor 58 lemon 59 Name: Gumdrops 60 calories: 35 61 Flavor: 1emon 62 Destroying Soft Candy 63 Destroying candy! 64. 65 66 / 67 68 //#include "stdafx.h" 69 #1 nclude "chocolate . h" 70 #include "HardCandy.h" 71 #include "SoftCandy.h" 72 73 #includedstream 74 #include 75 using namespace std; 76 77 int main() 79 Candy myCandy nullptr; /I to hold the test object 80 3 2 int choice - 0; /1 1-3 based on choice below 81 82 83 84 85 86 87 do std::cout > choice; while (choice-1 && choice-2 && choice -3); 89 90 91 92 93 94 95 96 97 98 I construct the type of candy all questions about the // particulars are in the constructors switch (choice) case 1: myCandy new Chocolate(); break; //case 2: myCandy-new HardCandy ); break; /I put these back in when //case 3: myCandy-new SoftCandy); break; // you are ready myCandy->display; // make sure info is in there right 100 delete myCandy; /I test the destructors 11 myCandy nullptr; I/ clear pointer, good form 102 103 1041 return 0

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions