Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

C++ programming help. The only change you have to make is in current program, wh

ID: 3575208 • Letter: C

Question

C++ programming help.

The only change you have to make is in current program, where it says "your code goes here", do not make any changes to any other files, they are just there to show you. This code should be written for arbitrary data, not specifically for this sequence of data. The only place you need to write a code is marked YOUR CODE GOES HERE.

You have been supplied a file with data in it (data2.txt). The line contains a series of integers. Your program tries to push each integer onto the stack, but if the stack is full, your program should just print the value that would have been one integer too many and terminate. For this purpose, the first item is number 1 and its value is 4. Given the data2.txt file, your program should print:

Stopping before trying to push item 11, whose value is 17.

Your grader may, of couurse replace data2.txt with a file of his own to make sure you haven't "faked out" the code.

INSTRUCTIONS:

CURRENT PROGRAM:

DATA2.TXT FILE:

IStack.cpp :

IStack.h file:

Problem 2. Stack push with safeguards The IStack class used in this problem is the same as used in Problem 1 The data file is different, and your challenge is to write code that tests the stack to make sure it's safe to put something into it You have been supplied a IStack class with the following characteristics: It holds only integers It recognizes only the following functions Stack constructs an empty stack void push (int x) pushes the argument onto the stack void pop pops and discards the top item int top returns a copy of the top item. if this function is called on an empty stack, the program will crash bool empty returns true if the stack is empty bool full returns true if the stack is full that is pushing onto a full stack the program will crash. These functions are sufficient to handle any sequence of data without crashing your program however, only a small stream of data is provided for testing and you need not protect your code against all possible inputs You have been supplied a file with data in it (data 2.txt). The line contains a series of integers Your program tries to push each integer onto the stack, but if the stack is full, your program should just print the value that would have been one integer too many, and terminate. For this purpose, the first item is item number 1 and its value is 4 Given the data2. txt file, your program should print Stopping before trying to push item 11 whose value is 17 Your grader may of course, replace data2.txt with a file of his own, to make sure you haven't "faked out" the code

Explanation / Answer

//put the below code

IStact st;

std::fstream myfile("data.txt", std::ios_base::in); //open the file

int a;
while (myfile >> a && !st.full()) //read the each number into a and check if stack is empty
{
st.push(a); //push to stack if it is not empty...
}

cout<<"numbers were pushed upto :"<<a<<" stack is full"<<endl;

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote