Advertisement
akevintg

(REVIEW MATERIAL)UAP 1[XCode]

Jun 8th, 2014
281
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 8.13 KB | None | 0 0
  1. //
  2. //  main.cpp
  3. //  UAP
  4. //
  5. //  Created by Alexander Kevin on 6/8/14.
  6. //  Copyright (c) 2014 Alexander Kevin. All rights reserved.
  7. //
  8.  
  9. #include <iostream>
  10. #include <string>
  11. #define abc cin.sync();cin.clear();
  12.  
  13. using namespace std;
  14.  
  15. void menu(string,int);
  16. string regist();
  17. bool cekUser(string);
  18.  
  19. class basic{
  20. protected:
  21.     string type;
  22.     string size;
  23.     string flavor;
  24.     int price;
  25.     string code;
  26. public:
  27.     basic(){
  28.         type="";
  29.         size="";
  30.         flavor="";
  31.         price=0;
  32.         code="ORD-";
  33.     }
  34.     void setBasic(string a,string b,string c,string d){
  35.         flavor=a;
  36.         type=b;
  37.         size=c;
  38.         code=code+d.substr(0,3);
  39.         code=code+'-';
  40.         srand(time(NULL));
  41.         char x;
  42.         x=rand()%26+65;
  43.         code=code+x;
  44.         x=rand()%26+65;
  45.         code=code+x;
  46.         x=rand()%9+1+48;
  47.         code=code+x;
  48.         x=rand()%9+1+48;
  49.         code=code+x;
  50.         if(flavor=="Coffee")
  51.             price+=15000;
  52.         else if(flavor=="Green Tea")
  53.             price+=16000;
  54.         else
  55.             price+=17000;
  56.         if(flavor=="Balkan")
  57.             price+=6000;
  58.         else if(flavor=="Swiss")
  59.             price+=7000;
  60.         else
  61.             price+=8000;
  62.         if(flavor=="Small")
  63.             price+=2000;
  64.         else if(flavor=="Medium")
  65.             price+=3000;
  66.         else
  67.             price+=4000;
  68.     }
  69.     string getType(){
  70.         return type;
  71.     }
  72.     string getSize(){
  73.         return size;
  74.     }
  75.     string getFlavor(){
  76.         return flavor;
  77.     }
  78.     int getPrice(){
  79.         return price;
  80.     }
  81.     string getCode(){
  82.         return code;
  83.     }
  84. };
  85.  
  86. class detail:public basic{
  87. private:
  88.     string topping;
  89. public:
  90.     detail(){
  91.         topping="No Topping";
  92.     }
  93.     void setTopping(string a){
  94.         topping=a;
  95.         if(topping=="Lychee")
  96.             price+=4000;
  97.         else if(topping=="Dark Chocolate")
  98.             price+=5000;
  99.         else
  100.             price+=6000;
  101.     }
  102.     string getTopping(){
  103.         return topping;
  104.     }
  105. };
  106.  
  107. void e(){
  108.     int x=0;
  109.     do{
  110.         cout<<endl;
  111.         x++;
  112.     }while(x<27);
  113. }
  114.  
  115. bool cekUser(string a){
  116.     if(a.length()<5||a.length()>20)
  117.         return false;
  118.     else if(a.find(" ")<20)
  119.         return false;
  120.     int w=0,z=0,x=0;
  121.     while(x<a.length()){
  122.         if(isalpha(a[x]))
  123.             w=1;
  124.         if(isdigit(a[x]))
  125.             z=1;
  126.         x++;
  127.     }
  128.     if(w==1&&z==1)
  129.         return true;
  130.     else
  131.         return false;
  132. }
  133.  
  134. string regist(){
  135.     e();
  136.     string a;
  137.     cout<<"Username Requirement :"<<endl<<"1) Combination of numbers and alphabets"<<endl<<"2) 5 - 20 characters"<<endl<<"3) One word only"<<endl;
  138.     while(!cekUser(a)){
  139.         cout<<"Masukan Username Anda :";
  140.         getline(cin,a);abc;
  141.         cekUser(a);
  142.     }
  143.     return a;
  144. }
  145.  
  146. void menu(string id,int jumlah){
  147.     system("cls");
  148.     e();
  149.     static detail ord[5];
  150.     int count;
  151.     count=jumlah;
  152.     cout<<"MAIN MENU"<<endl
  153.     <<"Welcome, "<<id<<endl
  154.     <<"1. Make an Order"<<endl
  155.     <<"2. View Your Order"<<endl
  156.     <<"3. Delete Order"<<endl
  157.     <<"4. Pay Order"<<endl;
  158.     int answer;
  159.     cout<<"Masukan Pilihan : ";
  160.     cin>>answer;abc;
  161.     switch(answer){
  162.         case 1:
  163.         {  
  164.             string a1,a2,a3,a4;
  165.             system("cls");
  166.             e();
  167.             int flag=0;
  168.             while(flag==0){
  169.                 cout<<"Input FLAVOUR (Coffee, Green Tea, Mocha) : ";
  170.                 getline(cin,a1);abc;
  171.                 if(a1=="Coffee"||a1=="Green Tea"||a1=="Mocha")
  172.                     flag=1;
  173.             }
  174.             flag=0;
  175.             while(flag==0){
  176.                 cout<<"Input TYPE (Balkan, Swiss, Greek) : ";
  177.                 getline(cin,a2);abc;
  178.                 if(a2=="Balkan"||a2=="Swiss"||a2=="Greek")
  179.                     flag=1;
  180.             }
  181.             flag=0;
  182.             while(flag==0){
  183.                 cout<<"Input SIZE (Small, Medium, Large) : ";
  184.                 getline(cin,a3);abc;
  185.                 if(a3=="Small"||a3=="Medium"||a3=="Large")
  186.                     flag=1;
  187.             }
  188.             cout<<"Add Topping[Y/N]?";
  189.             getline(cin,a4);abc;
  190.             if(a4=="Y"){
  191.                 flag=0;
  192.                 while(flag==0){
  193.                     cout<<"Input TOPPING (Lychee, Dark Chocolate, Marshmallow) : ";
  194.                     getline(cin,a4);abc;
  195.                     if(a4=="Lychee"||a4=="Dark Chocolate"||a4=="Marshmallow")
  196.                         flag=1;
  197.                 }
  198.                 ord[count].setTopping(a4);
  199.             }
  200.             ord[count].setBasic(a1,a2,a3,id);
  201.             cout<<endl<<"Detail Order"<<endl<<"==========================="<<endl
  202.             <<"Flavor : "<<ord[count].getFlavor()<<endl
  203.             <<"Type : "<<ord[count].getType()<<endl
  204.             <<"Size : "<<ord[count].getSize()<<endl
  205.             <<"Topping : "<<ord[count].getTopping()<<endl
  206.             <<"Price: "<<ord[count].getPrice()<<endl
  207.             <<"Code : "<<ord[count].getCode()<<endl;
  208.             cin.get();
  209.             count++;
  210.             menu(id,count);
  211.             break;
  212.         }
  213.         case 2:
  214.             system("cls");
  215.             e();
  216.             if(count>0){
  217.             cout<<"Detail Order"<<endl<<"==========================="<<endl;
  218.                 for(int i=0;i<count;i++){
  219.                     cout
  220.                     <<"Flavor : "<<ord[i].getFlavor()<<endl
  221.                     <<"Type : "<<ord[i].getType()<<endl
  222.                     <<"Size : "<<ord[i].getSize()<<endl
  223.                     <<"Topping : "<<ord[i].getTopping()<<endl
  224.                     <<"Price : "<<ord[i].getPrice()<<endl
  225.                     <<"Code : "<<ord[i].getCode()<<endl<<endl;
  226.                 }
  227.             }
  228.             else{
  229.                 cout<<"Belum Melakukan Pemesanan Apapun, Kembali ke menu";
  230.             }
  231.             cin.get();
  232.             cin.get();
  233.             menu(id,count);
  234.             break;
  235.         case 3:
  236.         {
  237.             system("cls");
  238.             e();
  239.             string hapus;
  240.             int flag=-1;
  241.             if(count>0){
  242.                 cout<<"List Order"<<endl<<"==========================="<<endl;
  243.                 for(int i=0;i<count;i++){
  244.                     cout<<"Code : "<<ord[i].getCode()<<endl<<endl;
  245.                 }
  246.                 while(flag==-1){
  247.                     cout<<"Masukan Code yang ingin di delete : ";
  248.                     getline(cin,hapus);abc;
  249.                     for(int i=0;i<count;i++){
  250.                         if(ord[i].getCode()==hapus)
  251.                             flag=i;
  252.                     }
  253.                     if(flag==-1)
  254.                         cout<<"Code yang anda masukan salah"<<endl;
  255.                 }
  256.                 for(int i=flag;i<count-1;i++)
  257.                     ord[i]=ord[i+1];
  258.                 count--;
  259.                 cout<<"Sukses Mengahus Order"<<hapus;
  260.             }
  261.             else
  262.                 cout<<"Belum Melakukan Pemesanan Apapun, Kembali ke menu";
  263.             cin.get();
  264.             menu(id,count);
  265.             break;
  266.         }
  267.         case 4:
  268.             system("cls");
  269.             e();
  270.             if(count>0){
  271.                 int total=0,payment=0;
  272.                 for(int i=0;i<count;i++){
  273.                     total+=ord[i].getPrice();
  274.                 }
  275.                 cout<<"total payment of all orders : Rp. "<<total<<",00"<<endl;
  276.                 while(payment<total){
  277.                     cout<<"Masukan Input user payment (Minimum is the amount of payment) : ";
  278.                     cin>>payment;abc;
  279.                 }
  280.                 if(payment>total)
  281.                     cout<<"Your Change is Rp."<<(payment-total)<<",00"<<endl;
  282.                 cout<<"Thank You, See you next time!";
  283.             }
  284.             else{
  285.                 cout<<"Belum Melakukan Pemesanan Apapun, Kembali ke menu";
  286.                 cin.get();
  287.                 menu(id,count);
  288.                 break;
  289.             }
  290.             cin.get();
  291.             cin.get();
  292.             break;
  293.         default:
  294.             menu(id,count);
  295.             break;
  296.     }
  297. }
  298.  
  299. int main(){
  300.     int count=0;
  301.     menu(regist(),count);
  302. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement