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;
}