Program on lexicographical order, C/C++ Programming

Assignment Help:

Introduction. In this assignment you are required to revisit the Assignment 1 topic. You will develop a new program which is more sophisticated, in particular, adding more functionality to its Programming2Student and Programming2Class classess. Also, you are asked to develop more sophisticated TestProgram.cpp.

Topics covered in this assignment include:

  • operator overloading;
  • storing/reading information in/from a binary file;
  • STL containers - map and set;

1. Class Programming2Student.

Here is the new header file for the Programming2Student class:

#ifndef STUDENT_H

#define STUDENT_H

#include

#include

#include

using namespace std;

class Student{

public:

Student();

Student(string name,string surname,int a1, int a2, int test, int exam);

string getName()const;

string getSurname()const;

int getAssignment1Mark()const;

int getAssignment2Mark()const;

int getLabTestMark()const;

int getExamMark()const;

void setAssignment1Mark(int);

void setAssignment2Mark(int);

void setLabTestMark(int);

void setExamMark(int);

bool passed()const;

string getGrade()const;

friend ostream& operator<<(ostream& stream, const Student &);

bool operator<(const Student &)const;

private:

string name;

string surname;

int assignment1Mark;

int assignment2Mark;

int labTestMark;

int examMark;

};

#endif

You are required to implement the class, i.e. to develop the implementation file

"Programming2Student.cpp" that conforms to the following specifications:

(1) The data fields, "get" and "set" functions, functions getGrade() and passed() are defined in the same way as in Assignment 1 (please consult Assignment 1 specifications).

 (2) friend ostream& operator<<(ostream& stream, const Programming2Student &) - the function overloads << operator, which allows to output a Programming2Student object information in the following format:

Underwood Scott:

Assignment 1 8

Assignment 2 16

Lab Test 0

Exam 34

Grade P

 (3) bool operator<(const Student &student)const - the function overloads < operator, which allows to compare student's full names lexicographically.

2. Class Programming2Class.

The class has the following header file. Objects of this class represent Programming2 teaching classes (student groups).

#ifndef PROGRAMMING2CLASS_H

#define PROGRAMMING2CLASS_H

#include "Programming2Student.h"

#include

#include

#include

class Programming2Class{

public:

Programming2Class();

Programming2Class(int dummy);

Programming2Class(set*);

~Programming2Class();

void addStudent(Programming2Student*);

map* getGroup();

void save();

private:

map* group;

};

#endif

You are required to implement the class, i.e. to develop the implementation file

"Programming2Class.cpp" that conforms to the following specifications:

(1) The only field of the class is a pointer to a "map" object representing a teaching group(or class), which is a map (an associative STL container) that contains the pairs:Key: a student's full name (i.e. name + " " + surname)

Value: corresponding Student object.

In this assignment you should assume that there are no different students with identical full names in Programming2 teaching classes.

(2) void addStudent(Programming2Student* studentPtr)- the function adds the pair

Key: (*studentPtr) student's full name

Value: (*studentPtr)

To the (*group) map;

Please note that instead of actual objects you are supposed to use pointers as function parameters.

 (3) void save()- the function writes the Programming2Student objects stored as values in the (*group) map to the "Programming2Students.bin" file. "Programming2Students.bin" is a binary file, and you are required to write the objects to the file using something like out.write(reinterpret_cast(s), sizeof(Programming2Student));

 (4) Constructor Programming2Class() and the destructor:

A default constructor initializes dynamically the group field.

The destructor deletes the group pointer.

[0.5×2 = 1 mark]

(5) Constructor Programming2Class(int dummy):

This constructor does not require any parameter. However, to distinguish it from the default constructor you should use some dummy argument (say of int type). This constructor opens the

"Programming2Students.bin" file, if such file exists, and reads information from the file into the

(*group) map using addStudent() function. If the file "Programming2Students.bin" does not exist, the constructor behaves as the default constructor.

 (6) Constructor Programming2Class(set* students):

This constructor takes a set of Programming2Student objects (in fact, a pointer to the set) as an argument and adds students from the set to the (*group) map, i.e. initializes the group field.

3. TestAssignment2.cpp

This is a test program that tests the Programming2Student and Programming2Class classes.

In this assignment you are provided with three input text files associated with this program:

  • firstNamesBoys.txt - contains first names for boys
  • firstNamesGirls.txt - contains first names for girls
  • lastNames.txt - contains last names

Each of these input files contains one name per line. Hence "firstNamesBoys.txt" will contain one boy's name per line, and "lastNames.txt" contains one surname per line. These input files will be used to create a random set of Programming2Student objects to test your application.

The test program should conform to the following specifications:

(1) There are three three global variables declared in the program:

vector* names = new vector();

vector* surnames = new vector();

set* students = new set();

(2) The test program should define a function with the following prototype:

void readInputFiles();

This function does the following:

  • Opens and reads firstNamesBoys.txt. Each name should be read into a string and added to the vector* names.
  • Opens and reads firstNamesGirls.txt. Each name should be read into a string and added to the vector* names.
  • Opens and reads firstNamesGirls.txt. Each name should be read into a string and added to the vector* surnames.

 (3) The test program should define a function with the following prototype:

void createRandomStudentSet(int n);

This function creates Student objects choosing values for their fields randomly:

  • Value for name is chosen randomly from the vector (*names).
  • Value for surname is chosen randomly from the vector (*surnames).
  • Values for the rest of fields are chosen randomly from the corresponding ranges, e.g. value for the examMark is a random value from 0 to 50.

If thus created Programming2Student object has passed the unit it is added to the (*students) set (an associative container from STL). You should continue adding random Student objects to the set until the total number of Student objects in the set is n.

 (4) The main function performs the following tasks:

  • Invokes consecutively functions readInputFiles(), createRandomStudentSet(12).
  • Then creates a Programming2Class object (or a pointer to the object) using the constructor Programming2Class(students), and saves it (to the file "Programming2Students.bin").
  • Creates another Programming2Class object using the constructor with a "dummy" parameter and prints down information of the Programming2Student objects from the (*group) map field of the class.

The following is a sample output of the test program (number of students is 5):

Adams Tiana:

Assignment 1 17

Assignment 2 5

Lab Test 4

Exam 34

Grade C

Barley Tia:

Assignment 1 9

Assignment 2 19

Lab Test 5

Exam 41

Grade D

Cameron Trent:

Assignment 1 19

Assignment 2 10

Lab Test 4

Exam 41

Grade D

Cannon Isabel:

Assignment 1 17

Assignment 2 19

Lab Test 8

Exam 25

Grade C

Davis Chelsea:

Assignment 1 3

Assignment 2 19

Lab Test 6

Exam 40

Grade C

Note that the student names are printed in lexicographical order.

Assignment must be submitted by the due date (check Unit Description for Details). Assignment must contain

  • A floppy disk or CDROM with your C++ project.
  • A report containing

o A title page with your name, class, tutor's name and acknowledgement of any assistance

o Hard Code for each of your authored classes

o Readable documentation for all classes

This assignment is worth 20 marks. Up to 2 marks could be deducted for poor code and design.

Any outside help must be fully acknowledged. You must acknowledge from whence you got the help and exactly what form this help took. This help should not be in the form of large blocks of code. Any unacknowledged assistance will be severely penalised.

 


Related Discussions:- Program on lexicographical order

Board coloring, color representation 0,1,2,3,4,5,6,7...

color representation 0,1,2,3,4,5,6,7...

Write a program that finds the minimum total number of shelv, At a shop of ...

At a shop of marbles, packs of marbles are prepared. Packets are named A, B, C, D, E …….. All packets are kept in a VERTICAL SHELF in random order. Any numbers of packets with thes

Boardcoloring, color representation 0,1,2,3,4,5,6,7,.......

color representation 0,1,2,3,4,5,6,7,.......

Describe what are dynamic pointers, Question: (a) Describe what are dy...

Question: (a) Describe what are dynamic pointers. Show their memory representations diagrammatically. (b) Write short notes about pointers in arrays, paying attention on

File Input and Output, Given a bool variable isReadable write some statem...

Given a bool variable isReadable write some statements that assign true to isReadable if the file "topsecret" exists and can be read by the program and assigns false to isR

Define the modulo division operator in c language, Define the Modulo Divisi...

Define the Modulo Division Operator in c language? The C provides one more arithmetic operator % called as modulo division operator and this operator yields the remainder of an

#tit, Write a program to find the area under the curve y = f(x) between x =...

Write a program to find the area under the curve y = f(x) between x = a and x = b, integrate y = f(x) between the limits of a and b. The area under a curve between two points can b

Prepare a script for providing instagram followers, Prepare a script for pr...

Prepare a script for providing Instagram Followers/Likes I need to prepare a panel where my customer able to get Instagram followers or likes automatically. - A panel where I

Write Your Message!

Captcha
Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd