Question
C++
Consider the definition of the following class: (1,2,3, 5,7 clasa productTyp publie productType O productType(int. double, double) productType (atring, int, double, double)s //tine6 productType (atring. atring.atring //Line1 /Line 2 /Line 3 //Line /Line s int, double, double) //Line 7 void set (atring, atring, string. int void print) const double, double) i //Line //tine 9 void setQuantitiesInstock (int x) void updateQuantitiesinstock (int x) int getQuantitiesInstock) const //Line 10 //Line 11 //Line 12 void #etPrice (double x); double getPrice) consti //Line 13 //Line 14 void setDiscount (double d) i double getDiscount) consti //Line 15 //Line 16 private: //Line 17 string productName string id string manufacturer: int quantitiesInstock: double price double discount //Line 18 //Line 19 //Line 20 //Line 21 //Line 22 //Line 23 //Line 24 a. Give the line number containing the constructor that is executed in each of the following declarations. i. productType producti; li productType product2 (Microwave, M3562, GeneralPool, 35, 175.00, 0.1) ili. productType product3 (D1290, 25, 375.00, 0.05) iv. productType product4 (10, 8.50, 0.2) Write the definition of the constructor in Line 4 so that the instance variables are initialized to0, o.o, and o.o, respectively b. c Write the definition of the constructor in Line 5 so that the string instance variables are initialized to , and the other instance variables
0 0
Add a comment Improve this question Transcribed image text
Answer #1
a)
   i)
      Line 4
      Default Contsructor

      Explanation:   There is no argument passed hence, the default constructor is called.

   ii)    
      Line 7
      Paramaterized Constructor

      Explanation:   Passed arguments are STRING, STRING, STRING, INT, DOUBLE, DOUBLE matches with this constructor prototype at line 7.

   iii)
      Line 6
      Paramaterized Constructor

      Explanation:   Passed arguments are STRING, INT, DOUBLE, DOUBLE matches with this constructor prototype at line 6.

   iv)
      Line 5
      Parematerized Constructor

      Explanation:   Passed arguments are INT, DOUBLE, DOUBLE matches with this constructor prototype at line 5.

b)
   //default constructor definition
   productType::productType() : productName(" "), id(" "), manufacturer(" "), quantitiesInStock(0), price(0.0), discount(0.0) {}


c)
   //parametrized constructor definition with given prototype
   productType::productType(int q, double p, double d) : productName(" "), id(" "), manufacturer(" "), quantitiesInStock(q), price(p), discount(d) {}

a) i) Line 4 Defoult Contsructor Explanation: There is no argument passed hence, the default constructor is called Line 7 Parematerized Constructor Explanation: Passed orguments are STRING, STRING, STRING, INT, DOUBLE, DCUBLE motches with this constructor prototype at line 7. Line 6 Parematerized Constructor Explanation: Passed arguments are STRING, INT, DOUBLE, DOUBLE natches with this constructor prototype at line 6 iv) Line 5 Parematerized Constructor Explanation: Passed arguments are INT, DOUBLE, DOUBLE matches with this constructor prototype at line 5 b) default constructor definition productType: :productType() productNane( ), id ), manufacturerquantitiesInStock(e), price(8.8), discount (.0) c) /paranetrized constructor definition with given prototype productType: :productType(int q, double p, double d): productName(, id ), manufacturer ),quantitiesinStock (q), price(p), discount (d) t Eait Pad 201 Download & Save | more

Note: Screenshot is attached for proper indentation and better understanding
Add a comment
Know the answer?
Add Answer to:
C++ Consider the definition of the following class: (1,2,3, 5,7 clasa productTyp publie productType O productType(int....
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Write a program that uses the class productType Please specify what goes in main.cpp, productType.h and...

    Write a program that uses the class productType Please specify what goes in main.cpp, productType.h and productType.cpp Please do not leave anything out, thank you! Consider the definition of the following class: (1, 2,3, 5,7) class productType 8. //Line 1 //Line 2 //Line //Line 4 //Line5 public: productType () productType (int, double, double) productType (string, int, double, double) /Line 6 productType (string, string, string, int, double, double) //Line'7 void set (string, string, string, int, double, double) //Line 8 //Line s...

  • There are four syntax errors/incorrect statements in the following class definition. List the line numbers of...

    There are four syntax errors/incorrect statements in the following class definition. List the line numbers of the lines that contain errors, and then write the corrected line(s). (4 points) class jetType //Line 1 { //Line 2 public: //Line 3 void setValues(string, int, double); //Line 4 print() const; //Line 5 string getManufacturer() const; //Line 6 double getPrice() const; //Line 7 bool compareSeating(const jetType&); //Line 8 int jetType(); //Line 9 jetType(string); //Line 10 jetType(string, int, double); //Line 11 private; //Line 12 string...

  • USE C++. Just want to confirm is this right~? Write a class named RetailItem that holds...

    USE C++. Just want to confirm is this right~? Write a class named RetailItem that holds data about an item in a retail store. The class should have the following member variables: description: A string that holds a brief description of the item. unitsOnHand: An int that holds thw number of units currently in inventory. price: A double that holds that item's retail price. Write the following functions: -appropriate mutator functions -appropriate accessor functions - a default constructor that sets:...

  • c. [3 marks] Given the following definition of the class MyClass, class MyClass { String s...

    c. [3 marks] Given the following definition of the class MyClass, class MyClass { String s int z Myclass(int y) { z = y } } fill in the blanks (labelled i., ii. and iii.) in the definition of the method main, of the class StringProcessing, with i. a declaration of a variable named obj of type MyClass, initialised with a MyClass object so that its instance variable z has a value of 20, ii. an assignment of the instance...

  • C++ Please create the class named BankAccount with the following properties below: // The BankAccount class...

    C++ Please create the class named BankAccount with the following properties below: // The BankAccount class sets up a clients account (name & ID), keeps track of a user's available balance. // It also keeps track of how many transactions (deposits and/or withdrawals) are made. public class BankAccount { Private String name private String id; private double balance; private int numTransactions; // Please define method definitions for Accessors and Mutator functions below Private member variables string getName(); // No set...

  • In JAVA Algorithm Workbench 1. Write the first line of the definition for a Poodle class....

    In JAVA Algorithm Workbench 1. Write the first line of the definition for a Poodle class. The class should extend the Dog class. 2. Look at the following code, which is the first line of a class definition: public class Tiger extends Felis In what order will the class constructors execute? 3. Write the statement that calls a superclass constructor and passes the arguments x, y, and z. 4. A superclass has the following method: public void setValue(int v) value...

  • Instructions: Consider the following C++ program. At the top you can see the interface for the...

    Instructions: Consider the following C++ program. At the top you can see the interface for the Student class. Below this is the implementation of the Student class methods. Finally, we have a very small main program. #include <string> #include <fstream> #include <iostream> using namespace std; class Student { public: Student(); Student(const Student & student); ~Student(); void Set(const int uaid, const string name, const float gpa); void Get(int & uaid, string & name, float & gpa) const; void Print() const; void...

  • Write a complete C++ program that defines the following class: Class Salesperson { public: Salesperson( );...

    Write a complete C++ program that defines the following class: Class Salesperson { public: Salesperson( ); // constructor ~Salesperson( ); // destructor Salesperson(double q1, double q2, double q3, double q4); // constructor void getsales( ); // Function to get 4 sales figures from user void setsales( int quarter, double sales); // Function to set 1 of 4 quarterly sales // figure. This function will be called // from function getsales ( ) every time a // user enters a sales...

  • Q1. Write a recursive function in C++ void printNumberedChars(string str, int i=0) { ... } which...

    Q1. Write a recursive function in C++ void printNumberedChars(string str, int i=0) { ... } which prints each character of the given string str on a new line, with each line numbered 1, 2, 3, …. For example calling the function with printNumberedChars("hello"); should output the following: 1. h 2. e 3. l 4. l 5. o Q2. Write a recursive function in C++ int sumArray(const int* arr, unsigned int size) { ... } which takes an array of integers,...

  • 1) Consider the following Java program: 1 public class HelloWorld { 2     // My first program!...

    1) Consider the following Java program: 1 public class HelloWorld { 2     // My first program! 3     public static void main(String[] args) { 4         System.out.println("Hello, World!"); 5     } 6 } What is on line 1? a. a variable declaration b. a statement c. a method (subroutine) definition d. a comment e. a class definition 2) Which one of the following does NOT describe an array? a. It can be used in a for-each loop. b. It has a numbered sequence...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT