Use the definition of the class productType to answer the questions a,b,c,d, and e pictured below.

EBK JAVA PROGRAMMING
9th Edition
ISBN:9781337671385
Author:FARRELL
Publisher:FARRELL
Chapter10: Introduction To Inheritance
Section: Chapter Questions
Problem 14RQ
icon
Related questions
Question

Use the definition of the class productType to answer the questions a,b,c,d, and e pictured below.

 

*class productType is also pictured below

*Everything is in C++

class productType
{
public:
productType ();
productType (int, double, double);
productType (string, int, double, double);
productType (string, string, string,
//Line 1
//Line 2
//Line 3
//Line 4
//Line 5
//Line 6
int, double, double);
//Line 7
void set (string, string, string, int,
double, double);
void print () const;
//Line 8
//Line 9
void setQuantitiesInStock (int x);
void updateQuantitiesInStock (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:
string productName;
string id;
string manufacturer;
int quantitiesInStock;
double price;
double discount;
};
//Line 17
//Line 18
//Line 19
//Line 20
//Line 21
//Line 22
//Line 23
//Line 24
1
a. Give the line number containing the constructor that is executed
in each of the following declarations.
i.
productType product2 ( "Microwave", "M3562",
productType productl;
ii.
"GeneralPoo1", 35, 175.00, 0.1);
productType product3 ("D1290", 25, 375.00, 0.05);
productType product4 (10, 8.50, 0.2);
b. Write the definition of the constructor in Line 4 so that the instance
variables are initialized to "", "", "", 0, 0.0, and o.0, respectively.
iii.
iv.
c. Write the definition of the constructor in Line 5 so that the string
instance variables are initialized to "", and the other instance variables
Copyright 2018 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. WCN 02-200-203
Transcribed Image Text:class productType { public: productType (); productType (int, double, double); productType (string, int, double, double); productType (string, string, string, //Line 1 //Line 2 //Line 3 //Line 4 //Line 5 //Line 6 int, double, double); //Line 7 void set (string, string, string, int, double, double); void print () const; //Line 8 //Line 9 void setQuantitiesInStock (int x); void updateQuantitiesInStock (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: string productName; string id; string manufacturer; int quantitiesInStock; double price; double discount; }; //Line 17 //Line 18 //Line 19 //Line 20 //Line 21 //Line 22 //Line 23 //Line 24 1 a. Give the line number containing the constructor that is executed in each of the following declarations. i. productType product2 ( "Microwave", "M3562", productType productl; ii. "GeneralPoo1", 35, 175.00, 0.1); productType product3 ("D1290", 25, 375.00, 0.05); productType product4 (10, 8.50, 0.2); b. Write the definition of the constructor in Line 4 so that the instance variables are initialized to "", "", "", 0, 0.0, and o.0, respectively. iii. iv. c. Write the definition of the constructor in Line 5 so that the string instance variables are initialized to "", and the other instance variables Copyright 2018 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. WCN 02-200-203
are initialized according to the parameters. Instance variables
quantitiesInstock, price, and discount must be nonnegative.
d. Write the definition of the constructor in Line 6 so that the
instance variables productName and manufacturer are initial-
ized to the empty string, instance variable id is initialized accord-
ing to the first parameter, and the remaining instance variables
are initialized according to the last three parameters. Instance
variables quantitiesInStock, price, and discount must be
nonnegative.
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.
Transcribed Image Text:are initialized according to the parameters. Instance variables quantitiesInstock, price, and discount must be nonnegative. d. Write the definition of the constructor in Line 6 so that the instance variables productName and manufacturer are initial- ized to the empty string, instance variable id is initialized accord- ing to the first parameter, and the remaining instance variables are initialized according to the last three parameters. Instance variables quantitiesInStock, price, and discount must be nonnegative. 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.
Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 2 steps

Blurred answer
Knowledge Booster
Reference Types in Function
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
EBK JAVA PROGRAMMING
EBK JAVA PROGRAMMING
Computer Science
ISBN:
9781337671385
Author:
FARRELL
Publisher:
CENGAGE LEARNING - CONSIGNMENT