Make a using four class program. helpful program. Store information sale something return complete things information.
#include <iostream>
#include <string>
#include <vector>
using namespace std;
class Product{
private:
string name;
float price;
int quantity;
public:
Product(string name,float price,int quantity){
this->name=name;
this->price=price;
this->quantity=quantity;
}
void display(){
cout<<"Name: "<<this->name<<"\n";
cout<<"Price: "<<this->price<<"\n";
cout<<"Quantity: "<<this->quantity<<"\n\n";
}
string getName(){
return this->name;
}
float getPrice(){
return this->price;
}
int getQuantity(){
return this->quantity;
}
};
class Customer{
private:
string ID;
string name;
string telephoneNumber;
vector<Product> selectedProducts;
public:
Customer(){}
Customer(string ID,string name,string telephoneNumber){
this->ID=ID;
this->name=name;
this->telephoneNumber=telephoneNumber;
}
void display(){
cout<<"ID: "<<this->ID<<"\n";
cout<<"Name: "<<this->name<<"\n";
cout<<"Telephone number: "<<this->telephoneNumber<<"\n\n";
}
void addProduct(Product product){
this->selectedProducts.push_back(product);
}
string getID(){
return this->ID;
}
string getName(){
return this->name;
}
string getTelephoneNumber(){
return this->telephoneNumber;
}
};
class Sale{
private:
string date;
float amount;
int quantity;
Customer customer;
public:
Sale(string date,float amount,int quantity){
this->date=date;
this->amount=amount;
this->quantity=quantity;
}
void display(){
customer.display();
cout<<"Date: "<<this->date<<"\n";
cout<<"Amount: "<<this->amount<<"\n";
cout<<"Quantity: "<<this->quantity<<"\n\n";
}
string getDate(){
return this->date;
}
float getAmount(){
return this->amount;
}
int getQuantity(){
return this->quantity;
}
void addCustomer(Customer customer){
this->customer=customer;
}
};
class Store{
private:
string name;
vector<Product> allProducts;
vector<Sale> sales;
public:
Store(string name){
this->name=name;
}
void display(){
cout<<"Name: "<<this->name<<"\n";
cout<<"All products:\n";
for(int i=0;i<allProducts.size();i++){
allProducts[i].display();
}
cout<<"\nAll sales:\n";
for(int i=0;i<sales.size();i++){
sales[i].display();
}
}
void addProduct(Product product){
this->allProducts.push_back(product);
}
void addSale(Sale sale){
this->sales.push_back(sale);
}
};
int main()
{
Store store("My Store");
Product product1("Item 1",50.5,12);
Product product2("Item 2",14.5,25);
Product product3("Item 3",25.4,58);
Customer customer1("5454132654","Mary Clark","066589458");
Customer customer2("4546321456","Peter Smith","045545656");
Customer customer3("1354646413","Mike Johnson","078464465");
customer1.addProduct(product1);
customer1.addProduct(product2);
customer2.addProduct(product2);
customer2.addProduct(product3);
customer3.addProduct(product1);
customer3.addProduct(product3);
Sale sale1=Sale("29/05/2021",25,3);
sale1.addCustomer(customer1);
Sale sale2=Sale("28/04/2021",10,10);
sale2.addCustomer(customer2);
Sale sale3=Sale("15/03/2021",15,5);
sale3.addCustomer(customer3);
store.addProduct(product1);
store.addProduct(product2);
store.addProduct(product2);
store.addSale(sale1);
store.addSale(sale2);
store.addSale(sale3);
store.display();
system("pause");
return 0;
}
Comments
Leave a comment