test
This commit is contained in:
parent
37776af5db
commit
ab03d5f10c
4045 changed files with 286212 additions and 3 deletions
86
.config/Code/User/History/65ec6aae/5QV7.cpp
Normal file
86
.config/Code/User/History/65ec6aae/5QV7.cpp
Normal file
|
@ -0,0 +1,86 @@
|
|||
/*
|
||||
Rafay Ahmad
|
||||
23I-2526
|
||||
*/
|
||||
#include <iostream>
|
||||
using namespace std;
|
||||
|
||||
class Customer{
|
||||
string name;
|
||||
string address;
|
||||
|
||||
public:
|
||||
|
||||
Customer(string name, string address) : name(name), address(address){}
|
||||
|
||||
string getName(){
|
||||
return name;
|
||||
}
|
||||
string getAddress(){
|
||||
return address;
|
||||
}
|
||||
};
|
||||
|
||||
class Product{
|
||||
string name;
|
||||
double price;
|
||||
|
||||
public:
|
||||
|
||||
Product(string name, double price) : name(name), price(price){}
|
||||
|
||||
string getName(){
|
||||
return name;
|
||||
}
|
||||
double getPrice(){
|
||||
return price;
|
||||
}
|
||||
};
|
||||
|
||||
class Order{
|
||||
Customer customer;
|
||||
struct OrderItem{
|
||||
Product product;
|
||||
int qty;
|
||||
};
|
||||
OrderItem *items;
|
||||
int noOfProducts;
|
||||
public:
|
||||
|
||||
Order(Customer customer) : customer(customer), noOfProducts(0){
|
||||
items = new OrderItem[1];
|
||||
}
|
||||
~Order(){
|
||||
delete[] items;
|
||||
}
|
||||
|
||||
void addItem(Product product, int qty){
|
||||
|
||||
OrderItem *tmp = new OrderItem[noOfProducts+1];
|
||||
for(int i=0;i<noOfProducts;i++) tmp[i] = items[i];
|
||||
tmp[noOfProducts] = {product, qty};
|
||||
|
||||
delete[] items;
|
||||
items = tmp;
|
||||
|
||||
noOfProducts++;
|
||||
}
|
||||
|
||||
void displayOrder(){
|
||||
cout<<"Name: "<<customer.getName()<<endl;
|
||||
cout<<"Address: "<<customer.getAddress()<<endl;
|
||||
for(int i=0;i<noOfProducts;i++){
|
||||
cout<<"product name: "<<items[i].product.getName()<<"\t";
|
||||
cout<<"product price: "<<items[i].product.getPrice()<<endl;
|
||||
}
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
|
||||
int main(){
|
||||
|
||||
|
||||
|
||||
return 0;
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue