Question
Please use the following code to write a another continuing program from the description given below in the pictures. please follow all instructions. Code: #include
Please use the following code to write a another continuing program from the description given below in the pictures. please follow all instructions. Code: #include
Description: In class, we've discussed the array implementation of the stack ADT. In this homework, you will write a program to test three stacks against each other. Two of the stacks are instances of farmingdaleni Stack. The third stack will be of type mystery: 1 stack() (contained in the downloads folder). All three stacks must hold std:strings. Note that you must convert the stack adt to hold std::strings and make it unlimited in capacity (as we'll do in class). In HW 01 you wrote a program that produces a file. We will use the file as input for the program we write in this assignment. Note that for this assignment we're ignoring lines that are "C". "S", or "E'. We will deal with these in a future assignment--you should just ignore these lines for now For example, the file may be like this (the line numbers are not in the file. I've added them for this explanation) 00 ON A-3245 A 2344 A 344322 A-34 1,000 1,001 D P The program, testStack, should operate as follows: It should request a filename from the user. This will be the name of a file which was created by randomStream from your Week 2 project part (again, the entire filename do not add .txt) It create two instances of the farmingdales estack ADT holding std::strings and one of the mystery::stack. The ctor for mystery::stack is parameterized. Please use 0 as the parameter for this exercise. The project containing mystery::stack is attached to this assignment in Blackboard. It should read each line of the file, and process the file as if it was a set of instructions: If the letter is "A", it should get the number from the remainder of the line as a string, and push() that string into all three of the stacks It must check the return value of the push() operations. If any of the stacks return FAILURE because they are full, all three must return that same return code. If only one or two of the stacks return FAILURE, that is an error, and it should terminate and print the line number from the instruction file If the letter is a "P", it should peek ) the stack. It must check the return value of the peek) operations. If any of the stacks return FAILURE because they are empty, all three must return that same return code. If only one or two of the stacks return PAILURE, that is an error, and it should terminate and print the line number from the instruction file. If the peek did not return FAILURE, your code should make sure all three peek() "retumed the same top string element (we use "return" loosely here to include data returned to the caller as a reference parameter) If the letter is a "D", it should check the top of the stack: It should pop() all three stacks. It must check the return value of the pop() operations. If any of the stacks retum FAILURE because they are empty, all three must return that same return code. If only one or two of the stacks return FAILURE, that is an error, and it should terminate and print the line number from the instruction file. If the stacks were not empty, it should check the element removed from each stack was the same If the tests fail (because they don't all fill up or empty at the same time, or they return different elements, the program must indicate which line of the input file at which the first error was found For example, using the sample file above On line 1 The system reads "P". It will try to peek ( all three stacks. Since they are empty they will all return FAILURE. This is fine since all three retum FAILURE On line 2 The system reads "D". It will try to pop all three stacks. Since they are empty. they will all return FAILURE This is fine since all three return FAILURE On line 3 The system reads "A-3245. It will try to push() -3245 into all three stacks. This will likely succeed, and if so all three must return SUCCESS On line 4 The system reads "A 2344". It will try to push() 2344 into all three stacks Depending on the size of the stacks, this may return SUCCESS or FAILURE. Whatever it returns, all three stacks must return the same return statusCode On line 5 The system reads "D" It will try to pop() all three stacks. It will likely return SUCCESS, but as long as all three stacks return the same statusCode, it's not an error. Depending on the results of steps (3) and (4), the reference parameter may end up as either-3245 or as 2344 The program doesn't know, but does know that if the three pop()s returned SUCCESS, it should check all three reference parameters to ensure they have the same value. On line 6 The system reads "A 344322". It will try to push() 344322 into all three stacks Depending on the size of the stacks, this may return SUCCESS or FAILURE. Whatever it returns, all three stacks must return the same statusCode On line 7 The system reads "E". It will check if all three stacks are empty using the isEmpty() function. Whatever is returned from isEmpty(), all three stacks must have returned the same thing On line 8 The system reads "A 34". It will try to push() -34 into all three stacks Depending on the size of the stacks, this may return SUCCESS or FAILURE. Whatever it returns, all three stacks must return the same statusCode on line 1000 Some time later The system reads "D'. It will try to popl) all three stacks. Depending on what happens in operations 8.999 and the capacity. It may return SUCCESS or FAILURE. If some of the stacks return SUCCESS and others return FAILURE this is an error. If the stacks return On line 1001 SUCCESS. then it should check all three reference parameters to ensure they have the same value The system reads "P" it will try to peek) all three stacks. Depending on what happens in operations 8.999 and the capacity, it may retum SUCCESS or FAILURE. If some of the stacks return SUCCESS and others return FAILURE this is an error the stacks return SUCCESS, then should check all three reference parameters to ensure they have the same value. Please make sure your program is well organized and well commented, and that you close the file before you ext. Your program must have a function int teststream(std::string fileName) that actually tests the stacks and returns a line number in case of error) or Zoro in the case the tests are passed. It should terminate on the first error since t's unlikely the stacks wil ever sync up again after they are different. The line number it returns should be the instruction line number in the file produced by randomStream[). The farmingdalen stack class code is attached to this assignment and also available in the "Downloads" folder IMPORTANT: This code (or a variation of it) will be used in many future homeworks. If you do not gett right, you will continue to lose significant points in each homework submission until you submit a homework with fixed code. You cannot get credit for pror work, so all those lost points are gone forever. If you don't understand something about this assignment, please see me in office hours for assistance The mystery stack code is already contained in a project. You may either slot your project into this [replacing the test code in main()) or use the brary and header in your project your choice. If you want a 64 bit version, use the header from that project the BCS370_mysteryaltak_lib_64.lib file Description: In class, we've discussed the array implementation of the stack ADT. In this homework, you will write a program to test three stacks against each other. Two of the stacks are instances of farmingdaleni Stack. The third stack will be of type mystery: 1 stack() (contained in the downloads folder). All three stacks must hold std:strings. Note that you must convert the stack adt to hold std::strings and make it unlimited in capacity (as we'll do in class). In HW 01 you wrote a program that produces a file. We will use the file as input for the program we write in this assignment. Note that for this assignment we're ignoring lines that are "C". "S", or "E'. We will deal with these in a future assignment--you should just ignore these lines for now For example, the file may be like this (the line numbers are not in the file. I've added them for this explanation) 00 ON A-3245 A 2344 A 344322 A-34 1,000 1,001 D P The program, testStack, should operate as follows: It should request a filename from the user. This will be the name of a file which was created by randomStream from your Week 2 project part (again, the entire filename do not add .txt) It create two instances of the farmingdales estack ADT holding std::strings and one of the mystery::stack. The ctor for mystery::stack is parameterized. Please use 0 as the parameter for this exercise. The project containing mystery::stack is attached to this assignment in Blackboard. It should read each line of the file, and process the file as if it was a set of instructions: If the letter is "A", it should get the number from the remainder of the line as a string, and push() that string into all three of the stacks It must check the return value of the push() operations. If any of the stacks return FAILURE because they are full, all three must return that same return code. If only one or two of the stacks return FAILURE, that is an error, and it should terminate and print the line number from the instruction file If the letter is a "P", it should peek ) the stack. It must check the return value of the peek) operations. If any of the stacks return FAILURE because they are empty, all three must return that same return code. If only one or two of the stacks return PAILURE, that is an error, and it should terminate and print the line number from the instruction file. If the peek did not return FAILURE, your code should make sure all three peek() "retumed the same top string element (we use "return" loosely here to include data returned to the caller as a reference parameter) If the letter is a "D", it should check the top of the stack: It should pop() all three stacks. It must check the return value of the pop() operations. If any of the stacks retum FAILURE because they are empty, all three must return that same return code. If only one or two of the stacks return FAILURE, that is an error, and it should terminate and print the line number from the instruction file. If the stacks were not empty, it should check the element removed from each stack was the same If the tests fail (because they don't all fill up or empty at the same time, or they return different elements, the program must indicate which line of the input file at which the first error was found For example, using the sample file above On line 1 The system reads "P". It will try to peek ( all three stacks. Since they are empty they will all return FAILURE. This is fine since all three retum FAILURE On line 2 The system reads "D". It will try to pop all three stacks. Since they are empty. they will all return FAILURE This is fine since all three return FAILURE On line 3 The system reads "A-3245. It will try to push() -3245 into all three stacks. This will likely succeed, and if so all three must return SUCCESS On line 4 The system reads "A 2344". It will try to push() 2344 into all three stacks Depending on the size of the stacks, this may return SUCCESS or FAILURE. Whatever it returns, all three stacks must return the same return statusCode On line 5 The system reads "D" It will try to pop() all three stacks. It will likely return SUCCESS, but as long as all three stacks return the same statusCode, it's not an error. Depending on the results of steps (3) and (4), the reference parameter may end up as either-3245 or as 2344 The program doesn't know, but does know that if the three pop()s returned SUCCESS, it should check all three reference parameters to ensure they have the same value. On line 6 The system reads "A 344322". It will try to push() 344322 into all three stacks Depending on the size of the stacks, this may return SUCCESS or FAILURE. Whatever it returns, all three stacks must return the same statusCode On line 7 The system reads "E". It will check if all three stacks are empty using the isEmpty() function. Whatever is returned from isEmpty(), all three stacks must have returned the same thing On line 8 The system reads "A 34". It will try to push() -34 into all three stacks Depending on the size of the stacks, this may return SUCCESS or FAILURE. Whatever it returns, all three stacks must return the same statusCode on line 1000 Some time later The system reads "D'. It will try to popl) all three stacks. Depending on what happens in operations 8.999 and the capacity. It may return SUCCESS or FAILURE. If some of the stacks return SUCCESS and others return FAILURE this is an error. If the stacks return On line 1001 SUCCESS. then it should check all three reference parameters to ensure they have the same value The system reads "P" it will try to peek) all three stacks. Depending on what happens in operations 8.999 and the capacity, it may retum SUCCESS or FAILURE. If some of the stacks return SUCCESS and others return FAILURE this is an error the stacks return SUCCESS, then should check all three reference parameters to ensure they have the same value. Please make sure your program is well organized and well commented, and that you close the file before you ext. Your program must have a function int teststream(std::string fileName) that actually tests the stacks and returns a line number in case of error) or Zoro in the case the tests are passed. It should terminate on the first error since t's unlikely the stacks wil ever sync up again after they are different. The line number it returns should be the instruction line number in the file produced by randomStream[). The farmingdalen stack class code is attached to this assignment and also available in the "Downloads" folder IMPORTANT: This code (or a variation of it) will be used in many future homeworks. If you do not gett right, you will continue to lose significant points in each homework submission until you submit a homework with fixed code. You cannot get credit for pror work, so all those lost points are gone forever. If you don't understand something about this assignment, please see me in office hours for assistance The mystery stack code is already contained in a project. You may either slot your project into this [replacing the test code in main()) or use the brary and header in your project your choice. If you want a 64 bit version, use the header from that project the BCS370_mysteryaltak_lib_64.lib file
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started