Question: C++ ADT int_Bag Part I Write a program that uses random function to randomly generate 6 integers between 0 and 99 with 0 and 99

C++ ADT int_Bag

Part I

Write a program that uses random function to randomly generate 6 integers between 0 and 99 with 0 and 99 included. Save them in a Bag.

Ask a user to make a guess. If the users guess is one of the numbers in the Bag, then give user 10 points and remove the number from the Bag.

Allow the user to make 10 attempts. Each time give user 10 points if the number user guess is in the Bag.

If the Bag is getting emptied before the user reach 10 attempts, then give user an additional 200 points and terminate the program (Game is over!).

If the Bag is not empty after the user use up all 10 attempts, then display the users score and terminate the program (Game is over!).

PartII

write a program that ask a user to enter an interger and display yes if the number is symetric otherwise display no

source.ccp

#include #include"Stack.h" using namespace std; int main() { Stack myStack; for (int k = 5; k < 15; k++) { myStack.push(k); } myStack.display(); cout << "the item on the top of the stack is" << myStack.peek() << endl; myStack.pop(); myStack.display(); myStack.clean(); myStack.display(); system("pause"); return 0; }

header file

#ifndef _STACK #define _STACK

#include using namespace std; template class Stack { private: ItemType items[100]; int top; //index of the item that is on the top of the stack int getCurrentTop() { return top; } void setCurrentTop(int s) { top = s; } public: Stack(); bool isEmpty(); bool push(ItemType newItem); bool pop(); ItemType peek(); void clean(); bool display(); }; template Stack::Stack() { setCurrentTop(-1); } template bool Stack::isEmpty() { return (top == -1); } template bool Stack::push(ItemType newItem) { if (top == 99) { cout << "Push failed, the Stack is full! "; return false; } else { items[top + 1] = newItem; top++; return true; } } template bool Stack::pop() { if (isEmpty()) { cout << "Pop failed, the stack is empty "; return false; } else { top--; return true; } } template ItemType Stack::peek() { if (isEmpty()) { cout << "The stack is empty, program aborted! "; exit(0); } else { return items[top]; } } template void Stack::clean() { setCurrentTop(-1); } template bool Stack::display() { if (isEmpty()) { cout << "It is an empty stack! "; return false; } else { cout << "The stack contains following items: "; for (int i = 0; i <= top; i++) cout << items[i] << endl; return true; } } #endif

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!