Write a program that uses the class productType defined in Exercises 8 and 10 of this chapter.
♥ 0 |
Write a program that uses the class productType defined in Exercises 8 and 10 of this chapter. |
Explanation
#######################################
main.cpp
#######################################
#include "productType.h"
int main() {
productType p("Cerelac", "XYYY-2333", "Nestle", 1002, 23.2, 1.4);
p.print();
p.setQuantitiesInStock(10);
p.print();
p.setDiscount(12);
p.print();
}
#######################################
productType.h
#######################################
#include
#include
using namespace std;
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);
void updateQuantitiesInStock(int x);
int getQuantitiesInStock() const;
void setPrice(double x);
double getPrice() const;
void setDiscount(double d);
double getDiscount() const;
private:
string productName;
string id;
string manufacturer;
int quantitiesInStock;
double price;
double discount;
};
#######################################
productTypeImp.cpp
#######################################
#include "productType.h"
productType::productType() {
productName = "";
id = "";
manufacturer = "";
quantitiesInStock= 0;
price = 0;
discount = 0;
}
productType::productType(int q, double p, double d) {
productName = "";
id = "";
manufacturer = "";
quantitiesInStock= q;
price = p;
discount = d;
}
productType::productType(string m, int q, double p, double d) {
productName = "";
id = "";
manufacturer = m;
quantitiesInStock= q;
price = p;
discount = d;
}
productType::productType(string pn, string i, string m, int q, double p, double d) {
productName = pn;
id = i;
manufacturer = m;
quantitiesInStock= q;
price = p;
discount = d;
}
void productType::set(string pn, string i, string m, int q, double p, double d) {
productName = pn;
id = i;
manufacturer = m;
quantitiesInStock= q;
price = p;
discount = d;
}
void productType::print() const {
cout << "Produce Name: " << productName << endl;
cout << "Produce Id: " << id << endl;
cout << "Produce Manufacturer: " << manufacturer << endl;
cout << "Quantity in stock: " << quantitiesInStock << endl;
cout << "Price: " << price << endl;
cout << "Discount: " << discount << endl << endl;
}
void productType::setQuantitiesInStock(int x) {
quantitiesInStock = x;
}
void productType::updateQuantitiesInStock(int x) {
quantitiesInStock += x;
}
int productType::getQuantitiesInStock() const {
return quantitiesInStock;
}
void productType::setPrice(double x) {
price = x;
}
double productType::getPrice() const {
return price;
}
void productType::setDiscount(double d) {
discount = d;
}
double productType::getDiscount() const {
return discount;
}
The Best Research Paper Writing Service
Would you want to pay someone to write your paper professionally from scratch? 100% Original and 0% AI Content!.