Can:The following Can class encapsulate the type of the drink it hold and the Can's size:class Can{ char m_content[21]; int m_size; // in mililiterspublic:};Complete the code of this class by adding a...


Can:





The following Can class encapsulate the type of the drink it hold and the Can's size:





class Can{


char m_content[21];


int m_size; // in mililiters

public:





};

Complete the code of this class by adding a read and a write function as follows.





1- The read function read a comma-separated value of content and size ending with a newline; we assume that the user will not make a mistake in data entry.





Beer,250





The above is a 250 cc Can of Beer













2- The write function displays the above as follows:





The size and then the content name in 20 characters, right justified and spaces filled with dots:





250 ................Beer





3- A Can object is always constructed as an empty Can with nothing in it.





Tray:





Complete the following Case class. A Case can come in different sizes; between 6 and 28.





class Case{


Can* m_cans; // dynamic array of cans


int m_size; // maximum number of mugs on the case


int m_num; // number of cans in the case

public:










};

4- Construct a Case using an integer for its size. If the size is less than 6 or more than 28, then the Case should be set to an invalid empty state.













5- When a Case goes out of scope all allocated memory will be deleted.













6- Add a setEmpty() method o set the Case to an invalid empty state.













7- If a Case object is casted to a boolean, it should return true of the Case is a valid tray or false if it is not.













8- Overload the += operator, returning the reference of the Case object and receiving a Can by value. This operator should add the Can besides the Cans already in the case. Any attempt to add a Can to an already full Case, will render the Case invalid (in safe empty state).













9- Create a display funciton printing all the Cans in the Case only if the Case is in a valid state, othewise, nothing will happen.













10- Create a read function to read all the empty Cans in the Case. For example if the Case has 12 spaces and 10 non-emtpy Cans, then the last 2 will be read from keyboard and the Case will be full afterwards.

Nov 04, 2022
SOLUTION.PDF

Get Answer To This Question

Related Questions & Answers

More Questions ยป

Submit New Assignment

Copy and Paste Your Assignment Here