Aim
The objectives of this assignment includes.
• Learning about generic programming templates, operator overloading, ST L (containers & algorithms) and writing io manipulators
• Apply the concepts learnt by developing a data processing program
Backqround
You program should be called ‘csci251 a3.exe’, and should posses the following capabilities.
a) read in the records from a user-specified filename
b) remove all duplicate rows of data
c) filter and display the data according to user-specified sorting criteria
d) store the records displayed in c), in a user-specified filename
The next section provides information about the requirements for developing this program.
Task Requirements
A) Appendix A provides a sample input data from a file called ‘messy.txt’. It contains information meant to be stored in 4 classes: ‘Point2D’, ‘Point 3D’, ‘Line2D’ and Line3D’. Please refer to the table in Appendix A for a description of the format in which the input data for each of the classes is stored.
B) Notel: You are to research and determine which kind of ST L containers (e.g. Map, Vector, Set, Lists etc) you should use, to store all the various objects from the 4 classes. For this assignment you are not allowed to use array [ ] to store any of your data!
C) Appendix B provides a description of the 4 classes: ‘Point2D’, ‘Point 3D’, ‘Line2D’ and ‘Line3D’, and the relationships between them. You are to study the diagrams and implement them accordingly.
D) Appendix C provides the sample output format and a description of the format requirements, for each of the 4 classes. These format are to be applied whether the data from these classes are output to a file or terminal.
E) Note2: To output data, you are required to create your own output manipulator(s) to display/store data in the format described in Appendix C. You are further required to overload the insertion operator ‘<<‘, for each of the 4 classes, to support the process of inserting data to the terminal, or the relevant file stream. (Hint : Research on the concept of writing output manipulators. E.g. https://en.cppreference.com/w/cpp/io/manip/left )
F) Note3: All output data must not contain any duplicates! There are many approaches to solving this problem. Firstly, you could check for, and remove duplicate records at the point of reading in the input. Alternatively, you could temporarily store the data in a ST L container, research and make use of any ST L algorithm to search for, and remove the duplicates. Another (inefficient) way is to store everything in ST L container, but your program needs to ensure that when user wishes to see / store the records in a file, no duplicate records are shown.
G) Appendix D provides a description of a few generic template functions that you are supposed to develop. These ‘utility’ functions plays a supporting role, and they should be developed in a separate header file called ‘MyTemplates.h’
H) Your program should allow user specify the filtering criteria so that user can specify which set of records he wishes to view / store. Your program should allow the following options.
i) Point2D records <= default selected option
Point3D records
Line2D records
Line3D records
l) Your program should allow user to specify the sorting criteria so that user can specify which attributes (of a set of records) to order the data by. The sorting criteria is based on the current filtering criteria.
For example, if the current filtering criteria is ‘Only Point2D records’, your program should restrict user to the options of sorting the data by ‘x’, ‘y’ & scalar value ‘distFrOrigin’ only!
Please refer to Appendix E for a detailed description of the combinations of filtering criteria, and the respective (allowable) sorting criteria.
J) Hint: It is not necessary to develop your own sorting algorithm, or make use of any of the classical algorithms like ‘Quick-Sort’, ‘Bubble-Sort’ to fulfill the sorting requirements. There is a function defined in ST L algorithm (i.e. #include <algorithm>) called ‘sort’ You should research on its usage, code the necessary comparator functions (for each of the 4 classes + sorting criteria). Once you mastered its usage, you will easily achieve the desired sorting effect using less than 3 lines of code!
K) To assist you in visualizing the desired program interactions, please refer to Appendix F which provides a sample menu displaying the output data / messages in response to user input.
M) 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
1 ) The deliverables include the following:
b) 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)
2) IMPT: Please follow closely, to the submission instructions in Appendix G, which contains details about what to submit, file naming conventions, when to submit, where to submit, etc.
3) 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.
Gradinq
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)
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
(Sample ‘messy’ data from an input file)
Point2D, [3, 2]
Line3D, [7, 12, 3], [-9, 13, 68]
Point3D, [1, 3, 8]
Line2D,
Point2D,
Line3D, [7, -12, 3], [9, 13, 68]
Point3D,
Point2D, [3, 2]
Line3D, [70, -120, -3], [-29, 1, 268]
Line3D, [25, -69, -33], [-2, -41, 58]
Point3D, [6, 9, -50]
Note:
1 ) Some data, (e.g. ‘Point2D, [ 3 , 2] ‘) can be repeated multiple times (i.e. they are duplicated data), this applies to all other kinds of data as well.
2) In each line, the 1 st field will contain the class’s name (e.g. ‘Point2D’, ‘Point 3D’, Line2D’ and ‘Line3D’)
3) The delimiter separating the 1 st field from the rest of the data, is a comma, followed by a space char (i.e.
4) The delimiter separating each number in the 2D/3D coordinate, is also a comma, followed by a space char (i.e.
5) Each 2D/3D point’s data, is enclosed by the square brackets ‘[‘ and ‘]’
6) Each Line2D / Line3D’s data consists of two points, each enclosed by square brackets, and the delimiter separating each point is also a comma, followed by a space char (i.e.
B
(The 4 classes, and their relationships)
Point2D Line2D
# x: int
# y: int
# distFrOrigin: double – ptl: Point2D
– pt2: Point2D
# length: double
# setDistFrOrigin 0
+ Point2D (x: int, y: int)
+ getX 0 : int
+ getY 0 : int
+ getScalarValue 0 : double
+ setX (x: int)
+ setY (y: int) # setLength 0
+ Line2D (ptl : Point2D, pt2: Point2D)
+ getPt1 0 : Point2D
+ getPt2 0 : Point2D
+ getScalarValue 0 : double
+ setPt1 (ptl: Point2D)
+ setPt2 (pt2: Point2D)
Point3D
# z: int
# setDistFrOrigin 0
+ Point3D (x: int, y: int, z: int)
+ getZ 0 : int + setZ (z: int)
Line3D
– ptl: Point3D
– pt2: Point3D
# setLength 0
+ Line3D (ptl : Point3D, pt2: Point3D)
+ getPt1 0 : Point3D
+ getPt2 0 : Point3D
+ setPt1 (ptl: Point3D)
+ setPt2 (pt2: Point3D)
APPENDIX B (con’t)
Note.
1 ) The above diagrams depict the bare minimum requirements for the 4 classes whose attributes and methods you MUST implement
2) In Point2D class, setDistFrOrigin ( ) method computes the distance of the point to the origin (0, 0), and initializes the attribute distFrOrigin with this distance value. The formula to compute is as follows.
distFrOrigin 0 ) 2 0 ) 2 OR
distFrOrigin 2
Note : means square root
3) In Point 2 D class, get ScalarValue ( ) method is merely an accessor method that returns the value of attribute distFrOrigin.
4) In Line2D class, set Length ( ) method computes the distance between its own Point2D attributes ptl and pt2, and initializes the attribute length with this distance value. The formula to compute is as follows.
length (ptl .x pt2 .x) 2 pt2 . Y) 2
5) In Line2D class, get ScalarValue ( ) method is merely an accessor method that returns the value of attribute length.
6) In Line 3D class, set Length ( ) method computes the distance between its own Point 3D attributes ptl and pt2, and initializes the attribute length with this distance value. The formula to compute is as follows.
length (ptl .x pt2 .x) 2 pt2 . y) 2 + (ptl . z pt2 . z) 2
7) For all the 4 classes, you are free to declare and implement any additional attributes and methods like.
• Overloading io-stream, arithmetic, comparison or any other operators ‘<<‘ etc.
• Writing static comparator functions to use in ST L algorithms and containers,
• Writing io manipulators specific to a particular class
• Writing any other supporting helper functions necessary to fulfill the requirements of this assignment.
C
(General Output Format for Point2D & Point 3D data)
Point2D
x
9,
99,
[-999,
3 ,
23 ,
123 , Y
9 ]
99 ]
999 ]
3
23 ]
123 ] Dist. Fr Origin
12 . 728
14 0 . 007
1412 . 7 99
32 . 527
173 . 948
Point3D
x
9,
99,
[-999
3 ,
23 ,
123 , 9,
99,
999,
3 ,
23 ,
123 , z Dist. Fr Origin
9 ] 15 . 589
99 ] 171 . 473
999 ] 1730 . 32 0
3 5 . 196
23 ] 39 . 837
123 ] 213 . 042
Note:
l ) The allocated width to store each x, y and/or z ordinate value is 4 ‘spaces’, inclusive of minus sign
2) All x, y, z values are strictly whole numbers (i.e. integers) and all Dist. Fr Origin values are strictly decimal (i.e. double), with precision set at up to 3 decimal places
3) The 1 st 2 lines (representing the ‘header’) is compulsory. The alignment of the ‘X’, ‘Y’ or ‘Z’ column names in the header is vertically aligned to its respective last digit’s position!
4) The should be 3 ‘spaces’ between the end of each point’s data values, and its corresponding Dist. Fr Origin values
APPENDIX C (con’t)
(General Output Format for Line2D & Line3D data)
Line2D
PI-X
99,
999,
999,
999, PI-Y
99
999
999
999 P2-X
99,
999,
999,
999, P2-Y
Length
127 . 279
1272 . 792
1400 . 071
1408 . 557
2825 . 599
1417 . 042
Line3D
PI-X
99,
-999,
999,
999, PI-Y
99,
999,
999,
999, PI-Z
99
-999
999
999 P2-X
99,
999,
999,
999, P2-Y P2-Z
99,
999,
999,
999, Length
155 . 885
1558 . 84 6
1714 . 730
1275 . 123
34 60 . 638
1735 . 515
Note:
5) In Line2D, the formatting for data under ‘PI -x’, ‘PI -Y’, ‘P2-X’ and ‘P2-Y’ headings is similar to that for Point2D. The corresponding formatting applies for the case of Line3D which is similar to that specified for Point3D.
6) The 1 st 2 lines (representing the ‘header’) is compulsory. The alignment of the ‘PI -x’ ‘PI -Y’, ‘PI -z’, ‘P2-X’, ‘P2-Y’ and ‘P2-Z’ column names in the header is vertically aligned to its respective last digit’s position!
7) The should be 3 ‘spaces’ between the end of each point’s data values, and its corresponding Length values
D
(Description of Generic Function Template)
Template function Parameter description If param(s) is of the following Class / Type “Meaning” of the template function when applied to (param’s) Class /
Type
Name :
scalar difference
Return Type : double No. of parameters : 2
Type of 1 st parameter
Type of 2 nd parameter . Point2D The absolute scalar values and 2.
(Hint: make use getScalarValue() Appendix B!) value difference in the betw. parameters 1
of the method mentioned in
Point3D
Line2D
Line3D
equals
Return Type :
‘bool’ No. of parameters : 2
Type of 1st parameter
Type of 2nd parameter Numeric primitives (int double, etc) parameter 1 parameter 2
Point2D param I ‘s x param 1’s y param 2’s x param 2’s y AND
Point3D param I ‘s x param 1’s y param I ‘s z param 2’s x param 2’s y param 2’s z AND
AND
Line2D param I ‘s ptl
AND param I ‘s pt2 param 2’s ptl param 2’s pt2
Line3D
Note:
1) Based on the information provided in the table, you will need to overload the relevant operators in the affected classes, in order to implement the ‘meaning’ correctly, when the generic function’s algo is applied on the 4 classes
2) The above generic function templates should be implemented in a header file called
‘My Templates . h’
E
(Combinations of filtering + sorting criteria)
Filtering Criteria Sorting Criteria (allow sorting by . . .)
Point2D records i) X ordinate value
Y ordinate value
Dist. Fr Origin value (default)
Point3D records i) X ordinate value
Y ordinate value
Z ordinate value
Dist. Fr Origin value (default)
Line2D records i) X and Y coordinate values of Pt. 1 X and Y coordinate values of Pt. 2
Length value (default)
Line3D records
Note:
l ) Sorting by X and Y coordinates is done, by first ordering all rows according to x-ordinate value, this will have a ‘sorting and bunching’ effect that groups rows with the same xordinate values together, if it exists.
Within each ‘group’ with similar x-ordinate values, the sorting order (assuming it is ascending), is then applied to the y-ordinate, such that rows with the same X, but smaller Y value will be ‘above’ those with same X, but bigger Y values.
2) For all sorting criteria, you should allow sorting in both ASCENDING and DESCENDING order! (Assume default is ‘ASC’)
3) If you are using ST L containers / algorithms to handle the storage of your objects and sorting, you need to implement the relevant function comparators for each of the 4 classes. These function comparators should ideally be implemented as static boolean functions under each of the 4 classes.
F
(Sample Menu Interactions)
Student ID : 1234567
Student Name : Tan Ah Meng Elvis
Welcome to Assn3 program!
1) Read in data
2) Specify filtering criteria (current : Point2D)
3) Specify sorting criteria (current : x-ordinate)
4) Specify sorting order (current : ASC)
5) View data
6) Store data
Please enter your choice .
Please enter filename : messy.txt
13 records read in successfully!
Going back to main menu .
Impt !! Please include your:
1. Student ID
2. Student Name
every time you display your Main Menu. Marks will be deducted if the required info is not shown.
The figure on the left describes a sample interaction for specifying input filename to read in data.
The program should acknowledge by indicating the no. of records read in successfully!
Student ID : 1234567
Student Name : Tan Ah Meng Elvis
Welcome to Assn3 program!
1) Read in data
2) Specify filtering criteria (current : Point2D)
3) Specify sorting criteria (current : x-ordinate)
4) Specify sorting order (current : ASC)
5) View data
6) Store data
Please enter your choice .
[ Specifying filtering criteria (current : Point2D)
a) Point2D records
b) Point3D records
c) Line2D records
d) Line3D records
Please enter your criteria (a — d) : d
Filter criteria successfully set to ‘Line3D’!
1) Read in data
2) Specify filtering criteria (current : Line3D)
3) Specify sorting criteria (current : Pt. 1)
4) Specify sorting order (current : ASC)
5)
The figure on the right describes a sample interaction for specifying filterinq criteria to indicate which type of records user wish to see.
Notel: Observe that the current filtering criteria has changed in option 2) of the main menu, once it has been successfully set to ‘Line3D’ !
Note2: Observe that the current sorting criteria is automatically changed to the default for Line3D records, which is sorting by Pt I ‘s (x, y) coordinates (refer to Appendix E for details)
APPENDIX F (con’t)
(Sample Menu Interactions)
1) Read in data
2) Specify filtering criteria (current : Line3D)
3) Specify sorting criteria (current : Pt. 1)
4) Specify sorting order (current : ASC)
5) View data
6) Store data
Please enter your choice .
[ Specifying sorting criteria (current :
a) Pt. I’s (x, y) values
b) Pt. 2’s (x, y) values
c) Length value
Please enter your criteria (a — c) : c
Sorting criteria successfully set to ‘Length’!
1) Read in data
2) Specify filtering criteria (current : Line3D)
3) Specify sorting criteria (current : Length)
4) Specify sorting order (current : ASC)
5)
The figure on the right describes a sample interaction for specifying sortinq criteria to indicate which attribute, of the selected type of records user wish to see.
Note3: Observe that the sub-menu display options which are relevant to currently selected filter, which is ‘Line3D’! (refer to Appendix E for details)
Note4: Observe that the current sorting criteria has changed in option 3) of the main menu, once it has been successfully set to ‘Length’!
1) Read in data
2) Specify filtering criteria (current : Line3D)
3) Specify sorting criteria (current : Pt. 1)
4) Specify sorting order (current : ASC)
5) View data
6) Store data
Please enter your choice .• 4
[ Specifying sorting order (current : ASC) ]
a) ASC (Ascending order)
b) DSC (Descending order)
Please enter your criteria (a — b) : b
Sorting order successfully set to ‘DSC’!
1) Read in data
2) Specify filtering criteria (current : Line3D)
3) Specify sorting criteria (current : Length)
4) Specify sorting order (current : DSC)5)
The figure on the right describes a sample interaction for specifying sortinq order to indicate whether records are to be displayed / output in Ascending or Descending order.
Note5: Observe that the current sorting order has changed in option 4) of the main menu, once it has been successfully set to ‘DSC’!
APPENDIX F (con’t)
(Sample Menu Interactions)
1) Read in data
2) Specify filtering criteria (current : Line3D)
3) Specify sorting criteria (current : Length)
4) Specify sorting order (current : DSC)
5) View data
6) Store data
Please enter your choice : 5
[ View data .
filtering criteria : Line3D sorting criteria : Length sorting order : DSC
PI-X PI-Y PI-Z P2-X P2-Y P2-Z Length
999, 999, 999] [—999, 999, 999] 3460 . 638
[—999, 999, 999] 3, 3, 3] 1735 . 515
[—999, 999, 999] 9, 9, 9] 1714 . 730
99, 99, 99] [—999, 999, 999] 1558 . 846
3, 3, 3] 999, 999, 999] 1275 . 123 9, 9, 9] 99, 99, 99] 155 . 885
Press any key to go back to main menu .
The figure on the right describes a sample interaction to display data.
Note6: Observe that all the latest criteria specified in main menu options 2) — 4) are re—iterated before the rows of Line3D records are displayed.
1) Read in data
2) Specify filtering criteria (current : Line3D)
3) Specify sorting criteria (current : Length)
4) Specify sorting order (current : DSC)
5) View data
6) Store data
Please enter your choice : 6
Please enter filename : Line3D.txt
13 records output successfully!
Going back to main menu .
The figure on the right describes a sample interaction to write data to an output file.
Note7: The contents and its formatting of the data in the output file ‘Line3D.txt’ should be similar to that displayed when user choose main menu option 5! (please refer to output of the figure above)
APPENDIX G
Submission Instructions (V. IMP T!!)
1) Deliverables
a) All submissions should be in softcopy, unless otherwise instructed
b) 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, *.0, or *.cpp files)
the executable file, (using Ubuntu g++ compiler), compile into an executable filename with *.exe (e.g. csci251 a3.exe)
2) How to package
Compress all your assignment files into a single zip file. Please use the following naming format .
Example : FT TutGrp3 A3 1234567_JohnDoeAnderson.zip
< FTI p Use for ull- ime student if you are Part-Time student
<Your Grp refers to your SIM tutorial group (e.g. TutGrp1 / TutGrp2 / TutGrp3 / etc.)
A if you are submitting assignment 3 Al if submitting assignment 1 etc.
<Stud. No.> refers to your I-JOW student number (e.g. 1234567)
<Name> refers to your I-JOW registered name (e.g. JohnDoeAnderson)
3) Where to submit
Please submit your assignment via Moodle el-earning site.
IMPORTANT NOTE :
• To minimize the chances of encountering UNFORSEEN SITUATIONS (mentioned below), please do an EARLY SUBMISSION via Moodle.
In the event of UNFORSEEN SITUATIONS :
[email protected] for FULL TIME students [email protected] for PART TIME students
In your email subject line, type in the following information
<FTIPT> <Your Grp <assignment inf0> <student number> and ìkname>
Example:
Subject FT TutGrp3 A3 1234567 JohnDoeAnderson
sent folder
4) When to submit
a) Depending on the time-table, a software demo / testinq / presentation for your assignment will be scheduled during the:
3 rd – 5th lab session for the semester (i.e. lab 3 – 5), for Full Time ( ) students
2 nd – 4th lab session for the semester (i.e. lab 2 – 4), for Part Time (P T) students
b) Please refer to the following table on the different deliverables, submission events & deadlines
Testing (test cases), during . Email Test Case Result files by :
1 Lab 2 Lab 3 Lab 2(PT), Lab End of Lab 2(PT), Lab 3(FT)
2 Lab 3 Lab 4 Lab 3(PT), Lab 4(FT) End of Lab 3(PT), Lab 4(FT)
3 Lab 4 Lab 5 Lab 4(PT), Lab End of Lab 4(PT), Lab 5(FT)
5) Please help by paying attention to the following
! VERY IMPORTANT !
PLEASE FOLLOW ALL THE GUIDELINES / REQUIREMENTS IN ALL ASSIGNMENT APPENDICES
PLEASE FOLLOW ALL THE SUBMISSION INSTRUCTIONS FROM 1 TO 4
IF YOU ARE NOT SURE
OR
MARKS WILL BE DEDUCTED IF YOU FAIL TO FOLLOW INSTRUCTIONS
Examples of marks deduction
Your deliverables / zip file does not follow naming convention
You have no email subject / or do not following naming convention
Wrong naming or misleading information given
(e.g. putting “A2” in email subject, when you are submitting “Al “)
(e.g. naming “Al” in your zip file, but inside contains A2 files )
Your submission cannot be downloaded and unzipped
Your program cannot be re-compiled and/or executable file cannot run
Your report / testing files cannot be opened by Microsoft Word / Excel 2003 You did not submit / incomplete submission of software demo / testing files etc
6) Re-submission administration
< Step 1> Prepare 2 zip files as follows
Zip up for re-submission, program files according to the following format
Resubmit <Your Grp A3 <Stud. No.>
Example : Resubmit FT TutGrp3 A3 1234567 JohnDoeAnderson.zip
Zip up for re-submission, test case results files according to the following format
Resubmit <Your A3 TCResuIts <Stud. No.> <Name>.zip
Example : Resubmit FT TutGrp3 A3 TCResuIts 1234567 JohnDoeAnderson.zip
< FTI p Use for Full-Time student if you are Part-Time student
<Your Grp refers to your SIM tutorial group (e.g. TutGrp1 / TutGrp2 / TutGrp3 / etc.)
A if you are submitting assignment , A2 if submitting assignment etc.
<Stud. No.> refers to your I-JOW student number (e.g. 1234567)
<Name> refers to your I-JOW registered name (e.g. JohnDoeAnderson)
< Step 2>
In your email subject line, type in the following information
Resubmit <FTIPT> <Your Grp <assignment inf0> <student number> and <name>
Example.
Subject Resubmit FT TutGrp3 A3 1234567 JohnDoeAnderson
IMPORTANT NOTE
Non-submission of any of the above mentioned files, or failure to adhere to submission instructions will result in ZERO marks!





