Question: Done in C++ (Class) Implement a User class. Create the specification file (User.h) and implementation file (User.cpp). User class has the following attributes: char firstN
Done in C++
(Class) Implement a User class. Create the specification file (User.h) and implementation file (User.cpp). User class has the following attributes: char firstName[6]; char lastName[6]; and dateOfBirth as DateType. The following constructor and functions must be implemented in the User class:
- Default constructor User()
- Void Initialize( char firstName[6], char lastName[6], DateType date): this function is to initialize a user object with given values.
- RelationType comparedTo(User* aUser) const: this function compare the self user with aUser and return a ReliationType value. It must call the CompareTo(DateType aDate) function of the DateType class (see case study in chapter 2). The rule of comparison and returning values is as follow:
- Returns LESS: if CompareTo(DateType aDate) returns LESS
- Return GREATER: if CompareTo(DateType aDate) returns GREATER
- Return EQUAL: if (both self user with aUser object have same firstName and lastName) and CompareTo(DateType aDate) returns EQUAL
(Note that the RelationType is defined as an enum: enum RelationType{LESS, EQUAL, GREATER} )
- string ToString(): this function returns a string that contains all information of the user (firstName, lastName, and dateOfBirth).
Case study code:
RelationType DateType::ComparedTo(DateType aDate) const /* Pre: self and aDate have been initialized post: function value = LESS, if self comes before aDate. = EQUAL, if self is the same as aDate. = GREATER, if self comes after aDate. */ { if (year < aDate.year) return LESS; else if (year > aDate.year) return GREATER; else if (month < aDate.month) return LESS; else if (month > aDate.month) return GREATER; else if (day < aDate.day) return LESS; else if (day > aDate.day) return GREATER; else return EQUAL; }
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
