In: Computer Science
Code the following in C++ and make sure to include all three files required at the end.
Hotdogs – The World’s Greatest Cost Effective Wholesome
Nutritious Food
Due to world food supply scarcity and the burgeoning populations of
the world’s countries, your hot stand business is
globalizing to satisfy the world’s desire for a cost effective
wholesome nutritious food source. Market studies have
shown that tens of billions of people are craving for the eponymous
hotdog which will result in a huge number of hotdog
sales from hotdog stands. You need to develop a program that tracks
the activities of all the hotdog stands.
HotDogStandsClass
Define a class named HotDogStandsClass.
This class has the following for private member instance
variables:
• Hotdog stand Identification
Each stand should have a unique identification
• Stand Location
A string that is the address of the stand which includes street,
city and country.
For examples:
12 Deepika Padukone Ci, Bangelore, Karnataka 67089, India
1038 West Nanjing Rd, Westgate Mall, 8th Floor, Shanghai, Shanghai
200041, China
123 Jennifer Dr, UTD Food Court, 2nd Floor, Richardson Texas,
66666, USA
• Cost per hotdog
Cannot be negative, must be 0 or greater.
• Total Hot Dogs Sold Across All Stands
Cannot be negative, must be 0 or greater.
• Hotdogs Inventory Amount
The lowest value the inventory can be is 0. Negative inventory
amounts do not make sense.
• Hotdogs Sold Count
This contains how many hot dogs this stand has sold since the stand
object was created.
The HotDogStandsClass Class must include the following
methods
• A constructor with parameters that sets all the instance
values
• Accessor (Getter) and Setter methods that are required for all
private member instance variables
• hotDogsBuy(n) method
• The method will be invoked each time someone (your main method
test driver) wants to buy some hotdog(s).
• Has a parameter (n) that indicates the requested amount of
hotdogs to be bought
• If the inventory is 0, the method should display a message that
there are no more hotdogs left to be sold.
The method uses the amount of the hot dogs requested to:
• Increase the hog dogs total number sold for all the stands by the
hotDogsBuy(n) parameter amount
It must be accessible to all the HotDogStandsClass objects.
• Increase the tracked hot dogs sold by the appropriate numberfor
each stand
• Decrease the hot dog inventory by the appropriate number
• This method should be intelligent regarding the inventory.
The lowest value the inventory can be is 0. Negative inventory
amounts do not make sense.
If the buy amount is more than the inventory, the class should
state the number of hotdogs in inventory and
state to retry a buy.
If inventory amount is 0, the class should state that it is out of
hotdogs and to try again later.
hopefully before a buy retry a stock inventory will be done.
• a stockInventory(n) method that is used to add inventory
Has a parameter (n) that indicates the requested number of hotdogs
to be stocked
main()
This main program has the following:
The main program must create and use at least three hot dog stand
objects of the HotDogStandsClass.
Write a main() test driver, a concept that is demonstrated in the
book, to test the HotDogStands program. The main
test driver must test all paths of the logic flow of the program
and conditions of the program to validate program
correctness.
Do not use any interactive prompts, unit test the HotdogStandsClass
by coding in test scenarios in the main program
which will act as a test driver.
The main unit test driver must display information that indicates
what is being tested with the test values being used
and after perfoming the hotdog stand operatiomn will display the
state of the HotDogStandClass.
To accomplish this display of the class state, you should develop
an overloaded stream output operator that displays a
well formatted string of object state (contents) that is well
suited to being displayed using cout.
The output must be well formatted and readable to the user running
the program. The main test unit driver does not
have to output if the test passed or failed, just what is being
tested in the object of the class for each test and the class
state using the overloaded stream output operator (<<).
Use the following code to pause the screen:
#include <stdio.h>
:
cout << "Press the enter key to continue..." << endl;
cin.ignore(); cin.get();
There is a system dependency that may require hitting the key twice
for correct behavior.
Example:
HotDogStandClass hotdogstand1;
cout << “ buy 20 hot dogs “ << endl;
hotdogstand1.buy(20);
cout << hotdogstand1 << endl;
cout << “Press enter to continue”; cin.ignore();
cin.get();
You will lose points if the main function does not do comprehensive
path testing of the program.
Before the program ends, the main part should display the total
amount sold and display the final states of each of the
objects of the HotDogStandsClass.
The program must hold the screen for each unit test so that the
class information can read.
Your program must use the class specification and class
implementation design paradigms.
Therefore, you will have multiple files to upload for submittal to
the eLearning system:
main.cpp
HotDogStandsClass.h
HotDogStandsClass.cpp
Ans)
//HotDogStandsClass.h
#ifndef HOTDOGSTANDSCLASS_H
#define HOTDOGSTANDSCLASS_H
#include <iostream>
#include <string>
using namespace std;
// Defines class HotDogStand
class HotDogStand
{
public:
// Prototype of member functions
HotDogStand();
HotDogStand(string, string, string, string, int);
void setID(string);
void setLication(string, string, string);
void setInventoryAmount(int);
string getID() const;
string getLication() const;
int getInventoryAmount() const;
int getTotalSold() const;
int getSoldCount() const;
void hotDogsBuy(int);
void stockInventory(int);
friend ostream & operator <<(ostream &, HotDogStand &);
private:
// Data member to store hot dog information
string ID;
string street, city, country;
int totalSold;
static int inventoryAmount;
int soldCount;
};
int HotDogStand::inventoryAmount = 0;
#endif // ! HOTDOGSTANDSCLASS_H
-------------------------------------------------------------------------------------------------
//HotDogStandsClass.cpp
#include "HotDogStandsClass.h"
using namespace std;
// Default constructor to assign default values to data member
HotDogStand::HotDogStand()
{
ID = street = city = country = "";
totalSold = inventoryAmount = soldCount = 0;
}// End of default constructor
// Parameterized constructor to assign parameter values to data member
HotDogStand::HotDogStand(string id, string st, string ci, string co, int amt)
{
ID = id;
street = st;
city = ci;
country = co;
// Calls the function to validate and assigns the parameter amount
setInventoryAmount(amt);
totalSold = soldCount = 0;
}// End of parameterized constructor
// Function to set id
void HotDogStand::setID(string id)
{
ID = id;
}// End of function
// Function to set location
void HotDogStand::setLication(string st, string ci, string co)
{
street = st;
city = ci;
country = co;
}// End of function
// Function to set inventory amount
void HotDogStand::setInventoryAmount(int amt)
{
// Checks if amount is less then 0 then set it to 0 after displaying error message
if(amt < 0)
{
cout<<"\n Invalid amount.";
inventoryAmount = 0;
}// End of if condition
// Otherwise assigns the parameter amount
else
inventoryAmount = amt;
}// End of function
// Function to return id
string HotDogStand::getID() const
{
return ID;
}// End of function
// Function to return location0
string HotDogStand::getLication() const
{
return street + ", " + city + ", " + country;
}// End of function
// Function to return inventory amount
int HotDogStand::getInventoryAmount() const
{
return inventoryAmount;
}// End of function
// Function to return total sold
int HotDogStand::getTotalSold() const
{
return totalSold;
}// End of function
// Function to return sold count
int HotDogStand::getSoldCount() const
{
return soldCount;
}// End of function
// Function to bub dog
void HotDogStand::hotDogsBuy(int n)
{
// Checks if inventory amount is 0 then display error message
if(inventoryAmount == 0)
cout<<"\n Insufficient inventory amount to purchase.";
// Otherwise checks if inventory amount is less than the parameter amount
// display error message
else if(inventoryAmount < n)
cout<<"\n Insufficient inventory amount "<<inventoryAmount
<<"\n Your request is more than the available. Try later.";
// Otherwise update data
else
{
inventoryAmount -= n;
totalSold += n;
soldCount++;
}// End of else
}// End of function
// Function to increase the inventory amount by the parameter amount
void HotDogStand::stockInventory(int n)
{
inventoryAmount += n;
}// End of function
// Overrides << operator to return hot dog information
ostream & operator <<(ostream &out, HotDogStand &hd)
{
out<<"\n\n ID: "<<hd.getID()<<"\n Location: "<<hd.getLication()
<<"\n Inventory Amount: "<<hd.getInventoryAmount()
<<"\n Total Sold: "<<hd.getTotalSold()
<<"\n Sold Count: "<<hd.getSoldCount();
return out;
}// End of function
// main function definition
int main()
{
// Creates two object of class HotDogStand using parameterized constructor
HotDogStand *hd1 = new HotDogStand("111", "12 Deepika", "Bangalore", "India", 900);
HotDogStand *hd2 = new HotDogStand("222", "11 Rukmini", "Mumbai", "India", 400);
// Calls the function to test
cout<<"\n Initial Status for HD1\n";
cout<<*hd1;
cout<<"\n After buying 50 for HD1 status\n";
hd1->stockInventory(50);
cout<<*hd1;
cout<<"\n After selling 10 for HD1 status\n";
hd1->hotDogsBuy(10);
cout<<*hd1;
cout<<"\n After selling 90 for HD1 status\n";
hd1->hotDogsBuy(90);
cout<<*hd1;
cout<<"\n Initial Status for HD2\n";
cout<<*hd2;
cout<<"\n After buying 50 for HD2 status\n";
hd2->stockInventory(50);
cout<<*hd2;
cout<<"\n After selling 10 for HD2 status\n";
hd2->hotDogsBuy(10);
cout<<*hd2;
cout<<"\n After selling 90 for HD2 status\n";
hd2->hotDogsBuy(90);
cout<<*hd2;
return 0;
}
Output
Initial Status for HD1
ID: 111
Location: 12 Deepika, Bangalore, India
Inventory Amount: 400
Total Sold: 0
Sold Count: 0
After buying 50 for HD1 status
ID: 111
Location: 12 Deepika, Bangalore, India
Inventory Amount: 450
Total Sold: 0
Sold Count: 0
After selling 10 for HD1 status
ID: 111
Location: 12 Deepika, Bangalore, India
Inventory Amount: 440
Total Sold: 10
Sold Count: 1
After selling 90 for HD1 status
ID: 111
Location: 12 Deepika, Bangalore, India
Inventory Amount: 350
Total Sold: 100
Sold Count: 2
Initial Status for HD2
ID: 222
Location: 11 Rukmini, Mumbai, India
Inventory Amount: 350
Total Sold: 0
Sold Count: 0
After buying 50 for HD2 status
ID: 222
Location: 11 Rukmini, Mumbai, India
Inventory Amount: 400
Total Sold: 0
Sold Count: 0
After selling 10 for HD2 status
ID: 222
Location: 11 Rukmini, Mumbai, India
Inventory Amount: 390
Total Sold: 10
Sold Count: 1
After selling 90 for HD2 status
ID: 222
Location: 11 Rukmini, Mumbai, India
Inventory Amount: 300
Total Sold: 100
Sold Count: 2
*********************-end **************
if your satisfy above answer please give positive rating or?
if any doubts below comment here
please don't dislike or downvote
Thankyou!