Consider the definition of the following class: (1, 2, 3, 5, 7) class productType //Line 1 { //Line 2 public: //Line 3 productType(); //Line 4 productType(int, double, double); //Line 5 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 void print() const; //Line 9 void setQuantitiesInStock(int x); //Line 10 void updateQuantitiesInStock(int x); //Line 11 int getQuantitiesInStock() const; //Line 12 void setPrice(double x); //Line 13 double getPrice() const; //Line 14 void setDiscount(double d); //Line 15 double getDiscount() const; //Line 16 private: //Line 17 string productName; //Line 18 string id; //Line 19 string manufacturer; //Line 20 int quantitiesInStock; //Line 21 double price; //Line 22 double discount; //Line 23 }; //Line 24 a. Give the line number containing the constructor that is executed in each of the following declarations. i. productType product1; ii. productType product2("Microwave", "M3562", "GeneralPool", 35, 175.00, 0.1); iii. productType product3("D1290", 25, 375.00, 0.05); iv. productType product4(10, 8.50, 0.2);

Respuesta :

Answer:

The C++ codes are given below with appropriate comments

Explanation:

// productType.h

#ifndef PRODUCTTYPE_H

#define PRODUCTTYPE_H

class productType

{

public:

productType();

productType(int , double ,double);

productType(string,int , double ,double);

productType(string,string,string,int , double ,double);

void set(string,string,string,int , double ,double);

void print() const;

void setQuantitiesInStock(int x);

int getQuantitiesInStock() const;

void updateQuantitiesInStock(int x);

 

void setPrice(double x);

double getPrice() const;

void setDiscount(double d);

double getDiscount() const;

 

 

 

private:

// Declaring variables

string productName;

string id;

string manufacturer;

int quantitiesInStock;

double price;

double discount;

};

#endif

=============================

// productType.cpp

#include <iostream>

using namespace std;

#include "productType.h"

productType::productType()

{

this->productName="";

this->id="";

this->manufacturer="";

this->quantitiesInStock=0;

this->price=0.0;

this->discount=0.0;

}

productType::productType(int quantitiesInStock, double price,double discount)

{

this->productName="";

this->id="";

this->manufacturer="";

this->quantitiesInStock=quantitiesInStock;

this->price=price;

this->discount=discount;

}

productType::productType(string productName,int quantitiesInStock, double price,double discount)

{

this->productName=productName;

this->id="";

this->manufacturer="";

this->quantitiesInStock=quantitiesInStock;

this->price=price;

this->discount=discount;

}

productType::productType(string productName,string id,string manufacturer,int quantitiesInStock, double price,double discount)

{

this->productName=productName;

this->id=id;

this->manufacturer=manufacturer;

this->quantitiesInStock=quantitiesInStock;

this->price=price;

this->discount=discount;

}

void productType::set(string productName,string id,string manufacturer,int quantitiesInStock, double price,double discount)

{

this->productName=productName;

this->id=id;

this->manufacturer=manufacturer;

this->quantitiesInStock=quantitiesInStock;

this->price=price;

this->discount=discount;

}

void productType::print() const

{

cout<<"Product Name :"<<productName<<endl;

cout<<"Id :"<<id<<endl;

cout<<"Manufacturer :"<<manufacturer<<endl;

cout<<"Quantities In Stock :"<<quantitiesInStock<<endl;

cout<<"Price :$"<<price<<endl;

cout<<"Discount :%"<<discount<<endl;

}

void productType::setQuantitiesInStock(int x)

{

this->quantitiesInStock=x;

}

int productType::getQuantitiesInStock() const

{

return quantitiesInStock;

}

 

void productType::setPrice(double x)

{

this->price=x;

}

double productType::getPrice() const

{

return price;

}

void productType::setDiscount(double d)

{

this->discount=d;

}

double productType::getDiscount() const

{

return discount;

}

void productType::updateQuantitiesInStock(int x)

{

this->quantitiesInStock=x;

}

=============================

// main.cpp

#include <iostream>

using namespace std;

#include "productType.h"

int main()

{

productType pt("Mobile","1234","Lenovo",34,1500,10);

pt.print();

 

pt.updateQuantitiesInStock(50);

cout<<"\nAfter Modifying the quantity ::"<<endl;

pt.print();

 

return 0;

}