ou are required to create a class that represents the beverages sold in a coffee shop. Each beverage can produce multiple cups at a specific price each. The name of the beverage (product), number of cups that can be produced at a given day and the price per cup are attributes of the CoffeeShop class and should be represented as parallel arrays in the class with the size of 5. You will receive a CSV file called “List.csv” to populate the class’ data members. The turnover data member must contain the total amount made per day. Now follow the UML class diagram and the description below and complete the CoffeeShop class. CoffeeShop - products: string[] - quantity: int[] - price: int[] - shopName: string - turnover: double + CoffeeShop(string) + loadProducts(string): void + buy(double,string,int): bool + display(): void - search(string): int Attribute/Method Description Products quantity price Data members. shopName turnover There are three parallel arrays. The products array stores the names of the different beverages that are sold in the coffee shop. The quantity array stores the number cups that can be made. The price array stores the price per unit. ShopName which stores the name of the shop and the turnover which must store the total amount made at the end of the day. CoffeeShop(string) The constructor must receive the name of the shop as parameter and assign it to the shop name. The method must also assign default values to the parallel arrays. loadProducts(string) This method must receive a file name as parameter and must populate the parallel data members’ arrays with information read from the file. A record in the file will always be in the format of: Products,quantity,price The first is the name of the product. The second is the quantity available. The third is the price per unit. NB: Use the getline() function when reading from the file search(string) This private method is used to find the availability of a particular product. It will receive the name of the product as a parameter and will then find and return the index of that product. If the product was not found, then the method must return -1. buy(double,string,int) The method receives the amount tendered by the customer, the name of the product, and the quantity as parameters. The method must first check the availability of the products, the quantity requested by the customer, and also the amount tendered by the customer if it is sufficient. If the amount tendered is enough to buy and the product is available in the amount tendered, an item is purchased by decrementing the stock quantity at that index and adding the total price calculated from that index to the turnover. A Boolean true is returned if the purchase was successful. If the purchase was not successful a Boolean false is returned. display() This method must display the data in all arrays Create the following front-end function in a file called RunQ2.cpp. Please remember that you may NOT duplicate any source code whose functionality already exists. In the main() function you must: Declare objects of type CoffeeShop that will be used throughout the program and any variables needed. Create the following menu that will repeat till the user chooses option 4. Coffee Shop Menu: ==================================== 1. Load Products 2. Buy a product 3. Display all product info 4. Exit………….. Menu Option Description 1 Load Products Read from the file and populate the arrays. Confirm if the data was loaded successful. 2 Buy Prompt the user for the name of the product, quantity and the amount tendered. If the transaction was successful display “Transaction successful”, otherwise display “Transaction unsuccessful”. 3 Display This option must display all the data in the arrays. The following data must be displayed: product quantity price 4 Terminate the program
OOPs
In today's technology-driven world, computer programming skills are in high demand. The object-oriented programming (OOP) approach is very much useful while designing and maintaining software programs. Object-oriented programming (OOP) is a basic programming paradigm that almost every developer has used at some stage in their career.
Constructor
The easiest way to think of a constructor in object-oriented programming (OOP) languages is:
You are required to create a class that represents the beverages sold in a coffee shop. Each
beverage can produce multiple cups at a specific price each. The name of the beverage
(product), number of cups that can be produced at a given day and the price per cup are
attributes of the CoffeeShop class and should be represented as parallel arrays in the class
with the size of 5. You will receive a CSV file called “List.csv” to populate the class’ data
members. The turnover data member must contain the total amount made per day.
Now follow the UML class diagram and the description below and complete the CoffeeShop
class.
CoffeeShop
- products: string[]
- quantity: int[]
- price: int[]
- shopName: string
- turnover: double
+ CoffeeShop(string)
+ loadProducts(string): void
+ buy(double,string,int): bool
+ display(): void
- search(string): int
Attribute/Method Description
Products
quantity
price
Data members.
shopName
turnover
There are three parallel arrays. The products array
stores the names of the different beverages that are
sold in the coffee shop.
The quantity array stores the number cups that can be
made.
The price array stores the price per unit. ShopName
which stores the name of the shop and the turnover
which must store the total amount made at the end of
the day.
CoffeeShop(string) The constructor must receive the name of the shop as
parameter and assign it to the shop name. The method
must also assign default values to the parallel arrays.
loadProducts(string) This method must receive a file name as parameter
and must populate the parallel data members’ arrays
with information read from the file. A record in the file
will always be in the format of:
Products,quantity,price
The first is the name of the product.
The second is the quantity available.
The third is the price per unit.
NB: Use the getline() function when reading from the
file
search(string) This private method is used to find the availability of a
particular product. It will receive the name of the
product as a parameter and will then find and return
the index of that product. If the product was not
found, then the method must return -1.
buy(double,string,int) The method receives the amount tendered by the
customer, the name of the product, and the quantity
as parameters. The method must first check the
availability of the products, the quantity requested by
the customer, and also the amount tendered by the
customer if it is sufficient.
If the amount tendered is enough to buy and the
product is available in the amount tendered, an item is
purchased by decrementing the stock quantity at that
index and adding the total price calculated from that
index to the turnover. A Boolean true is returned if the
purchase was successful. If the purchase was not
successful a Boolean false is returned.
display() This method must display the data in all arrays
Create the following front-end function in a file called RunQ2.cpp. Please remember that you
may NOT duplicate any source code whose functionality already exists.
In the main() function you must:
Declare objects of type CoffeeShop that will be used throughout the program
and any variables needed.
Create the following menu that will repeat till the user chooses option 4.
Coffee Shop Menu:
====================================
1. Load Products
2. Buy a product
3. Display all product info
4. Exit…………..
Menu Option Description
1 Load Products
Read from the file and populate the arrays. Confirm if the data was
loaded successful.
2 Buy
Prompt the user for the name of the product, quantity and the
amount tendered. If the transaction was successful display
“Transaction successful”, otherwise display “Transaction
unsuccessful”.
3 Display
This option must display all the data in the arrays. The following
data must be displayed:
product
quantity
price
4 Terminate the program
Trending now
This is a popular solution!
Step by step
Solved in 5 steps with 4 images