Answered step by step
Verified Expert Solution
Question
1 Approved Answer
CPP Starting from the myQueue.h (attached with this assignment) perform the following without adding any other operations to the class queue Type: 1. Write a
CPP
Starting from the myQueue.h (attached with this assignment) perform the following without adding any other operations to the class queue Type: 1. Write a non-member function that increment or decrement (operation will be specified as a character parameter) each element in the queue, that is passed to the function as a reference parameter, by a constant number that is also passed as a parameter. This function does not return any value. For example, if the queue Q contains the elements 2,1,3,4,5,3,0 Where 2 (left) is the front of the queue, and you call the function as in changeByConstantNM(Q.'+,3); The queue content will then be changed to 5,4,6,7,8,6,3 and if you call the function as in changeByConstantNM(Q,2,3); The stack content will be changed to -1,-2,0,1,2,0,-3 2. Implement the operation described in question 1 as a member function. You can name the function change ByConstantM. You are not allowed to use any of the predefined functions. You are not allowed to use any other Datastructure or array. 3. Re-implement the function in the previous question using recursion. Call the function changeByConstantMR. 4. Write a non-member function that duplicates each element in a queue that is passed to the function as a reference parameter. For example, if a queue Q contains the elements 2,1,3,4,5,3,0 Where 2 (left) is the front of the queue, and you call the function as in duplicateElementsNM(Q); The Queue content will then be changed to 2,2,1,1,3,3,4,4,5,5,3,3,0,0 You code should make sure that the queue will fit all the elements. 5. Implement the previous operation as a member function. You are not allowed to use any of the predefined functions. You are not allowed to use any other Datastructure. All your modifications should be performed inside the header file myQueue.h that is attached with this assignment. After performing the modifications, you should run the file hw3.cpp (attached with this assignment), without modifying it, without any problems and you should get the following output: Queue Q before changeByConstantNM(Q.'+', 3) contains: 2134530 Queue Q after changeByConstantNM(Q.'+', 3) contains: 5467863 Queue Q before changeByConstantNM(Q.4, 3) contains: 2134530 Queue Q after changeByConstantNM(Q.-, 3) contains: -1-20120-3 Queue Q before Q.changeByConstantM(':', 3) contains: 2134530 Queue Q after Q.changeByConstantM('+', 3) contains: 5467863 Queue Q before Q.changeByConstant M'-', 3) contains: 2134530 Queue Q after Q.changeByConstant('-', 3) contains: -1-20120-3 Queue Q before Q.changeByConstant MR('+', 3) contains: 2134530 Queue Q after Q.changeByConstantMR('+', 3) contains: 5467863 Queue Q before Q.changeByConstantMR(':', 3) contains: 2134530 Queue Q after Q.changeByConstantMR('-', 3) contains: -1-20120-3 Starting from the myQueue.h (attached with this assignment) perform the following without adding any other operations to the class queue Type: 1. Write a non-member function that increment or decrement (operation will be specified as a character parameter) each element in the queue, that is passed to the function as a reference parameter, by a constant number that is also passed as a parameter. This function does not return any value. For example, if the queue Q contains the elements 2,1,3,4,5,3,0 Where 2 (left) is the front of the queue, and you call the function as in changeByConstantNM(Q.'+,3); The queue content will then be changed to 5,4,6,7,8,6,3 and if you call the function as in changeByConstantNM(Q,2,3); The stack content will be changed to -1,-2,0,1,2,0,-3 2. Implement the operation described in question 1 as a member function. You can name the function change ByConstantM. You are not allowed to use any of the predefined functions. You are not allowed to use any other Datastructure or array. 3. Re-implement the function in the previous question using recursion. Call the function changeByConstantMR. 4. Write a non-member function that duplicates each element in a queue that is passed to the function as a reference parameter. For example, if a queue Q contains the elements 2,1,3,4,5,3,0 Where 2 (left) is the front of the queue, and you call the function as in duplicateElementsNM(Q); The Queue content will then be changed to 2,2,1,1,3,3,4,4,5,5,3,3,0,0 You code should make sure that the queue will fit all the elements. 5. Implement the previous operation as a member function. You are not allowed to use any of the predefined functions. You are not allowed to use any other Datastructure. All your modifications should be performed inside the header file myQueue.h that is attached with this assignment. After performing the modifications, you should run the file hw3.cpp (attached with this assignment), without modifying it, without any problems and you should get the following output: Queue Q before changeByConstantNM(Q.'+', 3) contains: 2134530 Queue Q after changeByConstantNM(Q.'+', 3) contains: 5467863 Queue Q before changeByConstantNM(Q.4, 3) contains: 2134530 Queue Q after changeByConstantNM(Q.-, 3) contains: -1-20120-3 Queue Q before Q.changeByConstantM(':', 3) contains: 2134530 Queue Q after Q.changeByConstantM('+', 3) contains: 5467863 Queue Q before Q.changeByConstant M'-', 3) contains: 2134530 Queue Q after Q.changeByConstant('-', 3) contains: -1-20120-3 Queue Q before Q.changeByConstant MR('+', 3) contains: 2134530 Queue Q after Q.changeByConstantMR('+', 3) contains: 5467863 Queue Q before Q.changeByConstantMR(':', 3) contains: 2134530 Queue Q after Q.changeByConstantMR('-', 3) contains: -1-20120-3Step 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