Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //
- // main.cpp
- // UAP
- //
- // Created by Alexander Kevin on 6/8/14.
- // Copyright (c) 2014 Alexander Kevin. All rights reserved.
- //
- #include <iostream>
- #include <string>
- #define abc cin.sync();cin.clear();
- using namespace std;
- void menu(string,int);
- string regist();
- bool cekUser(string);
- class basic{
- protected:
- string type;
- string size;
- string flavor;
- int price;
- string code;
- public:
- basic(){
- type="";
- size="";
- flavor="";
- price=0;
- code="ORD-";
- }
- void setBasic(string a,string b,string c,string d){
- flavor=a;
- type=b;
- size=c;
- code=code+d.substr(0,3);
- code=code+'-';
- srand(time(NULL));
- char x;
- x=rand()%26+65;
- code=code+x;
- x=rand()%26+65;
- code=code+x;
- x=rand()%9+1+48;
- code=code+x;
- x=rand()%9+1+48;
- code=code+x;
- if(flavor=="Coffee")
- price+=15000;
- else if(flavor=="Green Tea")
- price+=16000;
- else
- price+=17000;
- if(flavor=="Balkan")
- price+=6000;
- else if(flavor=="Swiss")
- price+=7000;
- else
- price+=8000;
- if(flavor=="Small")
- price+=2000;
- else if(flavor=="Medium")
- price+=3000;
- else
- price+=4000;
- }
- string getType(){
- return type;
- }
- string getSize(){
- return size;
- }
- string getFlavor(){
- return flavor;
- }
- int getPrice(){
- return price;
- }
- string getCode(){
- return code;
- }
- };
- class detail:public basic{
- private:
- string topping;
- public:
- detail(){
- topping="No Topping";
- }
- void setTopping(string a){
- topping=a;
- if(topping=="Lychee")
- price+=4000;
- else if(topping=="Dark Chocolate")
- price+=5000;
- else
- price+=6000;
- }
- string getTopping(){
- return topping;
- }
- };
- void e(){
- int x=0;
- do{
- cout<<endl;
- x++;
- }while(x<27);
- }
- bool cekUser(string a){
- if(a.length()<5||a.length()>20)
- return false;
- else if(a.find(" ")<20)
- return false;
- int w=0,z=0,x=0;
- while(x<a.length()){
- if(isalpha(a[x]))
- w=1;
- if(isdigit(a[x]))
- z=1;
- x++;
- }
- if(w==1&&z==1)
- return true;
- else
- return false;
- }
- string regist(){
- e();
- string a;
- cout<<"Username Requirement :"<<endl<<"1) Combination of numbers and alphabets"<<endl<<"2) 5 - 20 characters"<<endl<<"3) One word only"<<endl;
- while(!cekUser(a)){
- cout<<"Masukan Username Anda :";
- getline(cin,a);abc;
- cekUser(a);
- }
- return a;
- }
- void menu(string id,int jumlah){
- system("cls");
- e();
- static detail ord[5];
- int count;
- count=jumlah;
- cout<<"MAIN MENU"<<endl
- <<"Welcome, "<<id<<endl
- <<"1. Make an Order"<<endl
- <<"2. View Your Order"<<endl
- <<"3. Delete Order"<<endl
- <<"4. Pay Order"<<endl;
- int answer;
- cout<<"Masukan Pilihan : ";
- cin>>answer;abc;
- switch(answer){
- case 1:
- {
- string a1,a2,a3,a4;
- system("cls");
- e();
- int flag=0;
- while(flag==0){
- cout<<"Input FLAVOUR (Coffee, Green Tea, Mocha) : ";
- getline(cin,a1);abc;
- if(a1=="Coffee"||a1=="Green Tea"||a1=="Mocha")
- flag=1;
- }
- flag=0;
- while(flag==0){
- cout<<"Input TYPE (Balkan, Swiss, Greek) : ";
- getline(cin,a2);abc;
- if(a2=="Balkan"||a2=="Swiss"||a2=="Greek")
- flag=1;
- }
- flag=0;
- while(flag==0){
- cout<<"Input SIZE (Small, Medium, Large) : ";
- getline(cin,a3);abc;
- if(a3=="Small"||a3=="Medium"||a3=="Large")
- flag=1;
- }
- cout<<"Add Topping[Y/N]?";
- getline(cin,a4);abc;
- if(a4=="Y"){
- flag=0;
- while(flag==0){
- cout<<"Input TOPPING (Lychee, Dark Chocolate, Marshmallow) : ";
- getline(cin,a4);abc;
- if(a4=="Lychee"||a4=="Dark Chocolate"||a4=="Marshmallow")
- flag=1;
- }
- ord[count].setTopping(a4);
- }
- ord[count].setBasic(a1,a2,a3,id);
- cout<<endl<<"Detail Order"<<endl<<"==========================="<<endl
- <<"Flavor : "<<ord[count].getFlavor()<<endl
- <<"Type : "<<ord[count].getType()<<endl
- <<"Size : "<<ord[count].getSize()<<endl
- <<"Topping : "<<ord[count].getTopping()<<endl
- <<"Price: "<<ord[count].getPrice()<<endl
- <<"Code : "<<ord[count].getCode()<<endl;
- cin.get();
- count++;
- menu(id,count);
- break;
- }
- case 2:
- system("cls");
- e();
- if(count>0){
- cout<<"Detail Order"<<endl<<"==========================="<<endl;
- for(int i=0;i<count;i++){
- cout
- <<"Flavor : "<<ord[i].getFlavor()<<endl
- <<"Type : "<<ord[i].getType()<<endl
- <<"Size : "<<ord[i].getSize()<<endl
- <<"Topping : "<<ord[i].getTopping()<<endl
- <<"Price : "<<ord[i].getPrice()<<endl
- <<"Code : "<<ord[i].getCode()<<endl<<endl;
- }
- }
- else{
- cout<<"Belum Melakukan Pemesanan Apapun, Kembali ke menu";
- }
- cin.get();
- cin.get();
- menu(id,count);
- break;
- case 3:
- {
- system("cls");
- e();
- string hapus;
- int flag=-1;
- if(count>0){
- cout<<"List Order"<<endl<<"==========================="<<endl;
- for(int i=0;i<count;i++){
- cout<<"Code : "<<ord[i].getCode()<<endl<<endl;
- }
- while(flag==-1){
- cout<<"Masukan Code yang ingin di delete : ";
- getline(cin,hapus);abc;
- for(int i=0;i<count;i++){
- if(ord[i].getCode()==hapus)
- flag=i;
- }
- if(flag==-1)
- cout<<"Code yang anda masukan salah"<<endl;
- }
- for(int i=flag;i<count-1;i++)
- ord[i]=ord[i+1];
- count--;
- cout<<"Sukses Mengahus Order"<<hapus;
- }
- else
- cout<<"Belum Melakukan Pemesanan Apapun, Kembali ke menu";
- cin.get();
- menu(id,count);
- break;
- }
- case 4:
- system("cls");
- e();
- if(count>0){
- int total=0,payment=0;
- for(int i=0;i<count;i++){
- total+=ord[i].getPrice();
- }
- cout<<"total payment of all orders : Rp. "<<total<<",00"<<endl;
- while(payment<total){
- cout<<"Masukan Input user payment (Minimum is the amount of payment) : ";
- cin>>payment;abc;
- }
- if(payment>total)
- cout<<"Your Change is Rp."<<(payment-total)<<",00"<<endl;
- cout<<"Thank You, See you next time!";
- }
- else{
- cout<<"Belum Melakukan Pemesanan Apapun, Kembali ke menu";
- cin.get();
- menu(id,count);
- break;
- }
- cin.get();
- cin.get();
- break;
- default:
- menu(id,count);
- break;
- }
- }
- int main(){
- int count=0;
- menu(regist(),count);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement