1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103
|
#include "stdafx.h"
#include <string>
#include <iostream>
using namespace std;
class Product {
public:
Product(string, double, double);
string get_name() const {
return name;
}
double get_price() const {
return price;
}
double get_weight() const {
return weight;
}
void write() const {
cout << "Product name: " << name << " " << "Price: " << price << " Weight: " << weight << endl;
}
private:
string name;
double price;
double weight;
};
class Purchase : public Product {
public:
Purchase(string, double, double, int, int);
string get_name() const {
return Product::get_name();
}
double get_price() const {
return Product::get_price();
}
double get_weight() const {
return Product::get_weight();
}
int get_quantity() const {
return quantity;
}
int get_weightbought() const {
return weightbought;
}
void write() const {
cout << "Product name: " << get_name() << " Price: " << get_price() << " Weight: " << get_weight() << quantity << endl;
}
void buy() {
quantity += 1;
weightbought += get_weight();
}
private:
int quantity;
int weightbought;
};
class Verification : public Purchase {
};
int main()
{
Product A("pizza", 2.35, 0.350);
Product B("olive oil", 1.15, 0.800);
Product C("apple", 0.50, 0.25);
A.write();
B.write();
C.write();
cout << "Which product would you like to buy ?" << endl;
cout << "######################################" << endl;
string choice;
if (choice == "pizza") {
Purchase A1(A.get_name(), A.get_price(), A.get_weight(), 1, 0);
}
system("Pause");
return 0;
}
Product::Product(string n, double p, double w) {
name = n;
price = p;
weight = w;
}
Purchase::Purchase(string n, double p, double w, int q, int wb)
: Product(n, p, w) {
quantity = q;
weightbought = wb;
}
|