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

8. Consider the definition of the following class : class product Type public: p

ID: 3909309 • Letter: 8

Question

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

Below is the C++ code I hope that i have provided sufficient comments for your better understanding

#include <bits/stdc++.h>
using namespace std;

class ProductType
{
private:
string productname,id,manufacturer;
int quantityinstock;
double price,discount;
  
public:
//default constructor
ProductType()
{
}

//parameterized constructor
ProductType(int n,double d1,d2)
{
quanityinstock=n;
price=d1;
discount=d2;
}
ProductType(string s,int n,double d1,d2)
{
productname=s;
quantityinstock=n;
price=d1;
discount=d2;
}
ProductType(string s1,string s2,string s3,int n,double d1,d2)
{
productname=s1;
id=s2;
manufacturer=s3;
quantityinstock=n;
price=d1;
discount=d2;
}

//set the values of variables
void sets(string s1,string s2,string s3,int n,double d1,d2)
{
productname=s1;
id=s2;
manufacturer=s3;
quantityinstock=n;
price=d1;
discount=d2;
}

void print()
{
cout<<"Product name : "<<productname<<endl;
cout<<"id : "<<id<<endl;
cout<<"Manufacturer : "<<manufacturer<<endl;
cout<<"stock left : "<<quantityinstock<<endl;
cout<<"Price is : "<<price<<endl;
cout<<"Discount : "<<discount<<endl;
}

void setprice(double d)
{
price=d;
}


double getprice()
{
return price;
}

void setDiscount(double d)
{
discount=d;
}

double getDiscount()
{
return discount;
}
};

Hope i have answered your question satisfactorily.Leave doubts in comment section if any.

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