Question
Assume that a software application has four classes ListOfShapes,Shape,Rectangle andCircle. Rec-tangle and Circle are the subclasses of the class Shape. For this Part , there
Assume that a software application has four classes ListOfShapes,Shape,Rectangle andCircle. Rec-tangle and Circle are the subclasses of the class Shape. For this Part , there should 9 source files as follows:
1)Shape.h
2)Shape.cpp
3)Rectangle.h
4)Rectangle.cpp
5)Circle.h
6)Circle.cpp
7)ListOfShapes.h
8)ListOfShapes.cpp
9)Lab6Part2.cpp that contains the relevant main function
The class Shape is an abstract class (i.e. we should not be able to instantiate an object of this class). It has the followings:
A private member variable color.
A non-default constructor for initializing the member variablecolor.
A virtual destructor.
A member function getColor(). The class Shape has the implementation of getColor() which re-turns the color of a shape.
A pure virtual function called print().
The class Rectangle has the followings:
Two private member variables length and breadth.
A non-default constructor for initializing the length, breadth and color of a rectangle object.
A virtual destructor.
Overrides the virtual function print. The implementation of this function should print a rectangle object in a format that is consistent with the sample usage of the application shown later.(While printing, the area of a rectangle is to be computed using the formula (length breadth)).
The class Circle has the followings:
One private mem ber variable radius.
A non-default constructor for initializing the radius and color of a circle object.
A virtual destructor.
Overrides the virtual function print. The implementation of this function should print a circle object in a format that is consistent with the sample usage of the application shown later.(While printing,the area of a circle is to be computed using the formula (3.14 radius radius)).
The class ListOfShapes has the followings:
One private member variable shapes of type vector
A destructor that destroys all the objects, each object being pointed to by a relevant pointer present in the vector. (You might need the member function size of vector).
A member function addShape(Shape*) that adds a pointer to a rectangle object or a circle object to the vector. (You might need the member function push_back of vector).
A member function removeShape() that deletes the last element in the vector thereby reducing the number of elements in the vector by one. (You might need the member function pop_back of vector. Note that a call to pop_back is supposed to destroy the storage for an address in this case. The call to pop_back will not destroy the object pointed to by the address. Hence you might first need to get hold of the address (of the object) present in the last element of the vector by using the member function at of vector. You then need to explicitly destroy the object).
A member function displayShapes() that iterates over the items present in the vector and outputs the information about each item by calling the virtual function print
on the item.
There should be a console based command-line menu interface that should allow a user of the application to perform one of the operations add rectangle,add circle,
remove shape,display shapes. The menu should also support a quit operation that should end the application.
You also need to provide the UML class diagram for the design of the above software application.You should use the Violet UML editor to create the class diagram.
output:
linux-prompt> lab6_part2.exe [Shape List] There are currently 0 shape (s) in the list Please choose an option: 1. Add Rectangle 2. Add Circle 3. Remove Shape 4. Display Shapes 5. Quit > 1 [Add Rectangle] Enter Color: red Enter length: 1.5 Enter breadth: 0.3 .. [Adding Rectangle] [Shape List] There are currently 1 shape(s) in the list Please choose an option: 1. Add Rectangle 2. Add Circle 3. Remove Shape Page 3 of6 4. Display Shapes 5. Quit > 2 [Add Circle] Enter Color: blue Enter radius: 2.0 .[Adding Circle] [Shape List] There are currently 2 shape (s) in the list Please choose an option: 1. Add Rectangle 2. Add Circle 3. Remove Shape 4. Display Shapes 5. Quit > 1 [Add Rectangle] Enter Color: purple Enter length: 2.0 Enter breadth: 1.2
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