Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <iomanip>
- #include <cmath>
- #include <conio.h> //for loading screen
- #include <dos.h> //for loading screen
- #include <windows.h> //for loading screen (sleep)
- using namespace std;
- struct customer // struct for customer details
- {
- string name;
- string email;
- int number;
- };
- //function prototype
- void welcomeScreen(); //display welcome screen and customer information
- void getInfo(struct customer &cust); //get information from customer
- void listHardware(); //list of names of hardwares for the type that has been chosen by the customer
- double calcFunc(int,int,int,int,int,int,double,char); //to calculate price
- void search_hardware(); //to search any hardwares available
- void exit_system(); //to exit program
- int admin_login(); //function accessible for admin/shopkeeper only
- void welcomeScreen()
- {
- struct customer cust; // struct declaration
- char ordermore = 'y';
- const int SIZE=5;
- system("cls");
- getInfo(cust); //function call to get info from customer
- while (ordermore == 'y' || ordermore == 'Y')
- {
- system("cls");
- cout << endl << "Type of hardwares that we sell:" << endl; //list of hardwares (1d Array)
- string item[SIZE]={"Monitor","CPU","RAM","Solid-State Drive","Graphic Card"};
- for(int i=0;i<SIZE;i++)
- cout << "\t" << i+1 << ". " << item[i] << endl;
- listHardware(); //function call list of names of hardwares
- cout << endl;
- cout << fixed << showpoint << setprecision (2);
- cout << "Name: "<< cust.name << endl; // struct output
- cout << "Email: "<< cust.email << endl;
- cout << "Phone Number: " << cust.number << endl;
- cout << setfill ('-') << setw (55) << "-" << endl;
- cout << "\nMore Order?(New Transaction) Press Y for yes: ";
- cin >> ordermore;
- }
- }
- void getInfo(struct customer &cust)
- {
- cout << endl << "Enter name: "; // struct input
- cin >> cust.name;
- cin.ignore();
- cout << "Enter email: ";
- cin >> cust.email;
- cin.ignore();
- cout << "Enter phone number: ";
- cin >> cust.number;
- }
- void listHardware()
- {
- int i,j,type,m_type,c_type,r_type,s_type,g_type,quantity=0;
- const int SIZE=3;
- char shopmember,addorder = 'y';
- double total_price=0;
- const double discount=0.1;
- cout << endl;
- cout << "Membership (Y/N): ";
- cin >> shopmember;
- while(addorder=='Y' || addorder=='y')
- {
- cout << endl << "Select which type of hardware that you want to purchase: ";
- cin >> type;
- if(type==1)
- {
- const char *monitor[SIZE][2]=
- {
- {"BenQ PD3200U", "(RM3000)"},
- {"Acer Predator X34", "(RM4000)"},
- {"Dell UltraSharp UP3218K", "(RM8000)"}
- };
- cout << "Monitors:" << endl;
- for(i=0;i<SIZE;i++)
- {
- cout << "\t" << i+1 << ". ";
- for(j=0;j<2;j++)
- {
- cout << monitor[i][j] << " ";
- }
- cout << endl;
- }
- cout << endl << "Enter which Monitor you would like to purchase: ";
- cin >> m_type; //monitor
- cout << endl << "How many Monitor would you like to purchase?" << endl;
- cin >> quantity;
- }
- if(type==2)
- {
- const char *cpu[SIZE][2]=
- {
- {"AMD Ryzen 7 2700X", "(RM1200)"},
- {"Intel Core i5-8600K", "(RM1200)"},
- {"Intel Core i9-7980XE", "(RM8000)"}
- };
- cout << "CPU:" << endl;
- for(i=0;i<SIZE;i++)
- {
- cout << "\t" << i+1 << ". ";
- for(j=0;j<2;j++)
- {
- cout << cpu[i][j] << " ";
- }
- cout << endl;
- }
- cout << endl << "Enter which CPU would you like to purchase: ";
- cin >> c_type; //cpu
- cout << endl << "How many CPU would you like to purchase?" << endl;
- cin >> quantity;
- }
- if(type==3)
- {
- const char *ram[SIZE][2]=
- {
- {"Patriot Viper Elite 8GB DDR4-2400MHz", "(RM400)"},
- {"G.Skill Ripjaws V 16GB DDR4-2400MHz", "(RM1200)"},
- {"Corsair Dominator Platinum 32GB DDR4-3333MHz", "(RM2000)"}
- };
- cout << "RAM:" << endl;
- for(i=0;i<SIZE;i++)
- {
- cout << "\t" << i+1 << ". ";
- for(j=0;j<2;j++)
- {
- cout << ram[i][j] << " ";
- }
- cout << endl;
- }
- cout << endl << "Enter which RAM would you like to purchase: ";
- cin >> r_type; //ram
- cout << endl << "How many RAM would you like to purchase?" << endl;
- cin >> quantity;
- }
- if(type==4)
- {
- const char *ssd[SIZE][2]=
- {
- {"Samsung 860 Pro 1TB", "(RM1250)"},
- {"Crucial MX500 1TB", "(RM600)"},
- {"WD Blue 2TB", "(RM1600)"}
- };
- cout << "SSD:" << endl;
- for(i=0;i<SIZE;i++)
- {
- cout << "\t" << i+1 << ". ";
- for(j=0;j<2;j++)
- {
- cout << ssd[i][j] << " ";
- }
- cout << endl;
- }
- cout << endl << "Enter which SSD would you like to purchase: ";
- cin >> s_type; //ssd
- cout << endl << "How many SSD would you like to purchase?" << endl;
- cin >> quantity;
- }
- if(type==5)
- {
- const char *gcard[SIZE][2]=
- {
- {"Nvidia GeForce RTX 2080 Ti", "(RM4000)"},
- {"Nvidia GeForce GTX 1080 Ti", "(RM2900)"},
- {"AMD Radeon RX 580 8GB", "(RM2100)"}
- };
- cout << "Graphic Card:" << endl;
- for(i=0;i<SIZE;i++)
- {
- cout << "\t" << i+1 << ". ";
- for(j=0;j<2;j++)
- {
- cout << gcard[i][j] << " ";
- }
- cout << endl;
- }
- cout << endl << "Enter which Graphic Card would you like to purchase: ";
- cin >> g_type; //gpu
- cout << endl << "How many Graphic Card would you like to purchase?" << endl;
- cin >> quantity;
- }
- total_price=calcFunc(m_type,c_type,r_type,s_type,g_type,quantity,total_price,shopmember); //function call
- cout << setfill ('-') << setw (55) << "-" << endl;
- cout << "Total price for now (not including membership discount): RM" << total_price << endl;
- cout << setfill ('-') << setw (55) << "-" << endl;
- cout << "Do you want to purchase more? Press y for yes." << endl;
- cin >> addorder;
- }
- cout << setfill ('-') << setw (55) << "-" << endl;
- if (shopmember == 'y' || shopmember == 'Y')
- cout << "Total Price: RM" << total_price-(total_price*discount) << endl;
- else
- cout << "Total Price: RM" << total_price << endl;
- cout << setfill ('-') << setw (55) << "-" << endl;
- }
- double calcFunc(int m_type,int c_type,int r_type, int s_type, int g_type,int quantity,double total_price, char shopmember)
- {
- double m_price=0,c_price=0,r_price=0,s_price=0,g_price=0;
- if(m_type==1) //monitor
- {
- m_price+=3000*quantity;
- }
- else if(m_type==2) //monitor
- {
- m_price+=4000*quantity;
- }
- else if(m_type==3) //monitor
- {
- m_price+=8000*quantity;
- }
- if(c_type==1) //cpu
- {
- c_price+=1200*quantity;
- }
- else if(c_type==2) //cpu
- {
- c_price+=1200*quantity;
- }
- else if(c_type==3) //cpu
- {
- c_price+=8000*quantity;
- }
- if(r_type==1) //ram
- {
- r_price+=400*quantity;
- }
- else if(r_type==2) //ram
- {
- r_price+=1200*quantity;
- }
- else if(r_type==3) //ram
- {
- r_price+=2000*quantity;
- }
- if(s_type==1) //ssd
- {
- s_price+=1250*quantity;
- }
- else if(s_type==2) //ssd
- {
- s_price+=600*quantity;
- }
- else if(s_type==3) //ssd
- {
- s_price+=1600*quantity;
- }
- if(g_type==1) //gpu
- {
- g_price+=4000*quantity;
- }
- else if(g_type==2) //gpu
- {
- g_price+=2900*quantity;
- }
- else if(g_type==3) //gpu
- {
- g_price+=2100*quantity;
- }
- cout << m_price << endl;
- cout << c_price << endl;
- cout << r_price << endl;
- cout << s_price << endl;
- cout << g_price << endl;
- total_price=m_price+c_price+r_price+s_price+g_price;
- return total_price;
- }
- void search_hardware()
- {
- char const *hardware [2] = {"BENQ", "ACER PREDATOR X34"};
- char hw[20];
- char searchmore = 'y';
- system("cls");
- while (searchmore == 'y' || searchmore == 'Y')
- {
- cout << "Enter hardware to search: ";
- cin >> hw;
- int found=0;
- for (int j=0; j<2; j++)
- {
- if (strcmp(hardware[j], hw)==0)
- {
- found=1;
- break;
- }
- }
- if (found==1)
- {
- cout << setfill ('-') << setw (30) << "-" << endl;
- cout << hw << " model is available" << endl;
- cout << setfill ('-') << setw (30) << "-" << endl;
- }
- else
- {
- cout << endl;
- cout << "Sorry, the model " << hw << " is not available";
- }
- cout << "\nSearch again? (Y/N): ";
- cin >> searchmore;
- }
- system ("cls");
- }
- void exit_system()
- {
- cout << endl;
- cout << setfill ('-') << setw (55) << "-" << endl;
- cout << "\tHave a nice day!" << endl;
- cout << setfill ('-') << setw (55) << "-" << endl;
- cout << endl;
- }
- int admin_login()
- {
- string userName;
- string password;
- int loginAttempt = 0;
- while (loginAttempt < 3)
- {
- cout << "Please enter username: ";
- cin >> userName;
- cout << "Please enter password: ";
- cin >> password;
- if (userName == "admin" && password == "eop123")
- {
- cout << "Welcome Admin!" << endl;
- break;
- }
- else
- {
- cout << "Invalid login attempt. Please try again.\n" << '\n';
- loginAttempt++;
- }
- }
- if (loginAttempt == 3)
- {
- cout << "Too many login attempts! The program will now terminate.";
- return 0;
- }
- }
- int main()
- {
- char choice;
- //loading screen
- /*system("cls");
- for(int i=1;i<=50;i++)
- {
- system("cls");
- cout<<"\n\n\n\n\t\t\t\t Loading "<<'\n'<<'\t'<<'\t';
- for(int j=1;j<=i;j++)
- cout<<"²";
- cout<<"\n\n\t "<<2*i<<"%";
- if(i>1 && i<20)
- cout<<"\n\n\tConnecting to server...";
- else if(i>20 && i<40)
- cout<<"\n\n\tChecking your browser...";
- else if(i>40 && i<48)
- cout<<"\n\n\tAccessing Cache...";
- else cout<<"\n\n\tComplete. Press Enter to Continue ";
- Sleep(10);
- }
- getch();
- system("cls");*/
- cout << endl;
- cout << setfill ('-') << setw (55) << "-" << endl;
- cout << "\tWelcome to IIUM Computer Hardware Shop" << endl;
- cout << setfill ('-') << setw (55) << "-" << endl;
- do
- {
- cout << "\nA - Search hardware availability" << endl;
- cout << "\nB - Buy PC hardware" << endl;
- cout << "\nC - Exit System" << endl;
- cout << "\nX - Shopkeeper/Admin Access" << endl;
- cout << "\nPlease enter your selection: ";
- cin >> choice;
- cin.ignore();
- choice = toupper(choice); // Transform to uppercase
- switch (choice)
- {
- case 'A': search_hardware();
- break;
- case 'B': welcomeScreen();
- break;
- case 'C': exit_system();
- break;
- case 'X': admin_login();
- break;
- default: cout << endl;
- cout << "==== Invalid entry. Please select A, B, or C ====" << endl;
- break;
- }
- }while (choice!= 'C');
- system ("pause");
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement