/* OPPGAVETEKSTEN + NOEN KOMMENTARER.
----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Due: Wednesday, 5 October 2022 23:59
----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Guidelines and warnings:
• Use your own approach and algorithm to write the code.
• You are not allowed to use concepts and topics we have not covered in the course yet such as arrays, structures, pointers, etc. Use whatever you have learnt from the beginning of the semester up until the end of chapter 6 (Functions) in a way that makes your job easier.
• Group members should discuss the problem together to come up with a solution (an algorithm) before writing the actual code.
• Any copies from the internet or other groups will give you an automatic FAIL for the project for every involved party (the giver and the taker).
• Each group must submit one C++ file (e.g., project1.cpp) at the end, including the source code of the project.
• The submission will be done electronically to Canvas.
----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Wedding Planner
----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
In this project, you will write a C++ program to assist in wedding planning.
This program will mainly be used as an assistant to a wedding organization. Your program should work as follow:
----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
DESCRIPTION for each task (11 total) is included right after the part of code corresponding to the given task.
Most of descriptions are included furthest down, right after the "user defined" functions.
- FILIP
----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
EXAMPLE OUTPUT:
Enter the number of invited guests: 90
Needs: 45 invitation cards, 108 sweets, 15 tables, 15 cases of coke and 45 cases of water.
Cost of invitation cards: 9000 NOK
Cost of drinks: 450 NOK for coke and 900 NOK for water with a total of 1350 NOK.
NOTE!
THIS PROGRAM GIVES DIFFERENT OUTPUT THAN EXAMPLE, STILL, SAME SHIT IS INCLUDED.
- FILIP
----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
*/
#include <iostream>
#include <cmath> // used for ceil() and floor() functions in tasks 6 and 7.
using namespace std;
// VARIABLES ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------
int meny_valg;
int guests, cards, sweets, tables, coke, water, card_price, coke_price, water_price;
char empty;
// CONSTANT VARIABLES ------------------------------------------------------------------------------------------------------------------------------------------------------------------
const float guests_per_table = 6.00;
const float people_per_coke_case = 6.00;
const float people_per_water_case = 2.00;
const float cost_coke = 30.00;
const float cost_water = 20.00;
// USER DECLARED FUNCTIONS - USED IN THE MAIN PROGRAM -------------------------------------------------------------------------------------------------------------------------------------------
void menu(int guests); // cout ONLY - shows the menu - use together with choice()!!!
void choice(int& meny_valg, int &guests); // gets user's menu choice
void guests_number (int &guests); // gets number of guests
void cards_n_sweets(int &guests, int &cards, int &sweets); // calculates number of invitation cards and sweets needed
void tables_to_reserve (int &guests, int &tables, const float &guestes_per_table); // calculates number of tables needed for n guests. Needs <cmath> to work!
void drinks (int &guests, int &coke, int &water, const float &people_per_coke_case, const float &people_per_water_case); // calculates number of drinks needed
void card_cost (int &cards,int &guests, int &card_price); // calculates price of invitation cards
void drink_cost(int &coke, int &water, int &coke_price, int &water_price, const float &cost_coke, const float &cost_water); // calculates cost of drinks
void all_info (int &guests, int &cards, int &sweets, int &tables, int &coke, int &water, int &coke_price, int &water_price); // shows all info input/calculated from start to the point this function is called and executed
//--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
int main()
{
// TASK 1 - DESCRIPTION - Display a message stating that the Wedding Planning Assistant is pleased to be at your service!
// Hadi never stated that this one has to be a function soooo... lots of plain text. :D
cout
<<"Wedding Planning Assistant is pleased to be at your service! \nLet's begin!"<<endl<<endl
<<"Press any key, then 'ENTER' to show 'MENU' and begin planning."<<endl<<endl;
cout
<<"Use the following menu to navigate and choose information You want to give me first."<<endl<<endl
<<"I recommend starting from '1): Enter number of invited guests.'"<<endl<<endl
<<"PLEASE USE NUMBERS ONLY IF 'use any key' IS NOT DISPLAYED! "<<endl;
menu(guests); // cout ONLY, will be repeated MANY times from now on.
choice(meny_valg, guests); // get user's choice for the first time. Repeated later on in allmost each segment of code.
int SENT = 0; // USED TO MAKE WHOLE PROGRAM GO AROUND IN A LOOP UNTIL #8 IS CHOOSEN
for (SENT; SENT < 1; SENT) // SEE ONE LINE ABOVE. Used SENTINEL already, therefore *SENT* here instead of *SENTINEL* - FILIP.
{
if (meny_valg == 1)
{
guests_number(guests);
menu(guests);
choice(meny_valg, guests);
}
else if (meny_valg == 2)
{
cards_n_sweets(guests, cards, sweets);
menu(guests);
choice(meny_valg, guests);
}
else if (meny_valg == 3)
{
tables_to_reserve(guests, tables, guests_per_table);
menu(guests);
choice(meny_valg, guests);
}
else if (meny_valg == 4)
{
drinks(guests, coke, water, people_per_coke_case, people_per_water_case);
menu(guests);
choice(meny_valg, guests);
}
else if (meny_valg == 5)
{
card_cost(cards, guests, card_price);
menu(guests);
choice(meny_valg, guests);
}
else if (meny_valg == 6)
{
drink_cost(coke, water, coke_price, water_price, cost_coke, cost_water);
menu(guests);
choice(meny_valg, guests);
}
else if (meny_valg == 7) // cout ONLY function. But it shows what kind of input is missing :D
{
all_info(guests, cards, sweets, tables, coke, water, coke_price, water_price);
menu(guests);
choice(meny_valg, guests);
}
else if (meny_valg == 8)
// TASK 11 - The user will request that the wedding planning assistant stop by selecting menu choice 8. Quit.
//FOR ALL PRACTICAL PURPOSES -> EXITS MAIN LOOP :)
{
cout <<"GOOD BYE!"<<endl;
SENT = 1;
}
else // SOMETHING A'LA SENTINEL - HAD INFINITE LOOP HERE BEFORE... OR IT CAME FROM SOMEWHERE ELSE... ANYWAY, IT WORKS NOW! :D
{
choice(meny_valg, guests);
}
} // END OF 'FOR' LOOP! DON'T DELETE!
}
//---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
// FUNCTIONS
//---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
void menu(int guests) // cout ONLY function -> USE TOGETHER WITH choice(meny_valg, guests)
{
cout<< "Press any key, then 'ENTER' to open the 'MENU' vindow."<<endl;
cin>>empty;
cout<<"------------------------------------------------------------------------------------------------------"<<endl;
cout<<"1. Enter number of invited guests.";
((guests != 0)?(cout<<" (DONE!)"<<endl):(cout<<endl));
cout<<"2. Determine the number of invitation cards and sweets.";
((sweets != 0)?(cout<<" (DONE!)"<<endl):(cout<<endl));
cout<<"3. Determine the number of tables needed.";
((tables != 0)?(cout<<" (DONE!)"<<endl):(cout<<endl));
cout<<"4. Determine drinks order.";
((water != 0)?(cout<<" (DONE!)"<<endl):(cout<<endl));
cout<<"5. Cost of invitation cards.";
((card_price != 0)?(cout<<" (DONE!)"<<endl):(cout<<endl));
cout<<"6. Cost of drinks.";
((water_price != 0)?(cout<<" (DONE!)"<<endl):(cout<<endl));
cout<<"7. Display all information."<<endl;
// NO "DONE" MESSAGE HERE!
cout<<"8. Quit"<<endl;
cout<<"------------------------------------------------------------------------------------------------------"<<endl;
return ;
}
/* TASK 2 - DESCRIPTION
2) Write a function that displays the following menu of choices:
1. Enter number of invited guests.
2. Determine the number of invitation cards and sweets
3. Determine the number of tables needed
4. Determine drinks order
5. Cost of invitation cards
6. Cost of drinks
7. Display all information
8. Quit
*/
//---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
void choice (int &meny_valg, int &guests) // cin function. OBS! Works only with numbers! -> gives the main program an integer between 1 and 8 as user's choice. IF You try to use anything else -> infinite loop :/
{
int SENTINEL = 0;
cin >> meny_valg;
while (guests < 1)
{
for (SENTINEL; SENTINEL < 1; SENTINEL)
{
if ((meny_valg >= 1) and (meny_valg <=8 ))
{
cout << "You choose option "<<meny_valg<<"."<<endl;
SENTINEL = 1;
}
else
{
cout << "INVALID INPUT!"<<endl;
cin >> meny_valg;
}
}
break;
}
}
/* TASK 3 - DESCRIPTION
3) Write a function that reads the user's choice and returns it to the main program.
If the user enters a number which is not a valid choice (other than 1, 2, 3, 4, 5, 6, 7, 8), then ask the user to input a valid choice again.
You are not responsible for any error checking beyond identifying an invalid integer choice.
*/
//---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
void guests_number (int &guests) // gets number of guests, stores # "globally"
{
cout
<<"------------------------------------------------------------------------------------------------------"<<endl
<< "How many guests do You want to invite? \nNumber of invited guests: "<<endl;
cin >> guests;
cout<<"You chose to invite "<< guests <<" guests at your weeding!"<<endl<<endl;
cout
<<"------------------------------------------------------------------------------------------------------"<<endl
<<"You can change number of invited guests later on, without closing the program, but be careful!"<<endl
<<"You will have to start over and input all the information again!"<<endl
<<"------------------------------------------------------------------------------------------------------"<<endl;
return;
}
/* TASK 4 - DESCRIPTION
4) Write a function that prompts the user for the number of invited guests, reads that number and returns it to the main program.
*/
//---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
void cards_n_sweets(int &guests, int &cards, int &sweets) // calculates number of invitation cards and sweets needed and stores the ## "globally"
{
if (guests == 0)
{
cout
<<"------------------------------------------------------------------------------------------------------"<<endl
<< "You have not chosen how many people will be invited! \nGo back to 'MENU' and choose '1', please."<<endl
<<"------------------------------------------------------------------------------------------------------"<<endl;
return;
}
else
{
guests = guests;
cards = guests/2;
sweets = guests*1.2;
cout
<<"------------------------------------------------------------------------------------------------------"<<endl
<<"Number of invitation cards needed for "<<guests<<" guests: "<<cards<<"."<<endl
<<"Number of sweets needed for "<<guests<<" guests: "<<sweets<<"."<<endl
<<"------------------------------------------------------------------------------------------------------"<<endl;
return;
}
}
/* TASK 5 - DESCRIPTION
5) Write a function that computes the number of invitation cards and also sweets needed.
This function will take the number of invited guests as an input parameter (i.e., a parameter that should not be CHANGED by this function).
If the user hasn't entered the number of guests yet, display a message indicating that the user must select menu option 1 before the number of invitation cards computed. Otherwise, the function will compute the number of invitation cards and sweets needed.
These needs to be computed as follows:
- Invitation cards: Assume that children are not allowed to attend the party and each family has 2 members.
Then, the number of invitation cards needed = number of invited guests / 2.
- Number of sweets: You would like to order some extra sweets to make sure that you do not run out of sweets in the wedding,
so number of sweets = number of invited guests * 1.2.
*/
//---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
void tables_to_reserve (int &guests, int &tables, const float &guests_per_table) // calculates number of tables needed for N guests. Needs <cmath> to work! Stores # of tables "globally"
{
if (guests == 0)
{
cout
<<"------------------------------------------------------------------------------------------------------"<<endl
<< "You have not chosen how many people will be invited! \nGo back to 'MENU' and choose '1', please."<<endl
<<"------------------------------------------------------------------------------------------------------"<<endl;
return;
}
else
{
tables = ceil(guests / guests_per_table);
cout
<<"------------------------------------------------------------------------------------------------------"<<endl
<<"You will need: "<<tables<<" tables for "<<guests<<" guests."<<endl
<<"------------------------------------------------------------------------------------------------------"<<endl;
return;
}
}
/* TASK 6 - DESCRIPTION
6) Write a function that computes the number of tables needed.
This function will take the number of invited guests as an input parameter (i.e., a parameter that should not be CHANGED by this function).
If the user hasn't entered the number of guests yet, display a message indicating that the user must select menu option 1 before the number of tables computed.
Otherwise, the function will return the number of tables needed. The number of tables needed should be computed as follows:
- Assume that the capacity of each table is for 6 people.
Then, the number of tables needed = number of invited guests / 6.
If the number of guests does not divide evenly by 6 then you need to allocate extra table.
For example, you would reserve 8 tables for 44 guests.
*/
//---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
void drinks (int &guests, int &coke, int &water, const float &people_per_coke_case, const float &people_per_water_case) // calculates number of drinks needed. Again, overvrites ## globally
{
if (guests == 0)
{
cout
<<"------------------------------------------------------------------------------------------------------"<<endl
<<"You have not chosen how many people will be invited! \nGo back to 'MENU' and choose '1', please."<<endl
<<"------------------------------------------------------------------------------------------------------"<<endl;
return;
}
else
{
water = ceil(guests / people_per_water_case);
coke = floor(guests / people_per_coke_case);
cout
<<"------------------------------------------------------------------------------------------------------"<<endl
<<"You will need: "<<coke<<" boxes of coke for "<<guests<<" guests."<<endl
<<"You will need: "<<water<<" boxes of water for "<<guests<<" guests."<<endl
<<"------------------------------------------------------------------------------------------------------"<<endl;
}
}
/* TASK 7 - DESCRIPTION
7) Write a function that computes the coke and water order.
This function will take the number of invited guests as an input parameter (i.e., a parameter that should not be CHANGED by this function).
If the user hasn't entered the number of guests yet, display a message indicating that the user must select menu option 1 before the beverage order can be computed.
Otherwise, the function will compute the number coke cases and water cases. These numbers should be computed as follows:
- You should assume that one case of Coke will serve 6 guests.
Again, use a CONSTANT to represent people_per_coke_case (of Coke), because you might need to change this later!
The Wedding Planner Assistant assumes that people who like Coke will happily switch to water if you run out of Coke.
Therefore, if the number of people drinking Coke does not divide evenly by people_per_case, don't order the extra case.
For example, you would only order 2 cases of Coke if you had 13 to 17 guests drinking Coke.
- You should assume that one case of water will serve 2 guests. Again, use a CONSTANT to represent people_per_water_case, because you might need to change this later!
The wedding planner will be happy to order extra water so this time when you need round the number up.
For example, for 13 people, you need to order 7 cases of water.
*/
//---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
void card_cost (int &cards,int &guests, int &card_price) // Same as the others ;)
{
if ((guests == 0) || (cards == 0))
{
if ((guests == 0) && ((cards == 0)))
{
cout
<<"------------------------------------------------------------------------------------------------------"<<endl
<< "You have not chosen how many people will be invited or how many invitation cards You will need! \nGo back to 'MENU', please."<<endl
<<"------------------------------------------------------------------------------------------------------"<<endl;
return;
}
else if ((guests == 0))
{
cout
<<"------------------------------------------------------------------------------------------------------"<<endl
<< "You have not chosen how many people will be invited! \nGo back to 'MENU', please."<<endl
<<"------------------------------------------------------------------------------------------------------"<<endl;
return;
}
else
{
cout
<<"------------------------------------------------------------------------------------------------------"<<endl
<< "You have not chosen how many invitation cards You will need! \nGo back to 'MENU', please."<<endl
<<"------------------------------------------------------------------------------------------------------"<<endl;
return;
}
}
else
{
card_price = cards*200;
cout
<<"------------------------------------------------------------------------------------------------------"<<endl
<<cards<<" invitation cards for "<<guests<<" guests will cost: "<<card_price<<" NOK."<<endl
<<"------------------------------------------------------------------------------------------------------"<<endl;
return;
}
}
/* TASK 8 - DESCRIPTION
8) Write a function that computes the cost of invitation cards.
This function will take the number of invitation cards needed an input parameter and compute and return the total cost of the cards.
If the user hasn't entered the number of guests yet, display a message indicating that the user must select menu option 1 then menu
option 2 in order to get the cost of invitation cards.
Assume that each invitation card costs 200NOK.
*/
//---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
void drink_cost(int &coke, int &water, int &coke_price, int &water_price, const float &cost_coke, const float &cost_water) // Same as the others ;)
{
if ((guests == 0) || ((coke == 0) || (water == 0))) // "water = 0" CONDITION IS MAYBE USELESS HERE ?
{
cout
<<"------------------------------------------------------------------------------------------------------"<<endl
<< "You have not chosen how many people will be invited or how many cases of each drink You will need! \nGo back to 'MENU', please."<<endl
<<"------------------------------------------------------------------------------------------------------"<<endl;
return;
}
else
{
coke_price = coke * cost_coke;
water_price = water * cost_water;
cout
<<"------------------------------------------------------------------------------------------------------"<<endl
<<"Cost of coke for the wedding will be: "<< coke_price <<" NOK."<<endl
<<"Cost of water for the wedding will be: "<< water_price <<" NOK."<<endl
<<"Total cost of drinks will be: "<<coke_price + water_price<<" NOK."<<endl
<<"------------------------------------------------------------------------------------------------------"<<endl;
return;
}
}
/* TASK 9 - DESCRIPTION
9) Write a function that computes the cost of drinks.
Your program needs to maintain two constant values, one for the cost of one case of coke and one for the cost of one case of water
(cost_water and cost_coke).
This function needs to calculate the cost of water and coke separately.
Please note that this function needs to get the number of cases of cokes and cases of water to be ordered as input.
If the user hasn't entered the number of guests yet, display a message indicating that the user must select menu option 1
then menu option 4 in order to get the cost of drinks.
Assume that 1 case of coke = 30 NOK and 1 case of water = 20 NOK.
*/
//---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
void all_info (int &guests, int &cards, int &sweets, int &tables, int &coke, int &water, int &coke_price, int &water_price) // cout ONLY
{
if (guests == 0)
{
cout
<<"------------------------------------------------------------------------------------------------------"<<endl
<< "You have not chosen how many people will be invited! \nGo back to 'MENU' and choose '1', please."<<endl
<<"------------------------------------------------------------------------------------------------------"<<endl;
return;
}
else
{
cout <<"------------------------------------------------------------------------------------------------------"<<endl;
cout<<"Number of invited guests: "<<guests<<"."<<endl; // GUESTS
((tables == 0)? // TABLES
(cout<<"You haven't calculated number of tables needed yet!"<<endl):
(cout<<"Numer of tables needed "<<tables<<"."<<endl));
cout <<"------------------------------------------------------------------------------------------------------"<<endl;
((cards == 0 || card_price == 0)? // CARDS
(cout<<"You haven't calculated number of invitation cards needed or their total cost yet!"<<endl):
(cout<<"Numer of cards needed "<<cards<<"."<<endl<<"Total cost of invitation cards: "<<card_price<<" NOK."<<endl));
((sweets == 0)? // SWEETS
(cout<<"You haven't calculated number of sweets needed yet!"<<endl):
(cout<<"Numer of sweets needed "<<sweets<<"."<<endl));
cout <<"------------------------------------------------------------------------------------------------------"<<endl;
((coke == 0 || coke_price == 0)? // DRINKS
(cout<<"You haven't calculated number of cases of coke needed yet!"<<endl):
(cout<<"Numer of cases of coke needed "<<coke<<"."<<endl<<"Total cost of coke for the weeding: "<<coke_price<<" NOK."<<endl));
((water == 0 || water_price == 0)?
(cout<<"You haven't calculated number of cases of water needed yet!"<<endl):
(cout<<"Numer of cases of water needed "<<water<<"."<<endl<<"Total cost of water for the weeding: "<<water_price<<" NOK."<<endl));
(((water_price + coke_price) == 0)? // included this one to hide "cost of drinks" if it's 0 NOK
(cout<<endl):
(cout<<"Total cost of drinks for the wedding: "<<coke_price + water_price <<"."<<endl));
cout <<"------------------------------------------------------------------------------------------------------"<<endl;
(((card_price+coke_price+water_price) == 0)? // TOTAL COST FOR THE WEDDING
(cout<<"You haven't calculated any expenses yet!"<<endl):
(cout<<"Total cost for the weeding so far: "<<card_price+coke_price+water_price<<" NOK."<<endl));
cout <<"------------------------------------------------------------------------------------------------------"<<endl;
}
}
/* TASK 10 - DESCRIPTION
10) Write a function that takes all the information (number of guests, number of invitation cards, number of tables, cases of Coke, cases of water) as parameters and displays all this information on the screen for the user.
*/