I'm trying to see if there is a better way to go about getting the number of carts that the user inputs, instead of mandating that they have exactly three. My assignment calls for the following:
"You operate several hot dog stands distributed throughout town. Define a class named HotDogStand that has a member variable for the hot dog stand’s ID number and member variable for how many hot dogs the stand sold that day. Create a constructor that allows a user of the class to initialize both values. Also, create a function named JustSold that increments the number of hot dogs the stand has sold by one. This function will be invoked each time the stand sells a hot dog so that you can track the total number of hot dogs sold by the stand. Add another function that returns the number of hot dogs sold. Finally, add a static variable that tracks the total number of hot dogs sold by all hot dog stands an a static function that returns the value in this variable. Write a main function to test your class with at least three hot dog stands that each sell a variety of hot dogs."
My problem lies in the fact that the teacher might try to say that I own more than three stands, so then what happens!?!. I'm thinking that there might be a loop or array that would be a little better.
#include <iostream>
using namespace std;
class HotDogStand
{
public:
void JustSold();
int CartOne;
int CartTwo;
int CartThree;
int IdNumber;
int SalesToday1;
int SalesToday2;
int SalesToday3;
int TotalSales;
int IncrementalSale;
static int HotDogCartSales;
};
int main()
{
HotDogStand CartSales;
CartSales.SalesToday1 = 0;
CartSales.SalesToday2 = 0;
CartSales.SalesToday3 = 0;
CartSales.TotalSales = 0;
while (true)
{
cout << "Please Enter the Hot Dog Cart ID Numbers (Up to Three): " << endl;
cin >> CartSales.CartOne >> CartSales.CartTwo >> CartSales.CartThree;
cout << endl;
cout << "How Many Hot Dogs Has Cart ID #: " << CartSales.CartOne << " Sold ?" << endl;
cin >> CartSales.SalesToday1;
cout << endl;
cout << "How Many Hot Dogs Has Cart ID #: " << CartSales.CartTwo << " Sold ?" << endl;
cin >> CartSales.SalesToday2;
cout << endl;
cout << "How Many Hot Dogs Has Cart ID #: " << CartSales.CartThree << " Sold ?" << endl;
cin >> CartSales.SalesToday3;
cout << endl;
CartSales.JustSold();
CartSales.IncrementalSales();
}
}
void HotDogStand::JustSold()
{
TotalSales += SalesToday1;
TotalSales += SalesToday2;
TotalSales += SalesToday3;
cout << "Total Number of Hot Dogs Sold From All Stands Is: " << TotalSales << endl;
cout << endl;
}