▪ Youoperateseveralhotdogstandsdistributedthroughouttown.Definea class named HotDogStand that has a member variable for the hot dog stand's ID number and a 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 so that you can track the total number of hot dogs sold by the stand.
▪ Addanotherfunctionthatreturnsthenumberofhotdogssold.
▪ Finally, add a static variable that tracks the total number of hot dogs sold by all hot dog stands and 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.
I Want to make hotdog stand without #include <cstdlib>
Please help me...
The result:
ex)
Stand count(3~10 input) : input number -> 5
ID:0
ID:0
ID:3
ID:2
ID:0
ID:3
ID:4
ID:3
ID:2
ID:2
Stand 0 sold 3
Stand 1 sold 0
Stand 2 sold 3
Stand 3 sold 3
Stand 4 sold 1
Total sold = 10
What I have tried:
<main.cpp>
#include <iostream>
#include "Hotdog.h"
using namespace std;
int main()
{
int count;
HotDogStand* sList;
cout << "Stand count(3~10개) : ";
cin >> count;
sList = new HotDogStand[count];
for (int i = 0; i < count; i++) {
sList[i].SetID(i);
}
char input;
while (true)
{
cout << "ID : ";
cin >> input;
if (input == 'q' || input == 'Q') {
break;
}
for (int i = 1; i < count; i++) {
HotDogStand(i, 0);
}
}
for (int i; i < count; i++) {
sList[i].JustSold();
cout << "stand" << sList[i].GetID() << "sold" << sList[i].GetNumSold() << endl;
}
cout << "Total sold = " << sList[].GetTotalSold() << endl;
return 0;
}
<hotdog.h>
#ifndef HOTDOG.H
#define HOTDOG.H
class HotDogStand
{
public:
HotDogStand();
HotDogStand(int newID, int newNnumSold);
int GetID();
void SetID(int newID);
void JustSold();
int GetNumSold();
static int GetTotalSold();
private:
static int totalSold;
int numSold;
int ID;
};
#endif // !HOTDOG.H
<hotdog.cpp>
#include <iostream>
#include "Hotdog.h"
using namespace std;
int HotDogStand::totalSold = 0;
HotDogStand::HotDogStand()
{
numSold = 0;
ID = 0;
totalSold++;
}
HotDogStand::HotDogStand(int newID, int newNnumSold)
{
numSold = newNnumSold;
ID = newID;
totalSold++;
}
int HotDogStand::GetID()
{
return ID;
}
void HotDogStand::SetID(int newID)
{
ID = newID;
}
void HotDogStand::JustSold()
{
numSold++;
}
int HotDogStand::GetNumSold()
{
return numSold;
}
int HotDogStand::GetTotalSold()
{
return totalSold;
}