├── .gitattributes └── Dessert Shoppe system through Inheritance ├── Cookies.h ├── DessertItem.h ├── IceCream.h ├── Sundae.h └── main.cpp /.gitattributes: -------------------------------------------------------------------------------- 1 | # Auto detect text files and perform LF normalization 2 | * text=auto 3 | -------------------------------------------------------------------------------- /Dessert Shoppe system through Inheritance/Cookies.h: -------------------------------------------------------------------------------- 1 | #define Cookies_H 2 | #include 3 | #include"DessertItem.h" 4 | class Cookies:public DessertItem { 5 | private: 6 | int totalCookies; 7 | int pricePerDz; 8 | public: 9 | Cookies(){ 10 | totalCookies = 0; 11 | pricePerDz = 0; 12 | } 13 | Cookies(int totalCookies, int price, char*Name):DessertItem(Name) { 14 | this->totalCookies = totalCookies; 15 | this->pricePerDz = price; 16 | } 17 | int getcost() { 18 | int price = pricePerDz / 12;//price per cookies 19 | return (totalCookies*price); 20 | } 21 | int gettex() { 22 | int tex = getcost() * 2; 23 | return (tex / 100); 24 | } 25 | ~Cookies() { 26 | } 27 | }; -------------------------------------------------------------------------------- /Dessert Shoppe system through Inheritance/DessertItem.h: -------------------------------------------------------------------------------- 1 | #ifndef DessertItem_H 2 | #define DessertItem_H 3 | #include 4 | using namespace std; 5 | class DessertItem { 6 | private: 7 | char* name; 8 | public: 9 | DessertItem() { 10 | name = NULL; 11 | } 12 | DessertItem(char *Name) { 13 | name = Name; 14 | } 15 | void printName() { 16 | if (name != NULL) { 17 | cout << "\nName : " << name; 18 | } 19 | else { 20 | cout << "name not set"; 21 | } 22 | } 23 | virtual int getcost() = 0; 24 | virtual int gettex() = 0; 25 | ~DessertItem() { 26 | 27 | } 28 | }; 29 | #endif // !DessertItem_H 30 | -------------------------------------------------------------------------------- /Dessert Shoppe system through Inheritance/IceCream.h: -------------------------------------------------------------------------------- 1 | #ifndef IceCreame_H 2 | #define IceCreame_H 3 | 4 | #include"DessertItem.h" 5 | class IceCream:public DessertItem { 6 | private: 7 | int Icecost; 8 | public: 9 | 10 | IceCream():DessertItem() { 11 | Icecost = 0; 12 | } 13 | IceCream(int cost, char *name) :DessertItem(name) { 14 | this->Icecost = cost; 15 | } 16 | virtual int getcost() { 17 | return Icecost; 18 | } 19 | virtual int gettex() { 20 | int tex = getcost() * 2; 21 | return (tex / 100); 22 | } 23 | ~IceCream() { 24 | 25 | } 26 | }; 27 | 28 | #endif // !IceCreame_H 29 | -------------------------------------------------------------------------------- /Dessert Shoppe system through Inheritance/Sundae.h: -------------------------------------------------------------------------------- 1 | #ifndef Sundae_H 2 | #define Sundae_H 3 | #include"IceCream.h" 4 | 5 | class Sundae:public IceCream{ 6 | private: 7 | int SundaeCost; 8 | public: 9 | Sundae() :IceCream() { 10 | SundaeCost = 0; 11 | } 12 | Sundae(int sCost, int ICost, char* name) :IceCream(ICost,name) { 13 | this->SundaeCost = sCost; 14 | } 15 | int getcost() { 16 | return (SundaeCost + IceCream::getcost()); 17 | } 18 | int gettex() { 19 | int tex = getcost() * 2; 20 | return (tex / 100); 21 | } 22 | ~Sundae() { 23 | 24 | } 25 | }; 26 | #endif -------------------------------------------------------------------------------- /Dessert Shoppe system through Inheritance/main.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include"DessertItem.h" 3 | #include"Cookies.h" 4 | #include"IceCream.h" 5 | #include"Sundae.h" 6 | using namespace std; 7 | int main() { 8 | int itemCount = 0; 9 | const int purchaseOrder = 20; // total item that user can buy 10 | DessertItem* itemList[purchaseOrder]; //20 pointers of base class type, at most 20 objects 11 | //can be added 12 | char addMore = 'y'; 13 | int userChoice; 14 | 15 | cout << "\n\n............................................."; 16 | cout << "\n\nWant to add more items press y : "; 17 | cin >> addMore; //enter y for yes 18 | 19 | while (addMore == 'y'|| addMore == 'Y' && itemCount< purchaseOrder) { 20 | system("CLS"); 21 | cout << "\n\t\tChoose Item you want to add"; 22 | cout << "\n1 : for enter cookies"; 23 | cout << "\n2 : for enter iceCream"; 24 | cout << "\n3 : for enter Sundae\n----->>"; 25 | cin >> userChoice; 26 | if (userChoice == 1) { 27 | int totalCookies = -1; 28 | int pricePerDz = -1; 29 | while (totalCookies <= 0) { 30 | cout << "\nNumber of cookies : "; 31 | cin >> totalCookies; 32 | } 33 | while (pricePerDz <= 0) { 34 | cout << "\nEnter price per Dz : "; 35 | cin >> pricePerDz; 36 | } 37 | char name[36]; 38 | cout << "Enter name withOut space: "; 39 | cin >> name; 40 | itemList[itemCount++] = new Cookies(totalCookies, pricePerDz,name); //making base class pointer 41 | //point cookie object 42 | } 43 | else if (userChoice == 2) { 44 | int cost = -1; 45 | while (cost <= 0) { 46 | cout << "\nEnter Icecream cost :"; 47 | cin >> cost; 48 | } 49 | char name[36]; 50 | cout << "Enter name without space : "; 51 | cin >> name; 52 | itemList[itemCount++] = new IceCream(cost, name);//making base class pointer 53 | //point IceCream object 54 | } 55 | else if (userChoice == 3) { 56 | int Icecost = -1; 57 | while (Icecost <= 0) { 58 | cout << "\nEnter Icecream cost :"; 59 | cin >> Icecost; 60 | } 61 | int toppingCost = -1; 62 | while (toppingCost <= 0) { 63 | cout << "\nEnter topping cost : "; 64 | cin >> toppingCost; 65 | } 66 | char name[36]; 67 | cout << "Enter name without space : "; 68 | cin >> name; 69 | itemList[itemCount++] = new Sundae(toppingCost,Icecost,name);//making base class pointer 70 | //point Sundae object 71 | } 72 | 73 | cout << "\n\n............................................."; 74 | cout << "\n\nWant to add more items press y : "; 75 | cin >> addMore; //enter y for yes 76 | } 77 | int TotalCost = 0; // total cost withOut tex 78 | for (int i = 0; i < itemCount; i++) { 79 | TotalCost += itemList[i]->getcost(); 80 | } 81 | cout << "\nTotal cost : "<gettex(); 86 | } 87 | cout << "\nTotal Tex : " << TotalTax; 88 | 89 | } --------------------------------------------------------------------------------