Question: C++ Problem 1 Write a program that displays a menu and prompts the user for the option in creating stacks of doubles, chars, strings and
C++ Problem 1
Write a program that displays a menu and prompts the user for the option in creating stacks of
doubles, chars, strings and or circles, and prints the total numbers of all created objects of all classes.
You must include the following header files and implementation files:
*StackOfDoubles.h and StackOfDoubles.cpp
*StackOfChars.h and StackOfChars.cpp
*StackOfStrings.h and StackOfStrings.cpp
*StackOfCircles.h and StackOfCircles.cpp
*Circle.h and Circle.cpp
All classes must include static variable numberOfObjects and static function
getNumberOfObjects(). For all stack classes use an array of 10 elements. You may use the StackOfIntegers class reference
Reference for StackOfIntegers:
StackOfIntegers.h
#ifndef STACK_H
#define STACK_H
class StackOfIntegers
{
public:
StackOfIntegers();
bool isEmpty() const;
int peek() const;
void push(int value);
int pop();
int getSize() const;
private:
int elements[100];
int size;
};
#endif
TestStackOfIntegers.cpp
#include
#include "StackOfIntegers.h"
using namespace std;
int main()
{
StackOfIntegers stack;
for (int i = 0; i < 10; i++)
stack.push(i);
while (!stack.isEmpty())
cout << stack.pop() << " ";
return 0;
;
You must implement the following functions to be called from your main program:
** Please make sure the code matches the output exactly! Thank you.
//Display the menu
Void PrintMenu
Sample output:
=========================================
| Object-Oriented Thinking |
=========================================
| 1 - Create Stack Of Doubles |
| 2 - Create Stack Of Chars |
| 3 - Create Stack Of Strings |
| 4 - Create Stack Of Circles |
| 5 - Summary of ALL stacks |
| other - quit |
=========================================
//Randomly generate double values and push onto the stack, and display a message
that the stack of doubles has been created before return
void CreateStackOfDoubles()
Sample output:
A stack of 6 doubles was created.
Press any key to continue . . .
//Randomly generate char values and push onto the stack, and display a message
that the stack of chars has been created before return
void CreateStackOfChars()
Sample output:
A stack of 9 chars was created.
Press any key to continue . . .
//Randomly generate string values and push onto the stack, and display a message
that the stack of strings has been created before return
void CreateStackOfStrings()
Sample output:
A stack of 5 strings was created.
Press any key to continue . . .
//Randomly generate radius of circles and push onto the stack, and display a message
that the stack of circles has been created before return
void CreateStackOfCircles()
Sample output:
A stack of 8 circles was created.
Press any key to continue . . .
//Display all counts of the created objects/instances of all the classes
void PrintNumberOfAllObjects()
Sample output:
# StackOfDoubles # StackOfChars # StackOfStrings # StackOfCircles
================ ============== ================ ================
2 2 1 1
Press any key to continue . . .
Your main() function will be as follows
int main()
{
srand((unsigned)time(0));
while(true)
{
system("cls");
PrintMenu();
int option;
cin >> option;
cout << endl;
switch (option)
{
case 1 CreateStackOfDoubles(); break;
case 2 CreateStackOfChars(); break;
case 3 CreateStackOfStrings(); break;
case 4 CreateStackOfCircles(); break;
case 5 PrintNumberOfAllObjects(); break;
default: return -1;
}
system("pause");
}
return 0;
}
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
