10. Cafeteria Management System Code - Part 1
Hello folks!
Welcome back to this blog series. In the previous blog we have studied advance ways of file handling .
Now In this blog we will see the code for Cafeteria Management System which is an application of object oriented programming studied in prior blogs. So lets start by knowing the libraries used.
Theee libraries that we required in order the implement the code are mentioned above. I will explain you some of the important libraries we needed. So the first one is the iostream library which contains the input output streams which are needed to make the user experience more better.
Next is the fstream library which contains necessary functions for file handling. The stdlib.h library is used for dynamic memory allocation so as to make the space complexity low. Another important library is string.h which is required to perform string operations. We have also used a macro ‘max_value’ which is used to store the maximum number of tables available in the cafe.
Next task is to create a class and then create objects of this class which denote food serving tables of cafe.
So as you can see we have declared a class named Cafe which has private members price which is an array containing prices of each item present in the menu card which we will be displaying in the main() method. Quantity variable contains quantity of each item that the customer has ordered and bill contains the total amount that the customer needs to pay. In the constructor of the class we are setting values of arrays price and quantity to zero assuming that no customer is there on the table and cafe is just started. Next task is to set which items needed to be displayed in the menu. For example, we have taken four items as shown in the above picture. Also we have set the bill value to zero.
Now we need to create a method which would actually do the processing of data obtained from customer which includes getting the order, changing the appropriate values of quantity array and to calculate the total bill.
As you can see in the above image we have created a function named option which takes item number of the item ordered as input and changes values of quantity array and variable bill.
Next function is display which takes a fstream pointer as input. In this function we are basically display the items that we ordered and their respective quantities along with price and total amount. Simultaneously, we are also storing this bill as text in a file using the file pointer that we took as input.
Finally, in the destructor we are assigning bill variable to zero assuming that the previous customer has left the cafe and new customer has arrived. Also, we are assigning zero value to all elements of price and quantity array respectively.
So this is the end of class declaration and in the next blog we’ll explore the main() function and try to understand how the user will interact with the program. We will also examine the need for some global variables that we have used in the program.
By :
Ashutosh Bardapurkar (k-05)
Hrishikesh Deshpande (k-16)
Archit Hiwrekar (k-23)
Chinmay Kapkar (k-33)
Nice work
ReplyDeleteThank you for feedback
Delete👍👍👍👍
ReplyDeleteThank you for feedback
DeleteNice blog!!
ReplyDeleteThank you for feedback
DeleteVery informative blog👍🏻
ReplyDeleteThank you for feedback
DeleteNice
ReplyDeleteGood start
ReplyDelete