PropellerAds
Posted by : Unknown Tuesday, 27 January 2015

Problem:

You have to serve 20 people in all.

  •  space available in queue is for 10 people.
  •  first person entering the queue will be served first.
  •  people coming to pay the bill will be added 
  • if yes (ask for amount)
  • if no move next
  • In every iteration you will ask the secrity guard if any person is served or not
  • if yes ask number of user served and process them
  • when every one is served print the total amount of payment recieved
    Solution:

      #include<iostream>
        #include<conio.h>


            using namespace std;


                void enter_queue(int billing_array[], int &persons_in_queue, int &total_person_served){


                    char security = 'n';


                        if (total_person_served + persons_in_queue < 20){
                          cout << "To security guard:" << endl << "Is there any person to enter in queue? (press y for yes): ";
                            cin >> security;

                                if (security == 'y' && persons_in_queue < 10){
                                  do{
                                    cout << "Enter in queue, show your bill to security guard: ";
                                      cin >> billing_array[persons_in_queue];
                                        if (billing_array[persons_in_queue] < 0){
                                          cout << "Wrong Input" << endl;
                                            }
                                              } while (billing_array[persons_in_queue] < 0);
                                                persons_in_queue++;
                                                  } else if (persons_in_queue >= 10){
                                                    cout << endl << "No more space in queue....." << endl;
                                                      }
                                                        }
                                                          }


                                                              void people_served(int billing_array[], int &persons_in_queue, int &total_payment_recieved, int &total_person_served){

                                                                  int person_served = 0;
                                                                    cout << "To security guard:\nHow many user are served?\nNumber of user served are: ";
                                                                      cin >> person_served;


                                                                          //readjust/serve the person;
                                                                            if (person_served <= persons_in_queue){
                                                                              for(int i = 0; i < person_served; i++){
                                                                                total_payment_recieved += billing_array[i];
                                                                                  billing_array[i] = billing_array[i+person_served];
                                                                                    persons_in_queue--;
                                                                                      }

                                                                                          for(int i = persons_in_queue; i < 10; i++){
                                                                                            billing_array[i] = 0;
                                                                                              }
                                                                                                total_person_served += person_served;
                                                                                                  } else{
                                                                                                    cout << "Person served Exceeds person in queue limit..." << endl;
                                                                                                      }

                                                                                                          }


                                                                                                              void main(){
                                                                                                                int billing_array[10] = {0};
                                                                                                                  int persons_in_queue = 0;
                                                                                                                    int total_payment_recived = 0;
                                                                                                                      int total_person_served = 0;


                                                                                                                          while(total_person_served < 20){
                                                                                                                            //entry point queue;
                                                                                                                              enter_queue(billing_array, persons_in_queue, total_person_served);
                                                                                                                                people_served(billing_array, persons_in_queue, total_payment_recived, total_person_served);


                                                                                                                                    //print queue;
                                                                                                                                      cout << endl << "Queue status;" << endl;
                                                                                                                                        for (int i = 0; i < 10; i++){
                                                                                                                                          cout << billing_array[i] << endl;
                                                                                                                                            }


                                                                                                                                                cout << endl;
                                                                                                                                                  }


                                                                                                                                                      cout << endl << "Total Payment Recived: " << total_payment_recived;


                                                                                                                                                          _getch();
                                                                                                                                                            }

                                                                                                                                                            Leave a Reply

                                                                                                                                                            Subscribe to Posts | Subscribe to Comments

                                                                                                                                                            PropellerAds
                                                                                                                                                            PropellerAds

                                                                                                                                                            Popular Post

                                                                                                                                                            Powered by Blogger.

                                                                                                                                                            - Copyright © BSCS -Metrominimalist- Powered by Blogger - Designed by Johanes Djogan -