Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

10a) b) c) etc.. thank you 8. Consider the definition of the following class : c

ID: 3891322 • Letter: 1

Question

10a)

b)

c) etc.. thank you

8. Consider the definition of the following class : class product Type public: product Type(); product Type(int, double, double); product Type(string, int, double, double); product Type(string, string, string int, double, double); //Line 1 //Line 2 //Line 3 //Line 4 //Line 5 //Line 6 //Line 7 void set (string, string, string, int, double, double); void print() const; //Line 8 //Line 9 void setQuantities InStock (int x); void update Quantities Instock (int x); int getQuantitiesInStock() const; //Line 10 //Line 11 //Line 12 void setPrice (double x); double getPrice () const; void setDiscount (double d); double getDiscount() const; //Line 13 //Line 14 //Line 15 //Line 16 private: //Line 17 string product Name; //Line 18 string id; //Line 19 string manufacturer; //Line 20 int quantitiesInStock; //Line 21 double price; //Line 22 double discount; //Line 23 //Line 24 Consider the definition of the class product Type as given in Exercise 8. Answer the following questions. (1,2,3,5,7) a Write the definition of the function set so that instance variables are set according to the paramaters. Instance variables quantities Instock, price, and discount must be non negative. Write the definition of the function print to output the values of the instance variables. Write the definition of the function setQuantities InStock to set the value of the instance variable quantitiesInStock accord- ing to the parameter. Write the definition of the function update quantities Instock to update the value of instance variable quantities Instock by adding the value of the parameter. e Write the definition of the function getQuantitiesInStock to return the value of instance variable quantities Instock. Write the definition of the function set Price to set the value of the instance variable price according to the parameter. 9 Write the definition of the function getPrice to return the value of the instance variable price. h. Write the definition of the function setDiscount to set the value of the instance variable discount according to the parameter. 1. Write the definition of the function getDiscount to return the value of the instance variable discount.

Explanation / Answer

10 a)

void productType::set(string a, string b, string c,int d,double e, double f){

       productName = a;
       id = b;
       manufacturer = c;
       if (d >= 0)   // otherwise unchanged
          quantitiesInStock = d;
       else
          cout << "Invald value for quantities in stock ";
       if (e >= 0)   // otherwise unchanged
         price = e;
       else
          cout << "Invald value for price ";
       if (f >= 0)   // otherwise unchanged
         discount = f;
       else
          cout << "Invald value for discount ";
}

10 b)

   void productType::print() const{
      cout << "Name:" << productName << endl;
      cout << "Id:" << id << endl;
      cout << "Manufacturer:" << manufacturer << endl;
      cout << "Quantities in stock:" << quantitiesInStock << endl;
      cout << "Price:" << price << endl;
      cout << "Discount:" << discount << endl;
   }

10 c)

   void productType::setQuantitiesInStock(int x){
       if (x >= 0)
          quantitiesInStock = x;
       else
          cout << "Invalid value ";
   }

10 d)

   void productType::updateQuantitiesInStock(int x){

       int temp = quantitiesInStock + x;
       if (temp >= 0){
          quantitiesInStock = temp;
       }
       else {   // in case x is -ve. decreaseing the quantities
          cout << "Quantity can not be reduced by the given amount as it is less than the requested quantity ";
          cout << "Quantities in stock are not changed ";
       }
   }

10 e)

   int productType::getQuantitiesInStock() const{
          return quantitiesInStock;
   }

10 f)

   void productType::setPrice( double x){
          if (x >= 0)
              price = x;
          else
              cout << "Invalid value ";
   }

10 g)

   double productType::getPrice() const{
       return price;
   }


10 h)

   void productType::setDiscount( double d){
          if (d >= 0)
              discount = d;
          else
              cout << "Invalid value ";
   }

10 i)

   double productType::getDiscount() const{
       return discount;
   }

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at drjack9650@gmail.com
Chat Now And Get Quote