Assignment 2
Aim
The objectives of this assignment includes:
- Learning about encapsulation, inheritance, polymorphism and function overloading
- Apply the concepts learnt by developing a survey and path planning program
Β
Background
In a theoretical flat-land universe, everything is in 2 dimensions. People, animals, plants to planets, moons, galaxies and even space itself, is in 2D. In our flat-land space (i.e. βflat-spaceβ), there is a powerful organization called 2D-StarFleet (2DSF), whose goals include seeking out new life and civilization via exploration. Β
While on a routine mission of exploration, the flagship of 2DSF, the Enterprise-2D is trapped in an expanse of space encircled by a massive ring of violent, electrical plasma storm. Data coming in from the sensor array reveals that the only opening in this storm is located at the far end of the enclosed area, from Enterprise-2Dβs current location.
In addition, the sensor data also revealed that this area is populated by strange, 2D geometrical shapes, with sizes ranging from a small moon, asteroid, to large planets, or even a star! This implies that to travel to the βexitβ at the far end of the storm, you need to understand more about the properties of these shapes and attempt to chart a course to navigate to the exit!
As a Science Officer aboard Enterprise-2D, you need to develop a program that has the following capabilities:
- read in sensor data on the strange 2D shapes (via manual input)
- compute the area (βmassβ) of these shapes
- print shapes report (e.g. list of points: on its perimeter, or totally within shapeβs area)
- sort shapes data (sorted by special type and area)
The next section provides information about the requirements for developing this program.
Β
Task Requirements
Β
- In terms of relative positioning, you may assume a coordinate system with Enterprise-2D at the origin, trying to navigate in a general βupper-rightβ direction, to get to the exit in the storm. Please refer to Appendix A, which elaborates on this coordinate system and the unit representation of 2D shapes.
IMPORTANT : For this assignment, you should not assume that the 2D shapes in Appendix A are positioned exactly as shown in Appendix A, nor that there are not more shapes. There will, however, only be shapes of the types listed in Appendix B
- The sensor data coming in from Enterprise-2Dβs sensor array provides crucial information about the 2D shapes such as name, special type and location of all vertices (that outlines the perimeter of the shape). Please refer to Appendix B, which provides a more detailed description of the sensor data.
Β
- To assist you in the initial class design of your program, please refer to Appendix C, which illustrates one possible way of designing your program. It also describes a list of requirements which you need to implement, especially those marked under βcompulsoryβ. The classes highlighted in Appendix C are purely meant to store data about the 2D shapes entered into your program by user.
Β
- You are required to implement a main driver class called βAssn2β, whose methods are called to start the program. When started, it should print a menu providing the following functionalities :
Β
- read in sensor data on the strange 2D shapes (via manual input)
- compute the area (βmassβ) of these shapes
- print shapes report (e.g. list of points on its perimeter, or totally within shapes area)
- sort shapes data (sorted by special type and area)
Β
Appendix D provides more information about implementing this class.
Β
- Once the program is completed and tested to be working successfully, you are highly encouraged to add on βnew featuresβ to the program that you feel are relevant to the problem. Additional marks may be awarded subject to the relevancy and correctness of the new functionalities.
Β
- You are to use only C++ language to develop your program. There is no restriction on the IDE as long as your source files can be compiled by g++ compiler (that comes packaged in Ubuntu linux) and executed in the Ubuntu terminal shell environment.
Β
Β
Deliverables
Β
- The deliverables include the following:
Β
- The actual working C++ program (soft copy), with comments on each file, function or block of code to help the tutor understand its purpose.
Β
- A softcopy word document that elaborates on:
- (Interpreted) requirements of the program
- Diagram / Illustrations of program design
- Summary of implementation of each module in your program
- Reflections on program development (e.g. assumptions made, difficulties faced, what could have been done better, possible enhancements in future, what have you learnt, etc)
Β
- A program demo/software testing during lab session. You must be prepared to perform certain tasks / answer any questions posed by the tutor.
Β
- IMPT: Please follow closely, to the submission instructions in Appendix E, which contains details about what to submit, file naming conventions, when to submit, where to submit, etc.
Β
- The software demo / testing will be held during lab session where you are supposed to submit your assignment. Some time will be allocated for you to present / demonstrate your programβs capabilities during the session.
Β
Β
Grading
Β
Studentβs deliverable will be graded according to the following criteria:
Β
- Program fulfills all the basic requirements stipulated by the assignment
Β
- Successful demonstration of a working program, clarity of explanation / presentation and satisfactory answers provided during Q & A session.
Β
- Additional effort (e.g. enhancing the program with relevant features over and above task requirements, impressive, βkillerβ presentation)
Β
- After the submission of deliverables, students will be required undergo a software testing process (to determine the correctness and fulfillment of software requirements.) Further instructions will be given by the Tutor during the subsequent respective labs. Please pay attention as failure to adhere to instructions will result in deduction of marks.
Β
Β
Tutorβs note:
In the real working world, satisfactory completion of your tasks is no longer enough. The capability, efficiency and robustness of your system to operate under different testing conditions, and the ability to add value, communicate and/or demonstrate your ideas with clarity is just as important as correct functioning of your program. The grading criteria is set to imitate such requirements on a βsmaller scaleβ.
Β
Β
Β
APPENDIX A
Β
(Coordinate System w.r.t. Enterprise-2D, and the plasma storm)
Β
Enterprise-2D is trapped in this huge ring of electrical plasma storm. The only opening to exit this storm is located in the far βupper-rightβ of the coordinate system, for e.g. at Point2D (14, 14) !
APPENDIX B
Β
(Description of Sensor Data)
Β
Name
The name of the 2D shape reveals the general type of shape encountered. Currently, the values consist ofΒ : βSquareβ, βRectangleβ, βCrossβ and βCircleβ.
Β
Β
Special Type
Enterprise-2Dβs sensor has detected that some shapes encloses a βwarp-spaceβ with the amazing ability to teleport any objects that touches one of its vertex, to any other vertices of the same shape, instantaneously !
Β
This makes it highly desirable, for Enterprise-2D to travel towards this kind of shape, in the hopes of travelling faster, and saving precious fuel at the same time!
Β
There are only 2 values for βspecial typeβ : βWSβ (Warp-Space) or βNSβ (Normal-Space).
Β
Β
Vertices
The vertices is actually a set of (x, y) points, that describes the outline of the 2D shape. The number of points in the set, depends on the name of the shape. The table below summarizes the kind of sensor data your program expects to receive.
Β
| Name | Special Type | No. of Vertices
(i.e. x, y, points) |
Actual Vertex Data β¦ |
| βCrossβ | βWSβ or βNSβ | 12 | e.g. (1, 3), (1, 4), β¦ etc. |
| βSquareβ | βWSβ or βNSβ | 4 | |
| βRectangleβ | βWSβ or βNSβ | 4 | |
Β
Β
Β
Note :Β
As mentioned in the Background section, the 1st capability of your program should allow manual input of the above data.
Β
It is not necessary to prompt user for βNo. of Verticesβ because the name of the shape will already inform your program about how much vertex data to expect.
Β
For example, when your program prompt for name of the shape, if user enters βCrossβ, it is safe for your program to assume that user is going to key a set of 12 (x, y) points later!
Β
Β
APPENDIX C
Β
(Implementation Requirements)
Β
Β
Compulsory requirements
Β
#1 The parent class is βShapeTwoDβ. Any attributes, constructors and methods specified inΒ the diagram must be implemented, with the exact same name, parameter, type andΒ access!
Β
#2 Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β The sub-classes of ShapeTwoD must be named βCrossβ, βSquareβ, βCircleβ and
βRectangleβ.
Β
#3 The method βtoString()β in class ShapeTwoD is a virtual function that returns a stringΒ containing all the values of the attributes in the shape, excluding the array of vertex data.Β (However, sub-classes of ShapeTwoD must output the array of vertex data, inclusive ofΒ any other attributeβs values it inherited)
Β
#4 The method βcomputeArea()β in class ShapeTwoD is a virtual function. It must beΒ override by the sub-classes and implemented individually.
Β
For example, because each sub-class has different number of vertices and values, sub class Crossβs computeArea() implementation would use a different algorithm /Β formula from sub-class Squareβs computeArea() implementation!
Β
Note : The sensor data will only provide the locations (vertices) of each 2D shapeΒ encountered. You will be required to do the necessary research to derive the formula toΒ compute the area for each shape, based on the set of vertex data (i,e. a set of [ x, y ]Β points) provided!
Β
#5 The method βisPointInShape()β in class ShapeTwoD is a virtual function. It takes inΒ a [ x, y ] location and returns a boolean value indicating whether the location is totallyΒ within the shapeβs area. It must be over-ridden by the sub-classes and implementedΒ individually. (Pls refer to sample output in Appendix D).
Β
#6 The method βisPointOnShape()β in class ShapeTwoD is also a virtual function. ItΒ takes in a [ x, y ] location and returns a boolean value indicating whether the location isΒ found on any lines joining the shapesβ vertices! It must be over-ridden by the sub classes and implemented individually. (Pls refer to sample output in Appendix D).
Β
Β
Β
Other requirements
Β
- For parent class βShapeTwoDβ. You are free to add on any additional methods or attributes deemed necessary for your program to provide its services.
Β
- Since user will key in the name of the shape, it is possible for you to declare arrays of fixed sizes in the sub-classes to store the coordinate vertices of the shape!
Β
- You are free to implement any other additional classes you feel necessary so as to provide the required capabilities for this program.
Β
Β
Β
Β
Β
Β
Β
APPENDIX D
Β
(Implementation info for : Assn2 driver class)
Β
This class contains the main () method which declares and instantiates all other classes (i.e. Shape2D, Square, β¦ etc) and sets up all the necessary interactions to perform its task.
Β
Β
Student ID : 1234567 The figure on the left describes a sample Student Name : Tan Ah Meng Elvis interaction between the main menu and βInput
βββββββββββββββββ- Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β sensor dataβ sub-menu (1st example)
Welcome to Assn2 program! Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β
Β
- Input sensor data Note :Β
- Compute area (for all records) All shapes data should be stored in a Shape2D
- Print shapes report array in the Assn2 driver class. You may
- Sort shape data assume that no more than 100 shapes will be
Β
Please enter your choice : 1 Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β entered into your program at any one time!
[ Input sensor data ] Β Β Β Β
Please enter name of shape : Cross Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Impt !!Β Please include your:
Please enter special type : WS Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β 1. Student ID
Β
- Student Name
Please enter x-ordinate of pt.1 : 1 Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β
Please enter y-ordinate of pt.1 : 1 Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β every time you display your Main Menu.
Marks will be deducted if the required info
. . . Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β is not shown.
Β
Β
Please enter x-ordinate of pt.12 : 1
Please enter y-ordinate of pt.12 : 2
Student ID Β Β Β Β Β : 1234567
Record successfully stored. Going back to main Β Β Β Β Β Β Β Β Student Name : Tan Ah Meng Elvis
menu β¦ Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β βββββββββββββββββ-
Welcome to Assn2 program!
Student ID Β Β Β Β Β Β Β : 1234567 Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β
Student Name : Tan Ah Meng Elvis Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β 1) Β Β Β Β Β Β Input sensor data
βββββββββββββββββ- Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β 2) Β Β Β Β Β Β Compute area (for all records)
- Print shapes report
- Sort shapes data
Β Please enter your choice : 2
The figure on the right describes a sample
interaction between the main menu and Computation completed! ( 5 records were updated ) βCompute area (for all records)β function.
Β
Note : The example assumes the case where there are only 5 shapes input so far, hence, the message that β5 records were updatedβ!
Β
In this compute area function, you must exhibit polymorphic behavior and dynamic binding by invoking the correct function for each shape stored in the Shape2D array !
Β
Β
Β
| Student ID Β Β Β Β Β : 1234567
Student Name : Tan Ah Meng Elvis βββββββββββββββββ- Welcome to Assn2 program! Β 1)Β Β Β Β Β Β Β Β Β Β Β Input sensor data 2)Β Β Β Β Β Β Β Β Β Β Β Compute area (for all records) 3)Β Β Β Β Β Β Β Β Β Β Β Print shapes report 4)Β Β Β Β Β Β Β Β Β Β Β Sort shape data Β Please enter your choice : 1 Β [ Input sensor data ] Please enter name of shape : Circle Please enter special type : NS Β Please enter x-ordinate of center : 5 Please enter y-ordinate of center : 7 Please enter radius (units) : 2 Β Record successfully stored. Going back to main menu β¦ Β Student ID Β Β Β Β Β : 1234567 Student Name : Tan Ah Meng Elvis βββββββββββββββββ- |
The figure on the left describes a sample interaction between the main menu and βInput
sensor dataβ sub-menu (2nd example)
Β
Note : For circle, there is no need to enter vertices, as there are no βcornersβ as opposed to other multi-sided polygon shape. Instead, just prompt user to enter the [x, y] of its center and its
radius, as shown on the left β¦
Β
Β
Β
The figure on the right describes a sample interaction between the main menu and βPrint shapes reportβ function.
Β
Β
Notes : The example assumes the case where there has only been 5 sensor data records input so far.
Β
Β
βPoints on perimeterβ refers to only those points lying on the line drawn between 2 vertices, for each pair of vertices defining the shapeβs outline.
Β
E.g. (1, 2) lies on a line between vertices (1, 1) and (1, 3) !
Β
You do not need to include those points which describe the vertices of the shape!
Β
Β
βPoints within shapeβ refers to those points which are totally within the shape.
Β
You do not need to include :
Β
- those points which describe the vertices of the shape!
Β
- those points on the perimeter of the shape!
Β
Β
Β
Β
Β
Β
Β
Β
Β
Student ID Β Β Β Β Β : 1234567
Student Name : Tan Ah Meng Elvis
βββββββββββββββββ-
Welcome to Assn2 program!
Β
- Input sensor data
- Compute area (for all records)
- Print shapes report
- Sort shapes data
Β
Please enter your choice : 3
Β
Total no. of records available = 5
Β
Shape [0]
Name : Square
Special Type : WS Area : 4 units square Vertices :Β
Point [0] : (1, 1)
Point [1] : (1, 3)
Point [2] : (3, 3)
Point [3] : (3, 1)
Β
Points on perimeter : (1,2), (2, 1), (2, 3), (3, 2)
Β
Points within shape : (2, 2)
Β . . .Β
Β
Shape [4]
Name : Rectangle Special Type : NS Area : 8 units square Vertices :
Point [0] : (2, 17)
Point [1] : (2, 15)
Point [2] : (6, 15)
Point [3] : (6, 17)
Β
Points on perimeter : (2, 16), (3, 15), (4, 15), (5, 15), (6,
16), (5, 17), (4, 17), (3, 17)
Β
Points within shape : (3, 16), (4, 16), (5, 16)
Β
Β
Β
Β
The figure on the right describes a sample interaction between the main menu and βSort shapes dataβ sub-menu.
Β
Β
| Student ID Β Β Β Β : 1234567
Student Name : Tan Ah Meng Elvis βββββββββββββββββ- Welcome to Assn2 program! Β 1)Β Β Β Β Β Β Β Β Β Β Β Input sensor data 2)Β Β Β Β Β Β Β Β Β Β Β Compute area (for all records) 3)Β Β Β Β Β Β Β Β Β Β Β Print shapes report 4)Β Β Β Β Β Β Β Β Β Β Β Sort shapes data Β Please enter your choice : 4 Β a)Β Β Β Β Β Β Β Β Β Β Β Sort by area (ascending) b)Β Β Β Β Β Β Β Β Β Β Β Sort by area (descending) c)Β Β Β Β Β Β Β Β Β Β Β Sort by special type and area Β Please select sort option (βqβ to go main menu) : b Β Sort by area (largest to smallest) β¦ Β Shape [4] Name : Rectangle Special Type : NS Area : 8 units square Vertices : Point [0] : (2, 17) Point [1] : (2, 15) Point [2] : (6, 15) Point [3] : (6, 17) Β Points on perimeter : (2, 16), (3, 15), (4, 15), (5, 15), (6, 16), (5, 17), (4, 17), (3, 17) Β Points within shape : (3, 16), (4, 16), (5, 16) Β . . .Β Β Shape [2] Name : Square Special Type : WS Area : 1 units square Vertices :Β Point [0] : (6, 6) Point [1] : (6, 7) Point [2] : (7, 7) Point [3] : (7, 6) Β Points on perimeter : none! Β Points within shape : none! Β |
Note : For βsort by special type and areaβ option Β Β Β Β Β Β Β Β Β Β Β in the sub-menu, shapes with special types βWSβ should be displayed first, followed by all shapes with special types βNSβ.
Β
Β
Within each group of shapes (i.e. WS or NS), display the shapes in descending order!
Please select sort option (βqβ to go main menu) : q
APPENDIX E
Β
Submission Instructions (V. IMPT!!)
Β
Β
1) Deliverables
Β
- All submissions should be in softcopy, unless otherwise instructed
Β
- For the actual files to be submitted, you typically need to include the following:
Β
- word document report (e.g. *.doc), save as MS Word 97-2003 format
Β
- the source file(s), (e.g. *.h, *.o, or *.cpp files)
Β
- the executable file, compile into an executable filename with *.exe
(e.g. csci251_a2.exe)
Β
Β
2) How to package
Β
Compress all your assignment files into a single zip file. Please use the following namingΒ format :
Β
<FT/PT>_Assn2_<Stud. No.>_<Name>.zip
Example : Β FT_Assn2_1234567_JohnDoeAnderson. zip
Β
Β
- <FT/PT> Use βFTβ for Full-Time student, βPTβ if you are Part-Time student
Β
- Assn2 if you are submitting assignment 2, Assn3 if submitting assignment 3
Β
- <Stud. No.> refers to your UOW student number (e.g. 1234567)
Β
- <Name> refers to your UOW registered name (e.g. JohnDoeAnderson)
Β
Β








