Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

C++ please The code for DateType.h, DateType.cpp, User.h, and User.cpp and located below instructions Implement SortedUserType as a class sorted user objects. Create and implement

C++ please

The code for DateType.h, DateType.cpp, User.h, and User.cpp and located below instructions

Implement SortedUserType as a class sorted user objects. Create and implement the specification file (SortedUserType.h) and implementation file (SortedUserType.cpp). The SortedUserType class uses NodeUser struct to create a node of a user in the list. For testing purposes, SortedUserType can store a maximum of 5 users (maxList). The user object will be inserted based on the increasing order of the users dateOfBirth.

(Struct) Implement NodeUser struct in the SortedUserType.h and SortedUserType.cpp.

NodeUser has two fields:

User userInfo; // data info

NodeUser* next; // pointer

(SortedUserType operations) the SortedUserType class has the following operation:

Normal operators:

  • (Constructor) SortedUserType ();
  • (Transformer) void ResetList();
  • (Transformer) void MakeEmpty();// delete all item in the list
  • (Observer) bool IsFull() const;
  • (Observer) int GetLength() const;

Pointer related operators:

  • (Observer) User* GetUser(User* aUser, bool& found) const; // get a user from the list whose firstName, lastName, and dateOfBirth match with aUser.
  • (Transformer) void PutUser(User* aUser); // put aUser in to the list according to dateOfBirth order.
  • (Transformer) void DeleteUser(User* aUser); // delete a user from the list whose firstName, lastName, and dateOfBirth match with aUser.
  • (Observer) User* GetNextUser(); // get the next user in the list

DateType.h

#include #include using namespace std;

enum RelationType {LESS, EQUAL, GREATER};

class DateType { public: void Initialize(int newMonth, int newDay, int newYear); int GetMonth() const; int GetYear() const; int GetDay() const; string GetMonthAsString() const; DateType Adjust(int daysAway) const; RelationType ComparedTo(DateType someDate) const; private: int year; int month; int day; };

DateType.cpp

#include "DateType.h" #include #include using namespace std;

static int daysInMonth[] = {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 }; // number of days in each month

static string conversionTable[] = { "Error", "January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December" }; //Names of months

void DateType::Initialize (int newMonth, int newDay, int newYear) { if (newMonth < 1 || newMonth > 12) throw string("Month is invalid"); else if (newDay < 1 || newDay > daysInMonth[newMonth]) throw string("Day is invalid"); else if (newYear < 1583) throw string("Year is invalid"); year = newYear; month = newMonth; day = newDay; }

int DateType::GetMonth() const //accessor function for data member month { return month; }

string DateType::GetMonthAsString() const // returns data member as a string { return conversionTable[month]; }

int DateType::GetYear() const // accessor function for data member year { return year; }

int DateType::GetDay() const // accessor function for data member day { return day; }

RelationType DateType::ComparedTo(DateType aDate) const { 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; }

DateType DateType::Adjust(int daysAway) const { int newDay = day + daysAway; int newMonth = month; int newYear = year; bool finished = false; int daysInThisMonth; DateType returnDate; while (!finished) { daysInThisMonth = daysInMonth[newMonth]; if (newMonth == 2) if (((newYear % 4 == 0) && !(newYear % 100 == 0)) || (newYear % 400 == 0)) daysInThisMonth++; if (newDay <= daysInThisMonth) finished = true; else { newDay = newDay - daysInThisMonth; newMonth = (newMonth % 12) + 1; if (newMonth == 1) newYear++; } }

returnDate.Initialize(newMonth, newDay, newYear); return returnDate; }

User.h

#include "DateType.h" #include

class User { private: char firstName[7], lastName[7]; DateType date;

public: User(); void Initialize(char firstName[7], char lastName[7], DateType date); RelationType comparedTo(User* aUser) const; string ToString(); };

User.cpp

#include "User.h"

User::User() { strcpy(firstName, ""); strcpy(lastName, ""); date.Initialize(10, 21, 1999); } //initialize a user object with given values. void User::Initialize(char firstName[7], char lastName[7], DateType date) { strcpy(this->firstName, firstName); strcpy(this->lastName, lastName); this->date = date; } //compare the self user with aUser RelationType User::comparedTo(User* aUser) const { if (this->comparedTo(aUser) == LESS) { return LESS; } else if (this->comparedTo(aUser) == GREATER) { return GREATER; } else { return EQUAL; } } //returns a string that contains all information of the user string User::ToString() { return string(firstName) + " " + string(lastName) + ", DOB: " + date.GetMonthAsString() + " " + to_string(date.GetDay()) + ", " + to_string(date.GetYear()); }

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Temporal Databases Research And Practice Lncs 1399

Authors: Opher Etzion ,Sushil Jajodia ,Suryanarayana Sripada

1st Edition

3540645195, 978-3540645191

More Books

Students also viewed these Databases questions

Question

What is the purpose of the postclosing trial balance?

Answered: 1 week ago

Question

2. What type of team would you recommend?

Answered: 1 week ago

Question

What was the role of the team leader? How was he or she selected?

Answered: 1 week ago