I need a C++ Programmer
Budget: $30 – $250 CAD
Structures, Classes, Linked Lists, Templates, and Exceptions
C-style structs containing self-referential pointers are often used to implement dynamic data structures such as linked lists, stacks, queues, and trees. This lab combines several topics from this course to realize a linked stack class that stores objects.
Assignment
Create a new C++ project and copy all of the files from here into your project. These are the complete files for the Shape example that we did in class.
Create a new class Square that inherits the class Rectangle.
I have declared the template class Stack in the file Stack.hpp
Implement the functions push(), pop(), and top() that have been declared in Stack.hpp.
Because Stack is a template class, these functions must be implemented in the header file. Be sure to throw a StackException where appropriate.
Also, remember to use the C++ new and delete for dynamic memory allocation.
Modify shapeMain.cpp so that your Shapes are stored in a Stack<Shape*> (get rid of the array). Then, use a while loop to draw() each Shape as you pop it off of the stack. Be sure to use your stack operations inside of a try so that you can catch the exception!
Note that we must create a stack of Shape* rather than Shape because
Shape is an abstract class so we cannot create any Shapes.
We need to use a pointer from the base class for polymorphism to work.
Make sure that you use ALL of your functions in your main() so that you can verify that they work!
Do something "extra" in your main() that causes an exception to be thrown so that you can use your catch block.
Hand In:
Stack.hpp, Square.cpp, Square.hpp, shapeMain.cpp
C-style structs containing self-referential pointers are often used to implement dynamic data structures such as linked lists, stacks, queues, and trees. This lab combines several topics from this course to realize a linked stack class that stores objects.
Assignment
Create a new C++ project and copy all of the files from here into your project. These are the complete files for the Shape example that we did in class.
Create a new class Square that inherits the class Rectangle.
I have declared the template class Stack in the file Stack.hpp
Implement the functions push(), pop(), and top() that have been declared in Stack.hpp.
Because Stack is a template class, these functions must be implemented in the header file. Be sure to throw a StackException where appropriate.
Also, remember to use the C++ new and delete for dynamic memory allocation.
Modify shapeMain.cpp so that your Shapes are stored in a Stack<Shape*> (get rid of the array). Then, use a while loop to draw() each Shape as you pop it off of the stack. Be sure to use your stack operations inside of a try so that you can catch the exception!
Note that we must create a stack of Shape* rather than Shape because
Shape is an abstract class so we cannot create any Shapes.
We need to use a pointer from the base class for polymorphism to work.
Make sure that you use ALL of your functions in your main() so that you can verify that they work!
Do something "extra" in your main() that causes an exception to be thrown so that you can use your catch block.
Hand In:
Stack.hpp, Square.cpp, Square.hpp, shapeMain.cpp