Question: I'm having difficulty solving this code. LAB (50%) The Canister Module Your task for this lab is to make a Canister module for holding liquid

I'm having difficulty solving this code.      LAB (50%) The Canister Module  Your task for this lab is to make a Canister module for holding liquid edible products.  A Canister is a cylindrical container that is make using its height and its diameter and is Labeled by the name of its content with an unknown length(i.e. Milk, Orange juice, etc...) that is dynamically held by a Canister. A Canister also holds the volume of the content it is holding making sure the liquid does not exceed its capacity. Any container that is filled higher than 0.267 centimetres from the top of the canister is considered unusable.  The smallest Canister can have a height and diameter of 10.0 by 10.0 centimetres and the largest one can be 40 by 30 respectively.    Calculating the capacity  A Canister's capacity (i.e. maximum amount of content it can hold) is calculated as follows:  PI: 3.14159265 (a global constant double value make in Canister.cpp) H: Height D: Diameter Capacity = PI x (H - 0.267) x (D/2) x (D/2) The Canister can be make in three different ways;  By default a Canister is make with the following height and diameter: 13.0 x 10.0 with no name and content amount of 0 (empty) Also a Canister can be make with its content name. In this case, the dimensions will be set to default values like the previous case and it will be empty. Finally, a Canister can be make using its height, diameter and content name. In any case, when a Canister is make using initial values and any of the values provided is invalid, the Canister is rendered unusable.    Pouring contents of one canister into another  You can fill the Canisters with the content they are labelled for. If too much is poured into the Canister, it will overflow and rendered unsalable.  You can pour all or some of the content of one Canister into another. If this results in mixed content, the target will be rendered unusable.  For example, if you can fill an empty orange juice Canister with the contents of a Canister holding Olive oil. Since the Orange juice Canister was empty everything will be OK and the Canister will be re-labelled as Olive oil. But if the orange juice canister has some orange juice in it, then it would have been rendered unusable.  To reuse an unusable Canister it must be reset and cleared.  You must design your code in a way that re-labelling and destruction of Canisters do not result in a memory leak.    Implementation  Make a class in a Module called Canister.    Private attributes (member variables)   char* m_contentName; // points to a dynamically allocated Cstring.  double m_diameter; // in centimeters  double m_hieght; // in centimeters  double m_contentVolume; // in CCs  bool m_usable; // a flag to identify if the Canister is usable or unusable   Private methods (member functions)   void setToDefault(); This function sets the attributes to their default values. It sets the content name pointer to null, height to 13.0, diameter to 10.0, content volume to 0.0 and usable flag to true.   bool isEmpty()const; Returns true is the content volume is less than 0.00001 CCs.   bool hasSameContent(const Canister& C)const; Compares the content name of this Canister with the one received from the argument C. Using strCmp in cstring.h, it returns true if both content names are not null and are identical. Otherwise, it returns false;  Note: If you have not completed your cstring module in workshop one, either you can get it from a friend and cite it in the comment section of the file, or use the standard header file and leave the cstring module files empty.   void setName(const char* Cstr); Sets the content name of the current Canister.  If the incoming Cstr is not null and the Canister is usable, it will delete the current content name, allocate memory to the length of Cstr (+1 for null) and copies the Cstr into the newly allocated memory. Otherwise, it will silently do nothing.    Constructors    No argument Constructor (defualt)  Sets the attributes to their default values    One argument Constructor:  Canister(const char* contentName); Sets the attributes to their default values (note: reuse code) Sets the Name to the incoming contentName argument. Canister(double hieght, double diameter, const char* contentName); Sets the attributes to their default values. If the dimensions are within acceptable values:  it will set the m_height and m_diameter to the corresponding argument values it will set the content volume to 0. it will set the content name to the corresponding argument value. If any of the dimensions have invalid values, it will set the Canister unusable    The Destructor  Deallocates the dynamic memory pointed by the content name attribute.    Public Methods (member variables)   void clear(); Clears an unusable Canister back to an empty Canister by:  deallocating the memory pointed by the content name attribute sets the content name attribute to nullptr sets the content volume attribute to 0.0 set the usable flag attribute to true  double capacity()const; returns the capacity as stated in Calculating the capacity   double volume()const; returns the content volume attribute   Canister& setContent(const char* contentName); It will set the Content name of the canister using the following rule and then returns the reference of the current object (i.e. *this):  If the contentName argument is null it will render the Canister unusable  else if the Canister is empty it will set the Name to the value pointed by the argument  else if the name of the Canister is not the same as the contentName argument it will render the Canister unusable.   Canister& pour(double quantity); Adds the quantity argument to the content volume of the Canister if the quantity fits in the Canister. Otherwise, it will render the Canister unusable and then returns the reference of the current object.  Use this rule to accomplish the above:  If the Canister is usable and the quantity is more than zero and if the sum of the quantity and the volume() is less than or equal to the capacity(), add the quantity to the content volume, otherwise set usable flag attribute to false.   Canister& pour(Canister& C); Pours the content of the Canister argument into the current Canister following the Specs stated at the top  Set the content name to the Canister argument using setContent().  if the volume() of the argument is greater than the capacity() minus the volume()  Reduce the content volume of the argument by capacity() minus volume() and then set the content volume to capacity()  else pour the content volume of the argument using pour() method and set the content volume of the argument to 0.0.  return the reference of the current object at the end.   std::ostream& display()const; Prints all the number values with one digit after the decimal point.  Prints the Canister in the following format:  In 7 spaces prints the capacity "cc (" height "x" diameter ") Canister" if unusable:  " of Unusable content, discard!" otherwise, if the content name is not null  " of " in 7 spaces prints the volume "cc " content name returns the cout at the end.    Tester program:  // Workshop 4: // Version: 0.9 // Date: 2021/02/04 // Author: Fardad Soleimanloo // Description: // This file tests the lab section of your workshop ///////////////////////////////////////////// #include  #include "Canister.h" using namespace std; using namespace sdds; void showCans(const char* title, const Canister* boxArray, int num = 1); int main() {  int i;  Canister C[]={  Canister(),  Canister(nullptr),  Canister("Orange Juice"),  Canister(40,30),  Canister(20, 10, "Olive Oil"),  Canister(9,20, "Bad ones"),  Canister(20,9),  Canister(41,20, "Bad ones"),  Canister(20,31, "Bad ones")  };  showCans("Five good ones and 4 bad ones:", C, 9);  for (i = 5; i < 9; i++) C[i].clear();  showCans("All good:", C, 9);  C[5].setContent("Milk").pour(500);  C[6].setContent("MilK");  showCans("Milk canisters", &C[5], 2);  C[6].pour(C[5]);  showCans("Poured one into another", &C[5], 2);  showCans("Poured 800ccs into the empty canister", &C[5].pour(800), 1);  C[6].pour(C[5]);  showCans("Filled one with the milk from another", &C[5], 2);  showCans("Poured 1500ccs of Olive oil into Olive oil canister", &C[4].pour(1500), 1);  C[5].pour(C[4]);  showCans("Filled can of milk with olive oil", &C[4], 2);  showCans("Poured too much into olive oil canister", &C[4].pour(1500), 1);  for (i = 3; i < 9; i++) C[i].setContent(nullptr);  showCans("All bad", &C[3], 6);  return 0; } void showCans(const char* title, const Canister* canArray, int num ) {  cout << " " << title << endl;  cout << " Capacity, Dimensions Volume Content" << endl;  cout << "------------------------------ --------- ---------------------------" << endl;  for (int i = 0; i < num; i++) {  canArray[i].display() << endl;  }  cout << "------------------------------------------------------------------------" << endl << endl; }   cstring.h code:  #ifndef _244_NAME_H_ // replace with relevant names  #define _244_NAME_H_    namespace sdds {     // Copies the srouce character string into the destination   void strCpy(char* des, const char* src);     // Copies the source character string into the destination upto "len"   // characters. The destination will be null terminated only if the number   // of the characters copied is less than "len"   void strnCpy(char* des, const char* src, int len);       // Compares two C-strings   // returns 0 i thare the same   // return > 0 if s1 > s2   // return < 0 if s1 < s2   int strCmp(const char* s1, const char* s2);       // returns 0 i thare the same   // return > 0 if s1 > s2   // return < 0 if s1 < s2   int strnCmp(const char* s1, const char* s2, int len);       // returns the lenght of the C-string in characters   int strLen(const char* s);       // returns the address of first occurance of "str2" in "str1"   // returns nullptr if no match is found   const char* strStr(const char* str1, const char* str2);       // Concantinates "src" C-string to the end of "des"   void strCat(char* des, const char* src);  }  #endif    cstring.cpp code:  #include "cstring.h"  namespace sdds {       int strLen(const char* s) {   int length = 0;   while (s[length] != '\0') {   length++;   }   return length;   }     void strCpy(char* des, const char* src) {   int i = 0;   while (src[i] != '\0') {   des[i] = src[i];   i++;   }   des[i] = '\0';   }       void strnCpy(char* des, const char* src, int length) {   int i = 0;   while (i < length && src[i] != '\0') {   des[i] = src[i];   i++;   }   if (i != length) {   des[i] = '\0';   }   }       int strCmp(const char* string1, const char* string2) {   int i = 0;   while (string1[i] != '\0' && string2[i] != '\0') {   if (string1[i] > string2[i]) {   return 1;   }   if (string1[i] < string2[i]) {   return -1;   }   i++;   }   if (string1[i] == '\0' && string2[i] == '\0') {   return 0;   }   if (string2[i] != '\0') {   return -1;   }   return 1;   }       int strnCmp(const char* string1, const char* string2, int length) {   int i = 0;   while (i < length && string1[i] != '\0' && string2[i] != '\0') {   if (string1[i] > string2[i]) {   return 1;   }   if (string1[i] < string2[i]) {   return -1;   }   i++;   }   if (i == length) {   return 0;   }   if (string2[i] != '\0') {   return -1;   }   return 1;   }       const char* strStr(const char* str1, const char* str2)   {   const char* faddress = nullptr;   int i, flen = strLen(str2), slen = strLen(str1);   for (i = 0; i < slen - flen && strnCmp(&str1[i], str2, flen); i++);   if (i < slen - flen) {   faddress = &str1[i];   return faddress;   }         return nullptr;   }     void strCat(char* des, const char* src) {   int desSize = strLen(des);   int i = 0;   while (src[i] != '\0') {   des[desSize + i] = src[i];   i++;   }   des[desSize + i] = '\0';   return;   }  }    Execution sample:  Five good ones and 4 bad ones: Capacity, Dimensions Volume Content ------------------------------ --------- --------------------------- 1000.0cc (13.0x10.0) Canister 1000.0cc (13.0x10.0) Canister 1000.0cc (13.0x10.0) Canister of 0.0cc Orange Juice 28085.6cc (40.0x30.0) Canister 1549.8cc (20.0x10.0) Canister of 0.0cc Olive Oil 1000.0cc (13.0x10.0) Canister of Unusable content, discard! 1000.0cc (13.0x10.0) Canister of Unusable content, discard! 1000.0cc (13.0x10.0) Canister of Unusable content, discard! 1000.0cc (13.0x10.0) Canister of Unusable content, discard! ------------------------------------------------------------------------  All good: Capacity, Dimensions Volume Content ------------------------------ --------- --------------------------- 1000.0cc (13.0x10.0) Canister 1000.0cc (13.0x10.0) Canister 1000.0cc (13.0x10.0) Canister of 0.0cc Orange Juice 28085.6cc (40.0x30.0) Canister 1549.8cc (20.0x10.0) Canister of 0.0cc Olive Oil 1000.0cc (13.0x10.0) Canister 1000.0cc (13.0x10.0) Canister 1000.0cc (13.0x10.0) Canister 1000.0cc (13.0x10.0) Canister ------------------------------------------------------------------------  Milk canisters Capacity, Dimensions Volume Content ------------------------------ --------- --------------------------- 1000.0cc (13.0x10.0) Canister of 500.0cc Milk 1000.0cc (13.0x10.0) Canister of 0.0cc MilK ------------------------------------------------------------------------  Poured one into another Capacity, Dimensions Volume Content ------------------------------ --------- --------------------------- 1000.0cc (13.0x10.0) Canister of 0.0cc Milk 1000.0cc (13.0x10.0) Canister of 500.0cc Milk ------------------------------------------------------------------------  Poured 800ccs into the empty canister Capacity, Dimensions Volume Content ------------------------------ --------- --------------------------- 1000.0cc (13.0x10.0) Canister of 800.0cc Milk ------------------------------------------------------------------------  Filled one with the milk from another Capacity, Dimensions Volume Content ------------------------------ --------- --------------------------- 1000.0cc (13.0x10.0) Canister of 300.0cc Milk 1000.0cc (13.0x10.0) Canister of 1000.0cc Milk ------------------------------------------------------------------------  Poured 1500ccs of Olive oil into Olive oil canister Capacity, Dimensions Volume Content ------------------------------ --------- --------------------------- 1549.8cc (20.0x10.0) Canister of 1500.0cc Olive Oil ------------------------------------------------------------------------  Filled can of milk with olive oil Capacity, Dimensions Volume Content ------------------------------ --------- --------------------------- 1549.8cc (20.0x10.0) Canister of 799.9cc Olive Oil 1000.0cc (13.0x10.0) Canister of Unusable content, discard! ------------------------------------------------------------------------  Poured too much into olive oil canister Capacity, Dimensions Volume Content ------------------------------ --------- --------------------------- 1549.8cc (20.0x10.0) Canister of Unusable content, discard! ------------------------------------------------------------------------  All bad Capacity, Dimensions Volume Content ------------------------------ --------- --------------------------- 28085.6cc (40.0x30.0) Canister of Unusable content, discard! 1549.8cc (20.0x10.0) Canister of Unusable content, discard! 1000.0cc (13.0x10.0) Canister of Unusable content, discard! 1000.0cc (13.0x10.0) Canister of Unusable content, discard! 1000.0cc (13.0x10.0) Canister of Unusable content, discard! 1000.0cc (13.0x10.0) Canister of Unusable content, discard! ------------------------------------------------------------------------ 

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!