CS211 Homework 4 Solved

Original price was: $40.00.Current price is: $35.00.



5/5 - (1 vote)

The aim of this homework assignment is to practice using a class written by someone else and use dynamic allocation. This homework assignment will also help build towards project 1, which will be to write a program implementing the Roster Management Program.


For this assignment, write a program that uses the class Date. As an added challenge, I will not provide you with the .cpp file for this class, rather, only the .o file, to which you can link your program for testing purposes.


Write a program that does the following:

  1. Ask the user for a number that is going to be the size of the Date list.
    2. Create a list of Date type by storing the date instances in the dynamic array and populate the array with user input.
    3. Corresponding to each date there is a number that is between 1 to 9. The number is calculated in the following way: you add each digit of the day, month, and year and keep adding the digits of the answer until you get a single digit. Example: Feb 3, 2006 corresponds to (2 + 3 + 2 + 0 + 0 + 6) = 13 => 1 + 3 = 4
    4. Create an array of integers that would store integer representation of the date instances stored in the Date array
    5. Print out all the Dates and corresponding integers.
    6. Make sure to delete the dynamically allocated arrays before terminating the program.

Note that you do not need to know the implementation of the Date class.

In order to compile your program and link it to my Date class you will need to do the following:

1. Before you begin writing any program, make a copy of the Date.h file into your directory. Do this by typing the following (note the . at the end):
cp ~alayev/cs211/fall2022/hw4/Date.h .
2. Write your program.
3. Compile your program using the following (to link to my .o file)
g++ main.cpp ~alayev/cs211/fall2022/hw4/Date.o

Note that you may copy the Date.o file to your local directory; however, this is not necessary, and will use up valuable space on your venus/mars account. Note further that this .o file will only work on venus/mars, it will not work on other UNIX systems or on Windows.


Submit this program to your lab instructor following his instructions. If you find any bugs with the code, please do not hesitate to e-mail me.



Due Date: November 8





/* Date.h
* Declaration of the class that holds a date,
* which is a month-day-year combination.
* Author: Yosef Alayev
#ifndef DATE_H
#define DATE_H
#include <string>
using namespace std;
class Date {
// Initializes a date to the default value of January 1, 1970.

// Initializes a date to the values in the parameters.  If the
//date is not legal, sets the date to one of the legal values.
Date(int m, int d, int y);

// Returns the month stored by the class
string getMonth() const;

// Returns the month stored by the class as a number
int getMonthNum() const;

// Returns the day stored by the class
int getDay() const;

// Returns the year stored by the class
int getYear() const;

// solicit the date from the user
void input();

// output the date in a nice format
void output() const;

int month, day, year;
void adjust();