C++ Café Project- camelCase

AbdulSamad Olagunju / January 07, 2022

12 min read

Tutorials

Here is the code:

MainScreen.h

MainScreen.h
#ifndef MAINSCREEN_H
#define MAINSCREEN_H
//include all libraries to be used
#include <iostream>
#include "SELFCHECKOUT.h"
#include "CASHIERCHECKOUT.h"
#include <string>
#include "STRUCTURE.h"

using namespace std;

//create class mainscreen, declare members required for program
class MainScreen 
{
	public:
		int numberofcustomers = 5;
		int continueornot;
		int option, whichmenu;
		bool correctlogin = false;
		bool correctpassword;
		char ans;
		int num, num2;
		float discountcost;
		int id;
		int position, position2;
		int choice;
		int IDans, IDnum;
		int counter;
		float discount;
		float customercash;
		float customercashtotal = 0;
		char typeofdiscount;
		float cost = 0;
		int password;
		void mainMessage();
		float menu[11] = {0, 8, 14, 16, 15, 16, 17, 14, 15, 9, 9};
};
#endif

MainScreen.cpp

MainScreen.cpp
//include all libraries to be used
#include <iostream>
#include "SELFCHECKOUT.h"
#include "CASHIERCHECKOUT.h"
#include "MAINSCREEN.h"
#include "STRUCTURE.h"
#include <string>

using namespace std;

void MainScreen :: mainMessage()
{
	//create information for five customers
	customer person[50];
	person[0].ID = 11;
	person[0].username = "joe@gmail.com";
	person[0].password = "bobby";
	person[0].typeofdiscount = 'E';
	person[1].ID = 12;
	person[1].username = "kyle@gmail.com";
	person[1].password = "drew";
	person[1].typeofdiscount = 'E';
	person[2].ID = 13;
	person[2].username = "narr@gmail.com";
	person[2].password = "dog";
	person[2].typeofdiscount = 'R';
	person[3].ID = 18;
	person[3].username = "daad@gmail.com";
	person[3].password = "doop";
	person[3].typeofdiscount = 'R';
	person[4].ID = 166;
	person[4].username = "narrkk@gmail.com";
	person[4].password = "dogmath";
	person[4].typeofdiscount = 'R';
	int othernum;
	//do while so that customer enters correct id and password
	do{
		numberofcustomers = 5;
		cout << "Please enter your correct login information: " << endl;
		cout << "ID: ";
		cin >> id;
		cout << "Password: ";
		cin >> person[40].password;
		for(int i = 0; i <= numberofcustomers; i++)
		{
			if((id == person[i].ID) && (person[40].password == person[i].password))
			{
				othernum = i;
				correctlogin = true;
			}
		}
	}while(correctlogin == false);
	//do while if user wants to continue shopping
	do{
		//so user enters 1 or 2
		do
		{
			if(correctlogin == true)
			{
				cout << "Please enter option 1 or option 2 in order to identify your preferred method of check out. " << endl;
				cout << "Option 1: Self Check Out" << endl; 
				cout << "Option 2: Check Out by Cashier" << endl;
				cin >> option;
			}
		}while((option != 1) && (option != 2));
		if(option == 1)
		{
			//create object s for self check out
			SelfCheckOut s;
			s.findcost(othernum, person);
		}
		if(option == 2)	
		{	
			//create object c for cashiercheckout
			CashierCheckOut c;
			//must enter 1 or 2 to enter sales menu of data entry menu
			do{
				cout << "Select 1 to enter the sales menu, or 2 to enter the data entry menu: ";
				cin >> whichmenu;
			}while((whichmenu != 1) && (whichmenu != 2));
			if (whichmenu == 1)
			{
				//call on function for sales menu
				c.salesMenu();
			}
			else if(whichmenu == 2)
			{
				//call on function for data entry menu
				c.dataEntryMenu(person);
			}
		}
		cout << "If you would like to continue shopping, press 1. If you would like to quit the program, press 2: ";
		cin >> continueornot;
	}while(continueornot == 1);
}

CashierCheckOut.h

CashierCheckOut.h
#ifndef CASHIERCHECKOUT_H
#define CASHIERCHECKOUT_H
#include <string>
//include all libraries to be used
#include <iostream>
#include "SELFCHECKOUT.h"
#include "MAINSCREEN.h"
#include "STRUCTURE.h"

using namespace std;
//creat class cashier checkout, inherit public mainscreen
class cashiercheckout : public mainscreen
{	
	public:
		void salesMenu();
		void dataEntryMenu(customer person[50]); 
};

#endif

CashierCheckOut.cpp

CashierCheckOut.cpp
//include all libraries to be used
#include <iostream>
#include "SELFCHECKOUT.h"
#include "CASHIERCHECKOUT.h"
#include "MAINSCREEN.h"
#include "STRUCTURE.h"
#include <string>

using namespace std;

void CashierCheckout :: salesMenu() 
{   //show menu
	cout << "Abdul's Cafe and Bakery Breakfast Menu: " << endl;
	cout << "1. YOGURT PARFAIT | $8.00 |" << endl;
	cout << "2. BACON & EGG | $14.00 |" << endl;
	cout << "3. EGGS BENEDICT – CANADIAN | $16.00 |" << endl;
	cout << "4. EGGS BENEDICT – GARDEN | $15.00 |" << endl;
	cout << "5. EGGS BENEDICT – GRAVLAX | $16.00 |" << endl;
	cout << "6. CRAB & SPRING ONION OMELETTE | $17.00 |" << endl;
	cout << "7. BUTTERMILK WAFFLES | $14.00 |" << endl;
	cout << "8. HAZELNUT CHOCOLATE CRÈPE | $15.00 |" << endl;
	cout << "9. BACON BREAKFAST SANDWICH | $9.00 |" << endl;
	cout << "10. VEGGIE BREAKFAST SANDWICH | $9.00 |" << endl;
	//ask user for amount of products they would like to buy, and number of units
	do{
		cout << "Please choose the product the customer would like to purchase by entering the product number: ";
		cin >> num;
		cout << "How many units of the product would the customer like to purchase? ";
		cin >> num2;
		for(int i = 1; i <= 11; i++)
		{
			if(num == i)
			{
				for(int otheri = 0; otheri < num2; otheri++)
				{
					cost += menu[i];
				}
			}
		}
		cout << "Would the customer like to purchase another product? (y/n)";
		cin >> ans;
	}while(ans == 'y');
	do{
		//find out type of membership
		cout << "Select 'E' if the customer is an executive member, 'R' if the customer is a regular member, and 'N' if the customer is not a member: ";
		cin >> typeofdiscount;
	}while((typeofdiscount != 'E') && (typeofdiscount != 'R') && (typeofdiscount != 'N'));
	if(typeofdiscount == 'E')
	{
		discount = 0.8;
	}
	else if(typeofdiscount == 'R')
	{
		discount = 0.9;
	}
	else if(typeofdiscount == 'N')
	{
		discount = 1;
	}
	discountcost = cost * discount;
	//show cost
	cout << "The total cost of the meal is $" << discountcost << "." << endl;
	do
	{
		//get customer cash, see if they have paid right amount
		cout << "Please enter the amount of money the customer would like to deposit: " << endl;
		cin >> customercash;
		customercashtotal += customercash;					
		if(customercashtotal > discountcost)
		{
			cout << "Here is the change: " << customercashtotal - discountcost << endl;
		}
		else if((customercash < discountcost) && (discountcost - customercashtotal != 0))
		{
			cout << "Here is the amount the customer still needs to pay: " << discountcost - customercashtotal << endl;	
		}
	}while(customercashtotal < discountcost);
}

void CashierCheckout :: dataEntryMenu(customer person[50]) 
{
	/*//create 5 customers
	numberofcustomers = 5;
	customer person[50];
	person[0].ID = 11;
	person[0].username = "joe@gmail.com";
	person[0].password = "bobby";
	person[0].typeofdiscount = 'E';
	person[1].ID = 12;
	person[1].username = "kyle@gmail.com";
	person[1].password = "drew";
	person[1].typeofdiscount = 'E';
	person[2].ID = 13;
	person[2].username = "narr@gmail.com";
	person[2].password = "dog";
	person[2].typeofdiscount = 'R';
	person[3].ID = 18;
	person[3].username = "daad@gmail.com";
	person[3].password = "doop";
	person[3].typeofdiscount = 'R';
	person[4].ID = 166;
	person[4].username = "narrkk@gmail.com";
	person[4].password = "dogmath";
	person[4].typeofdiscount = 'R';*/
	//ask what user wants, to add, update, or delete
	do{
		cout << "To enter a new customer into the system, please select 1. To search for an ID in the system, please select 2. To update a customer's information, please select 3. To display all the information in the database, please select 4. To delete a customer, please select 5: ";
		cin >> IDans;
	}while((IDans != 1) && (IDans != 2) && (IDans != 3) && (IDans != 4) && (IDans != 5));
	if(IDans == 1)
	{
		cout << "Please enter the person's ID, username, password, and type of discount (E or R): ";
		cin >> person[numberofcustomers].ID >> person[numberofcustomers].username >> person[numberofcustomers].password >> person[numberofcustomers].typeofdiscount;
		numberofcustomers++;
	}
	if(IDans == 2)
	{
		cout << "Please enter the person's ID: ";
		cin >> IDans;
		for(int i = 0; i < numberofcustomers; i++)
		{
			if(IDans == person[i].ID)
			{
				cout << "ID: " << person[i].ID << endl << "Username: " << person[i].username << endl << "Password: " << person[i].password << endl << "Type of Discount: " << person[i].typeofdiscount << endl;
			}		
		}
	}
	if(IDans == 3)
	{
		cout << "Please enter the person's ID: ";
		cin >> IDans;
		cout << "Select 1 to edit the person's ID, 2 to edit the person's username, 3 to edit the person's password, or 4 to edit the person's type of discount (E or R): ";
		cin >> choice;
		if(choice == 1)
		{
			for(int i = 0; i < numberofcustomers; i++)
			{
				if(IDans == person[i].ID)
				{
					cout << "Please enter the person's new ID: ";
					cin >> person[i].ID;
				}		
			}
		}
		else if(choice == 2)
		{
			for(int i = 0; i < numberofcustomers; i++)
			{
				if(IDans == person[i].ID)
				{
					cout << "Please enter the person's new username: ";
					cin >> person[i].username;
				}		
			}
		}
		else if(choice == 3)
		{
			for(int i = 0; i < numberofcustomers; i++)
			{
				if(IDans == person[i].ID)
				{
					cout << "Please enter the person's new password: ";
					cin >> person[i].password;
				}		
			}
		}
		else if(choice == 4)
		{
			for(int i = 0; i < numberofcustomers; i++)
			{
				if(IDans == person[i].ID)
				{
					cout << "Please enter the person's new type of discount: ";
					cin >> person[i].typeofdiscount;
				}		
			}
		}
	}
	if(IDans == 4)
	{
		//sort before displaying
		for(int i = 0; i < numberofcustomers; i++)
		{
			for(int j = 0; j < numberofcustomers-1; j++)
			{
				if(person[j].ID > person[j+1].ID)
				{
					int temp = person[j+1].ID;
					person[j+1].ID = person[j].ID;
					person[j].ID = temp;
				}
			}
		}
		for(int i = 0; i < numberofcustomers; i++)
		{
			cout << "ID: " << person[i].ID << endl << "Username: " << person[i].username << endl << "Type of Discount: " << person[i].typeofdiscount << endl;
		}
	}
	if(IDans == 5)
	{
		cout << "Please enter the person's ID: ";
		cin >> IDans;
		for(int i = 0; i < numberofcustomers; i++)
		{
			if(IDans == person[i].ID)
			{
				position = i;
			}
		}
		position2 = numberofcustomers;
		position2--;
		for(int i = position; i <= position2; i++)
	    {
	    	person[i].ID = person[i+1].ID;
			person[i].username = person[i+1].username;
			person[i].password = person[i+1].password;
			person[i].typeofdiscount = person[i+1].typeofdiscount;
	    }
	    for(int i = 0; i < position2; i++)
		{
			cout << "ID: " << person[i].ID << endl << "Username: " << person[i].username << endl << "Type of Discount: " << person[i].typeofdiscount << endl;
		}
	}
	//sort customers
	for(int i = 0; i < numberofcustomers; i++)
	{
		for(int j = 0; j < numberofcustomers-1; j++)
		{
			if(person[j].ID > person[j+1].ID)
			{
				int temp = person[j+1].ID;
				person[j+1].ID = person[j].ID;
				person[j].ID = temp;
			}
		}
	}
}

SelfCheckOut.h

SelfCheckOut.h
#ifndef SELFCHECKOUT_H
#define SELFCHECKOUT_H
//include all libraries to be used
#include <iostream>
#include <string>
#include "CASHIERCHECKOUT.h"
#include "MAINSCREEN.h"
#include "STRUCTURE.h"

using namespace std;
//create selfcheckout, inherit mainscreen
class SelfCheckOut : public MainScreen
{	
	public:
		void findCost(int newID, customer person[50]);
};
#endif

SelfCheckOut.cpp

SelfCheckOut.cpp
//include all libraries to be used
#include <iostream>
#include "SELFCHECKOUT.h"
#include "CASHIERCHECKOUT.h"
#include "MAINSCREEN.h"
#include "STRUCTURE.h"
#include <string>

using namespace std;

void SelfCheckOut :: findCost(int newID, customer person[50]) 
{
	//create customers
	/*customer person[50];
	person[0].ID = 11;
	person[0].username = "joe@gmail.com";
	person[0].password = "bobby";
	person[0].typeofdiscount = 'E';
	person[1].ID = 12;
	person[1].username = "kyle@gmail.com";
	person[1].password = "drew";
	person[1].typeofdiscount = 'E';
	person[2].ID = 13;
	person[2].username = "narr@gmail.com";
	person[2].password = "dog";
	person[2].typeofdiscount = 'R';
	person[3].ID = 18;
	person[3].username = "daad@gmail.com";
	person[3].password = "doop";
	person[3].typeofdiscount = 'R';
	person[4].ID = 166;
	person[4].username = "narrkk@gmail.com";
	person[4].password = "dogmath";
	person[4].typeofdiscount = 'R';*/
	//show menu
	cout << "Abdul's Cafe and Bakery Breakfast Menu: " << endl;
	cout << "1. YOGURT PARFAIT | $8.00 |" << endl;
	cout << "2. BACON & EGG | $14.00 |" << endl;
	cout << "3. EGGS BENEDICT – CANADIAN | $16.00 |" << endl;
	cout << "4. EGGS BENEDICT – GARDEN | $15.00 |" << endl;
	cout << "5. EGGS BENEDICT – GRAVLAX | $16.00 |" << endl;
	cout << "6. CRAB & SPRING ONION OMELETTE | $17.00 |" << endl;
	cout << "7. BUTTERMILK WAFFLES | $14.00 |" << endl;
	cout << "8. HAZELNUT CHOCOLATE CRÈPE | $15.00 |" << endl;
	cout << "9. BACON BREAKFAST SANDWICH | $9.00 |" << endl;
	cout << "10. VEGGIE BREAKFAST SANDWICH | $9.00 |" << endl;
	//ask user for amount of products they would like to buy, and number of units
	do{
		cout << "Please choose the product you would like to purchase by entering the product number: ";
		cin >> num;
		cout << "How many units of the product would you like to purchase? ";
		cin >> num2;
		for(int i = 1; i <= 11; i++)
		{
			if(num == i)
			{
				for(int otheri = 0; otheri < num2; otheri++)
				{
					cost += menu[i];
				}
			}
		}
		cout << "Would you like to purchase another product? (y/n)";
		cin >> ans;
	}while(ans == 'y');
	//since it is self checkout, already know membership
	typeofdiscount = person[newID].typeofdiscount;
	if(typeofdiscount == 'E')
	{
		discount = 0.8;
	}
	if(typeofdiscount == 'R')
	{
		discount = 0.9;
	}
	discountcost = cost * discount;
	//show cost
	cout << "The total cost of your meal is $" << discountcost << "." << endl;
	do
	{
		//get customer cash, see if they have paid right amount
		cout << "Please enter the amount of money you would like to deposit: " << endl;
		cin >> customercash;
		customercashtotal += customercash;					
		if(customercashtotal > discountcost)
		{
			cout << "Here is your change: " << customercashtotal - discountcost << endl;
		}
		else if((customercash < discountcost) && (discountcost - customercashtotal != 0))
		{
			cout << "Here is the amount you still need to pay: " << discountcost - customercashtotal << endl;	
		}
	}while(customercashtotal < discountcost);
}

structure.h

structure.h
#ifndef STRUCTURE_H
#define STRUCTURE_H
//include all libraries to be used
#include <string>

using namespace std;
//create structure for customer information
struct customer 
{
	int ID;
	string username;
	string password;
	char typeofdiscount;
};

		
#endif

main.cpp

main.cpp
//Abdul-Samad Olagunju

//include all libraries to be used
#include <iostream>
#include "SELFCHECKOUT.h"
#include "CASHIERCHECKOUT.h"
#include "MAINSCREEN.h"
#include "STRUCTURE.h"
#include <string>

using namespace std;

int main() 
{
	//welcome message
	cout << "Welcome to Abdul's Cafe!" << endl;
	//create object and call on function needed
	MainScreen m;
	m.mainMessage();
	//thank you message
	cout << "Thank you for shopping at Abdul's Cafe! Come Back Again!" << endl;	
}