Professional Documents
Culture Documents
CSC404 PROGRAMMING II
PREPARED BY
GROUP
CS2302B2
PREPARED FOR
DATE OF SUBMISSION
In our application program, there are 3 structs that we use to store the information.
The structs are “Burgers”, “CustomerOrder”, and “WorkerInfo”. In Burger’s struct, the
members are burgername, price, and drink. For CustomerOrder’s struct, the members are
choice, custname, qty (quantity), totalpay, burger, and drink. Lastly, for WorkerInfo’s struct,
the members are name, age, workhour, hourrate, and salary. Our program implements 6
functions. The first function is “displaymenu” and it is displayed on the terminal. It is used to
display the menu which is the burger's name, price, and drink that we served in our burger
shop.The menu that is displayed on the terminal is read from the “inputmenu” function.
“inputmenu” function reads the menu from the BurgersMenu.txt. Next is, “displayreceipt”
function that is used to show the receipt for the customers and it is written into Receipt.txt.
Next function is “calcaveragentotal”. As the name suggests, it will calculate the total
pay from all the customers and we declared it as our total sale. Based on our customers'
number on that day, we will calculate the average. Both total sale and average are written into
a text file named SalesReport.txt. The next function is “maxmin”. This function will find the
maximum and minimum sale for today and display the total pay. The last function is the
function “search”. This function will search the customers who spent over RM50 and display
the customers name and the total pay if the bool found returns true. Else, it will display the
message “No customers have total pay above RM 50”. All the functions that were used are
void type.
There are many 1-dimensional arrays that can be found in our application program as
we declared it as the variable of structs. For CustomerOrder struct, we declared an array
named “customer” sized 200. For Burgers struct, we declared an array named “combo” sized
5. For the last struct which is the WorkerInfo struct, we declared an array named “worker”
with the size of 5. Another 1D array that we used is the “totalbonus” with the size of 5 as we
have 5 workers. While for the 2-dimensional array, we have a “bonus” array with row size 5
and column size 200. Row size is following the number of workers and the column size is
depending on the number of customers. We used nested loops for calculating the values that
we want to store in the “bonus” array. For pointer, we declared variable p as a pointer and
assigned it to address value of totalcust to calculate the total customer that came to our shop
on that day.
In conclusion, the program code is created to smoothen our shop management and
help us to see a clearer vision of our shop’s future since it has all the techniques and
functionality in the program, which in less time will improve the burger shop business and
give a brighter opportunity to become successful. This application helps our business in
many ways, such as expanding our business branch and becoming a franchise, helps the
business to target more customers, gives a boost to our business sales and improves the
quality services within time. Lastly, this program will ensure the workers get the total salary
that they deserved since no mistake could happen when calculating their bonus using this
program code
The purpose of this program code is to collect all the data that are related to our shop.
Firstly, we want to display our shop menu and price to our customers. We want to help
customers in making their orders and let our customers know about our special burgers’
names which are only available at our shop. This program will read the data from a text file
named BurgersMenu.
This program code will ask the customer's choice, name, and quantity. The customer’s
choice will determine the burger combo he or she will get and the total pay for his or her
order based on the quantity. All of this information will be recorded and written into a text
file named Receipt. From the customer's total pay, this program will search the customers
who pay above RM 50 and write the information into a text file named SalesReport. The
sales report also stores the total customers, total pay for all the customers, and finds the
average pay for each customer for one day of business. This program code will also
determine the minimum and maximum customers’ pay and store into this SalesReport textfile
too.
Not only that, the program code will also read the worker's information from the
WorkersData text file that contains name, age, work hour, and rate per hour of the workers.
Then, from work hour and rate per hour, the program code will calculate the salary of each
worker. The total bonus will be added to the salary to get the final salary amount for each
worker. The bonus is gained from 0.05% of each customer's total pay. All of the workers'
information will be written into a text file named WorkersReport.
The application program will be used by the workers since they need to input the
customer’s orders. There are two limitations that we have in this program code. First, the
number of customers that we can receive in a day. For the number of customers, we can only
receive 200 customers per day. The total customers can be less than 200 depends on the total
customers buying burger for that day. It does not mean it has to be totally 200 customers but
the maximum capita of customers we can receive is only 200. The next limitation is this
program is only able to get the data for one day of business. In order to save the data for
another day of business, we have to create the new text file for every day we run our
business, or we have to clear the previous information that we have stored before.
4.0 SOURCE CODE
int main(){
//declare struct variable into array
CustomerOrder customer[200];
WorkerInfo worker[5];
Burgers combo[5];
int totalcust=0; //declare variable totalcust
totalcust=0; //initialize totalcust
int *p; //declare variable pointer
p=&totalcust; //assign address to variable pointer
int x = 0; //counter for array customer in do while loop
float totalsale=0; //declare and initialize totalsale
float average; //declare average
char next; //declare variable next
bool found = false; //declare and initialize variable found
float bonus[5][200]; //declare 2d array [5]-worker [200]-customer
float totalbonus[5]; //declare 1d array [5]-worker
//reading data and open the input file
ifstream order("BurgersMenu.txt");
else{
cout << "This combo is not exist in our menu." << endl;} //display if the set is not in
menu
cout << "Total pay: RM "<<fixed<<setprecision(2) << customer[x].totalpay << endl;
//display totalpay
totalcust++; //count total customer
cout << "Next customer? [Y-Yes || N-No]"<<endl; //ask user to continue or not
cin >> next; //user input
if (next=='N'||next=='n'){ //condition for No answer
break;} //to stop
cout << endl << endl;
}
sale << "TOTAL CUSTOMER OF ZATOHAJO BURGER SHOP FOR TODAY IS "<<
totalcust <<endl; //display totalcust in textfile
displayreceipt(receipt, customer, *p); //function call for displayreceipt function
avgntotal(sale, customer, *p); //function call for calcaveragentotalsale function
maxmin(sale, customer, *p); //function call for maxmin function
search(sale, customer, *p, found); //function call for search function
//close order, receipt,sale files
order.close();
receipt.close();
sale.close();
ifstream workdata("WorkersData.txt"); //reading data and open the input file
ofstream workreport("WorkersReport.txt"); //writing data and open the output file
while (order.good()){
int i = 0; //initialize i
getline(order, line);
stringstream ss (line); //convert into string stream
string temp; //declare temp
while (getline (ss, temp, ';')){ //use semicolon as delimeter for cutting string
tokens[i] = temp; //assign token to temp
i++;
}
combo[j].burgername = tokens[0];
combo[j].price = atof(tokens[1].c_str()); //string to float
combo[j].drink = tokens[2];
j++;} //increament by 1
}
void displayreceipt(ofstream &receipt, CustomerOrder customer[], int totalcust){//function
definition for display function
//display receipt for customer
for (int i=0; i<totalcust; i++){
receipt << "THANK YOU " << customer[i].custname << " \nTHIS IS YOUR
RECEIPT." << endl;
receipt << setw(15) << "CHOICE"<< setw(18) <<"BURGER" << setw(18)
<< "DRINK" << setw(20) << "QUANTITY" << endl;
receipt << setw(15) << "------"<< setw(18) <<"------" << setw(18) <<"-----"
<< setw(20) <<"--------" << endl;
receipt << setw(15) << customer[i].choice << setw(20) ;
receipt << customer[i].burger << setw(10) <<" ";
receipt << customer[i].drink << setw(10) <<" ";
receipt << customer[i].qty;
receipt << endl << endl << "TOTAL PAY : RM "<< fixed << setprecision(2) <<
customer[i].totalpay << endl ; //display totalpay
receipt << "PLEASE COME AGAIN :) " << endl << endl;}
}
void search(ofstream &sale, CustomerOrder customer[], int totalcust, bool found){ //function
definition for search function