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

8. Consider the detinition ot the following class class productType publici //Li

ID: 3909266 • Letter: 8

Question

8. Consider the detinition ot the following class class productType publici //Line 1 //Line2 //Line 3 //Line 4 //Line 5 productType(atring, int, double, doubl)Line 6 productType () ; productType(int, double, double); productType(atring, string, string int, double, double) void set (string, string, string, int double, double) /Line /Line 9 void print eonati void setQuantitiesInstock (int x) void updateQuantitiesInStock (int x) int getQuantitiesInstock() const: //Line 10 //Line 11 /Line 12 void setPrice (double x) double getPrice) conat: void setDiacount (double a) : double getDiscount) consti //Line 13 //Line 14 //Line 15 //Line 16 /Line 17 //Line 18 //Lìn?19 //Line 20 /Line 21 //Line 22 //Line 23 //Line 24 private atring productNane: string idi string manufacturer int quantitiesInstock double pricei double discounti a. Give the line umber containing the constructor that is executed in each afthe following declarations i.preauctType productl; "General ool,35, 175.00,0.1 iii.proauctType produc2(D1290", 25, 375.00, 0.05) Iv. preductype proio, 0.50. 0.2) b, write the definition ofthe constructor m Line 4 so that the instance variables are initialized to " " " " " ".0.0·0, and o. D. respectively. c. Write the definition of the constructor in Line 5 so that the string instance variables are initialized toand the other instance variables are initialized according to the parameters. Instance variables quantitieaInStock.price, and diacount must he nonnegative d Write the definition ofthe constructor in Line 6 so that the instance var ables pzoauctiaí e and m ????facture: are nitialized to the empty string instance variable zdis niti Ized according to the first parameter and the remaining nstance variables are initialized according to the last three parameters. Instance varlables qwantitiesinStock. price. and dscount must be nonnegative. e. Write the definition of the constructor in Line 7 so that the instance variables are initialized according to the parameters. Instance variables quantitiesInStock, price.and discount must be nonnegative.

Explanation / Answer

a)
i)Line 4//default constructor will be executed
ii)Line 7//that was the only constructor which has 6 parameters
iii)Line 6// this was the only constructor that has match
iv)Line 5
b)
ProductType::ProductType()
{
productname="";
id="";
manufacturer="";
quantitiesInStock=0;
price=0.0;
discount=0.0;
}
c)
ProductType::ProductType(int i,double d,double e)
{
productname="";
id="";
manufacturer="";
if(i<0)
quantitiesInStock=0;
else
quantitiesInStock=i;
if(d<0)
price=0.0;
else
price = d;
if(e<0)
discount=0.0;
else
discount=e;
}
d)
ProductType::ProductType(string s,int i,double d,double e)
{
productname="";
id=s;
manufacturer="";
if(i<0)
quantitiesInStock=0;
else
quantitiesInStock=i;
if(d<0)
price=0.0;
else
price = d;
if(e<0)
discount=0.0;
else
discount=e;
}
e)
ProductType::ProductType(string s1,string s2,string s3,int i,double d,double e)
{
productname=s11;
id=s2;
manufacturer=s3;
if(i<0)
quantitiesInStock=0;
else
quantitiesInStock=i;
if(d<0)
price=0.0;
else
price = d;
if(e<0)
discount=0.0;
else
discount=e;
}

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