Objective: get practical experience in using: string and binary data advanced I/O and manipulator; templates and STLGeneral Requirements Follow the common principles of OO programming when you design your classes Put your name, student number at the beginning of each source file/*Students Name:Students email address:Laboratory group (group code and time):Purpose of this assignment:-*/ Add comments to the source code to make your solution easier to followAssignment requirements:There are three tasks in this assignment.Task 1: Template (8 marks)1. ListNodeDefine and implement a template class ListNode in a namespace MYLIB in afile OrderedList.h, which has a template data member and two pointersthat point to the previous ListNode object and next ListNode object. Defineand implement necessary constructor(s) and other member functions in the fileOrderedList.h.2. OrderedListDefine and implement a template class OrderedList as a container in a fileOrderedList.h that can be used to store template data in a Doubly LinkedList (DLL) with nodes ordered by the data values from the smallest one to thebiggest one. Define two data members head and tail as pointers ofListNode type. They point to the head and tail of a DLL.3. iteratorDefine a nested class iterator in the template class OrderedList that canbe used to traversal the DLL. It contains a data member of a ListNodepointer points to a node in the DLL. Define constructors, overloading operators,such as ++ (pre-fix and post-fix increment operator) that change an iteratorpoints to the next node, * (dereference operator) returns the data that the iteratorpoints to, and != (not equal) to compare two iterators in the class iterator.Define a constructor, destructor for the template class OrderedList. Definea member function begin() for the template class OrderedList that returnsan iterator object points to the beginning of the DLL. Define a member functionend() for the template class OrderedList that returns an iterator objectpoints to the end of the DLL. Define a member function insert(const T &)for the template class OrderedList that take a template data as a parameter,insert a new node with the data value into the correct location in the DLL.Implement member functions for the template class OrderedList and nestedclass iterator in the file OrderedList.h.4. StudentDefine a class Student in a file Student.h, which contains student number,name and email. Define overloading insertion operator (<<) to print out datamembers of a Student object. Define overloading extraction operator () toget input data to a Student object. Define overloading comparison operator <=(or <) that compare two Students objects by their emails.Define necessary member functions, such as constructors, etc., for the classStudent.Implement member functions, friend input operator, output operator for the classStudent in a file Student.cpp.Download a file task1Main.cpp to test the DLL by different data (integers, doublesand Student objects). You will get data from the keyboard, add them into the orderedDLL, then print out results.Testing:You can compile the task 1 byCC o task1 task1Main.cpp Student.cppThen run the program like following (input data in red):./task1How many integers? 5Input an integer: 18Input an integer: 2Input an integer: 13Input an integer: 9Input an integer: 7Output integers:2 7 9 13 18How many doubles? 8Input a double: 17.5Input a double: 12.5Input a double: 11.3Input a double: 19.8Input a double: 18.4Input a double: 10.2Input a double: 21.4Input a double: 22.2Output doubles:10.2 11.3 12.5 17.5 18.4 19.8 22.2 31.4How many student records? 4Input number: 1234567Input name: Cart DongInput email: [email protected]Input number: 1234568Input name: Bob SmithInput email: [email protected]Input number: 1234570Input name: Mark TwainInput email: [email protected]Input number: 1234571Input name: Alice MontageInput email: [email protected]Output students:1234571, Alice Montage, [email protected]1234568, Bob Smith, [email protected]1234567, Cart Dong, [email protected]1234570, Mark Twain, [email protected]You can download the testing file input1.txt from Moodle and save it into yourworking directory, test your program by using following method:./task1 < input1.txtNote: Your program of task 1 should work on different testing data.Task 2: file I/O and manipulations (5 marks)Download the source code Date.h and Date.cpp from Moodle for this task.1. AccountDefine a class Account in a file Account.h that contains data membersaccount number, name, sex, date of birth (Date type), addressand account balance. Define constructor(s), overloading operators,include assignment operator (=), less than and equals to operator (<=), insertionoperator (<<), and extraction operator () for the class Account. Define othernecessary member functions.Implement member functions and overloading operators for the class Accountin a file Account.cpp.Define you own manipulator Currency that takes two integers as width andprecision for the output of currency in the file Account.h. Implement themanipulator Currency in the file Account.cpp. The manipulator Currencywill be used in the insertion operator for Account balance. The manipulatorCurrency will set output currency symbol as $, the width of output currency, theprecision of currency and filled by zeros (0s) if the width of currency is not longenough.Hint: Define fixed size char arrays instead of strings for some datamembers defined in the class Account (such as name, address).Hint: Use iomanip and Currency that defined to generate formatted outputs for the account records.2. AccountManagementDefine a class AccountManagement in a file AccountManagement.h that contains a data member of a container OrderedList, which will be used to store account records. Define member functions: loadData(const char *) will load Account record from a given textfile and store the records in the container of OrderedList. displayData() will use iterator of OrderedList object to traversal the DLL and display formatted output data of accounts. saveData(const char *) will save the accounts from DLL to a given binary file.Implement the member functions in a file AccountManagement.cpp.Download a file task2Main.cpp to test your task 2.Testing:Use CC to compile the source files byCC o task2 task2main.cpp Account.cpp Date.cpp AccountManagement.cppand run the program by ./task2 accounts.txt accounts.datThe output records on the screen can be found in a text file output2.txt.The input text file accounts.txt can be downloaded from Moodle. The sortedAccount records will be saved in a binary file accounts.dat.Note: Your solutions of task 2 should work on different testing data / files.Task3: STL map and iterator (3 marks)Use the source code files Date.h, Date.cpp, Account.h, and Account.cpp thatused in task 2.1. AccountMapDefine a class AccountMap in a file AccountMap.h. It contains a data member, which is a multimap container that can be used to store Account records. The key of the container is a char pointer of accounts name. You will define a comparison function CompareCharArrays to compare two char arrays in the file AccountMap.h for the multimap object. For example:multimap Define a destructor for the class AccountMap to release dynamic memory allocated for the container to avoid memory leaks.Define a member function loadData(const char *) for the class AccountMap that load account records from a given binary file (created in task2), insert the records into the multimap container.Define a member function displayData() for the class AccountMap that use iterator of the container to display all records.Implement the member functions in a file AccountMap.cpp.Download a file task3Main.cpp from Moodle to test your task 3.Testing:Use CC to compile the source files byCC o task3 task3Main.cpp Account.cpp Date.cpp AccountMap.cppand run the program by./task3 accounts.datThe binary file accounts.dat is generated by your task 2. The outputs of this tasklook like the results in a text file output3.txt.
.
Reviews
There are no reviews yet.