Hello the assignment is from chapter 10 and it is question number 10. can you pl
ID: 3882178 • Letter: H
Question
Hello
the assignment is from chapter 10 and it is question number 10. can you please give the answers of a, b, c, d from question 10. please give the answers seperatly that way i can understand which one is a , which one b and etc.
i only want question number-10
Which functian Consider the definition of the class productType as give Answer the following questions.(1,2, 3, 5,7 . Write the definition of the function set 10. o that instance nsta variables are set according to the paramaters. Inn quantitiesInstock, price, and diacount must Write the definition of the function print to o the instance variables of Write the definition of the function setquantitiest set the value of the instance variable quantitiesInstock ing to the parameter. d. Write the definition of the function updateQuantits titiestnStock to update the value of instance variable quantitlestne adding the value of the parameter.Explanation / Answer
a) In the class productType, the set function definition will be as :
in the definition its sets the value given in the parameter, if the qtyStock, pprice and discount contains negative value it stores the value 0.
void set(string pName, string Pid, string pManufacturer, int qtyStock, double pprice, double pdiscount) {
productName = pName; // stores the productName
id = Pid; //stores product id
manufacturer = pManufacturer; //stores the manufacturer of the product
if (qtyStock > 0) //checks for nonnegative number
quantitiesInStock = qtyStock; //if qtyStock is nonnegative stores the value
else
quantitiesInStock = 0; // if negative stores 0
if (pprice > 0)//checks for nonnegative number
price = pprice; //if pprice is nonnegative stores the value
else
price = 0; // if negative stores 0
if (pdiscount > 0)//checks for nonnegative number
discount = pdiscount; //if discount is nonnegative stores the value
else
discount = 0; //if negative stores 0
}
b) print function prints the value stored in the members of the class
void print() {
cout << "Product Name :" << productName << endl; // prints pName
cout << "Product id :" << id << endl; //prints product id
cout << "Manufacturer :" << manufacturer << endl; //prints manufacturer
cout << "quantitiesInStock :" << quantitiesInStock << endl; //prints quantitiesInStock
cout << "price :" << price << endl; //prints price
cout << "Discount " << discount << endl; //prints discount
}
c) setQuantitiesInStock function set the value of instance variable quantitiesInStock to x.
void setQuantitiesInStock(int x){
quantitiesInStock = x;
}
d)updateQuantitiesInStock function set the value of instance variable quantitiesInStock to quantitiesInStock plus x.
void updateQuantitiesInStock(int x){
quantitiesInStock = quantitiesInStock + x;
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.