Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<iostream>
- #include<string>
- #define MAX 1000
- using namespace std;
- //struct of customer
- struct Customer
- {
- //num of pax
- int num;
- //customer name
- string name;
- // phone number
- string phone;
- //booking date
- string date;
- //booking time
- string time;
- };
- //struct of restoren
- struct Restaurant
- {
- //Array of customers stored in the restaurant
- struct Customer customerArray[MAX];
- //The restaurant currently records the number of customers
- int m_size;
- };
- int isEmty(Restaurant* rts, string Date) {
- for (int i = 0; i < rts->m_size; i++)
- {
- if (rts->customerArray[i].date==Date)
- {
- return i;
- }
- }
- return -1;
- }
- int isEmty(Restaurant* rts, int Num) {
- for (int i = 0; i < rts->m_size; i++)
- {
- if (rts->customerArray[i].num==Num)
- {
- return i;
- }
- }
- return -1;
- }
- void addCustomer(Restaurant*rts) {
- if (rts->m_size == MAX) {
- cout << "it is full, cannot at\n ";
- return;
- }
- else {//add the data
- int Num;
- cout << "enter num of pax:\n";
- cin >> Num;
- rts->customerArray[rts->m_size].num = Num;
- string Name;
- cout << "enter customer name;\n";
- cin >> Name;
- rts->customerArray[rts->m_size].name = Name;
- string Phone;
- cout << "Enter phone Number:\n";
- cin >> Phone;
- rts->customerArray[rts->m_size].phone = Phone;
- string Date;
- cout << "Enter Booking Date:\n";
- cin >> Date;
- rts->customerArray[rts->m_size].date = Date;
- string Time;
- cout << "Enter Booking Time:\n";
- cin >> Time;
- rts->customerArray[rts->m_size].time = Time;
- rts->m_size++;//uodate the quantiti of m_size
- cout << "add finish\n";
- system("pause");
- system("cls");
- }
- }
- void nameBubbleSort(Restaurant* rts){
- int i,j;
- Customer current;
- for(i=0; i<rts->m_size;i++)
- for (j=0; j<rts->m_size-1; j++){
- if(rts->customerArray[j].name>rts->customerArray[j+1].name){
- current = rts->customerArray[j];
- rts->customerArray[j] = rts->customerArray[j+1];
- rts->customerArray[j+1] = current;
- }
- }
- }
- void dateBubbleSort(Restaurant* rts){
- int i,j;
- Customer current;
- for(i=0; i<rts->m_size;i++)
- for (j=0; j<rts->m_size-1; j++){
- if(rts->customerArray[j].date>rts->customerArray[j+1].date){
- current = rts->customerArray[j];
- rts->customerArray[j] = rts->customerArray[j+1];
- rts->customerArray[j+1] = current;
- }
- }
- }
- void phoneBubbleSort(Restaurant* rts){
- int i,j;
- Customer current;
- for(i=0; i<rts->m_size;i++)
- for (j=0; j<rts->m_size-1; j++){
- if(rts->customerArray[j].phone>rts->customerArray[j+1].phone){
- current = rts->customerArray[j];
- rts->customerArray[j] = rts->customerArray[j+1];
- rts->customerArray[j+1] = current;
- }
- }
- }
- void nameBinarySearch(Restaurant* rts, string key){
- int low = 0;
- int high = SIZE-1;
- int median;
- nameBubbleSort(&rts);
- while(low <= high){
- median = (low+high)/2;
- if(key == rts->customerArray[median].name){
- cout<<"*********************************************************\n" ;
- cout << "num of pax:" << rts->customerArray[median].num<< "\n";
- cout << "name:" << rts->customerArray[median].name << "\n";
- cout << "phone number :" << rts->customerArray[median].phone << "\n";
- cout << "Booking time:" << rts->customerArray[median].time << "\n";
- cout << "Booking Date :" << rts->customerArray[median].date << "\n";
- cout<<"*********************************************************\n";
- return;
- }else if(key < rts->customerArray[median].name){
- high = median - 1;
- }else{
- low = median + 1;
- }
- }
- cout<<"no data\n";
- }
- void phoneBinarySearch(Restaurant* rts, string key){
- int low = 0;
- int high = SIZE-1;
- int median;
- nameBubbleSort(&rts);
- while(low <= high){
- median = (low+high)/2;
- if(key == rts->customerArray[median].phone){
- cout<<"*********************************************************\n" ;
- cout << "num of pax:" << rts->customerArray[median].num<< "\n";
- cout << "name:" << rts->customerArray[median].name << "\n";
- cout << "phone number :" << rts->customerArray[median].phone << "\n";
- cout << "Booking time:" << rts->customerArray[median].time << "\n";
- cout << "Booking Date :" << rts->customerArray[median].date << "\n";
- cout<<"*********************************************************\n";
- return;
- }else if(key < rts->customerArray[median].phone){
- high = median - 1;
- }else{
- low = median + 1;
- }
- }
- cout<<"no data\n";
- }
- int seachcustomer(Restaurant*rts){
- int m_num;
- string Date;
- int ch=0;
- cout<<"1.seach by num fo pax\n";
- cout<<"2.sech by date\n";
- while(true){
- cin>>ch;
- if(ch==1){
- int Num;
- cout<<"enter number of pax\n";
- cin>>Num;
- Num=m_num+1;
- int ret = isEmty(rts, Num);
- if (ret!=-1){
- string Num, Name, Phone, Date, Time;
- cout << "num of pax:" << rts->customerArray[ret].num << "\t";
- cout << "name:" << rts->customerArray[ret].name << "\t";
- cout << "phone number :" << rts->customerArray[ret].phone << "\t";
- cout << "Booking time:" << rts->customerArray[ret].time << "\t";
- cout << "Booking Date :" << rts->customerArray[ret].date << "\t";
- cout << "\n";
- }
- else
- {
- cout << " no fine record\n";
- }
- cout << "\n";
- system("pause");
- system("cls");
- }
- else if(ch==2){
- string Date;
- cout << "enter booking date you need seach";
- cin >> Date;
- int ret = isEmty(rts, Date);
- if (ret != -1)
- {
- string Num, Name, Phone, Date, Time;
- cout << "num of pax:" << rts->customerArray[ret].num<< "\t";
- cout << "name:" << rts->customerArray[ret].name<< "\t";
- cout << "phone number :" << rts->customerArray[ret].phone<< "\t";
- cout << "Booking time:" << rts->customerArray[ret].time<< "\t";
- cout << "Booking Date :" << rts->customerArray[ret].date<< "\t";
- cout << "\n";
- }
- else
- {
- cout << " no fine record\n";
- }
- cout << "\n";
- system("pause");
- system("cls");
- }else{
- cout<<"Erro input\n";
- }
- return 0;
- system("pause");
- system("cls");
- }
- }
- void ShowAll(Restaurant*rts) {
- //if m_size=0 then emty else show all record
- if (rts->m_size == 0) {
- cout << "the recort is emty\n";
- }
- else
- {
- for ( int i = 0; i <rts->m_size; i++)
- { cout<<"*********************************************************\n" ;
- cout << "num of pax:" << rts->customerArray[i].num<< "\n";
- cout << "name:" << rts->customerArray[i].name << "\n";
- cout << "phone number :" << rts->customerArray[i].phone << "\n";
- cout << "Booking time:" << rts->customerArray[i].time << "\n";
- cout << "Booking Date :" << rts->customerArray[i].date << "\n";
- cout<<"*********************************************************\n";
- system("pause");
- system("cls");
- }
- }
- }
- void ShowManu() {
- cout << "1.add\n ";
- cout << "2.show\n";
- cout << "3.sort\n";
- cout << "4.seach\n";
- cout << "0.exit\n";
- }
- int main() {
- Restaurant rts;
- rts.m_size = 0;
- int select = 0;
- int selectSort = 0;
- while (true)
- {
- ShowManu();
- cin >> select;
- switch (select)
- {
- case 1://add
- addCustomer(&rts);
- break;
- case 2://show
- ShowAll(&rts);
- break;
- case 3:
- cout << "1.sort by name\n ";
- cout << "2.sort by date\n";
- cout << "0.exit\n";
- cin >> selectSort;
- switch (selectSort)
- {
- case 1://add
- nameBubbleSort(&rts);
- break;
- case 2://show
- dateBubbleSort(&rts);
- break;
- default:
- break;
- }
- break;
- case 4://seach
- seachcustomer(&rts);
- break;
- case 0://exit
- cout << "welcome next time" << endl;
- system("pause");
- return 0;
- break;
- default:
- break;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement