Question

In: Computer Science

In this programming assignment, you need to create 3 files. 1. DateType.h 2. DateType.cpp 3. A...

In this programming assignment, you need to create 3 files.

1. DateType.h

2. DateType.cpp

3. A test driver for testing the class defined in the other 2 files. You can name your file in the way you like. Remember it must be a .cpp file.

In DateType.h file, type these lines:

// To declare a class for the Date ADT // This is the header file DateType.h

class DateType

{
public:

void Initialize(int newMonth, int newDay, int newYear); int GetYear() const;
int GetMonth() const;
int GetDay() const;

private:
int year;

int month;

int day; };

// Class implementation // DateType.cpp

#include "DateType.h"

void DateType::Initialize(int newMonth, int newDay, int newYear)

{
year = newYear;

month = newMonth;

day = newDay; }

int DateType::GetMonth() const

{
return month;

}

In DateType.cpp file, type these lines:

int DateType::GetDay() const

{
return day;

}

int DateType::GetYear() const

{

return year; }

In you test driver, type in these lines:

// test driver
// I give the file name: testDriver.cpp
// To compile, type c++ DataType.cpp testDriver.cpp, this will generate an a.out executable.
// Or, type c++ Type.cpp testDriver.cpp –o testdriver, this will generate an executable named testdriver.

#include "DateType.h" #include <iostream>

using namespace std;

int main()

{
DateType today;

DateType anotherDay; today.Initialize(9, 24, 2003); anotherDay.Initialize(9, 25, 2003);

cout << "Today is " << today.GetMonth() << "/" << today.GetDay() << "/" << today.GetYear() << endl;

cout << "Anotherday is " << anotherDay.GetMonth() << "/" << anotherDay.GetDay() << "/" << anotherDay.GetYear() << endl;

return 0; }

Once you have the 3 files ready, you can compile them. The compile command is in the comments of the test driver.

After the compilation, you run the program, and see what output you get.
Now, modify the code to initialize 2 different dates, compile and run it, and see what the output is.

Solutions

Expert Solution

If you have any doubts, please give me comment...

DateType.h

// To declare a class for the Date ADT // This is the header file DateType.h

class DateType

{

public:

    void Initialize(int newMonth, int newDay, int newYear);

    int GetYear() const;

    int GetMonth() const;

    int GetDay() const;

private:

    int year;

    int month;

    int day;

};

DateType.cpp

// Class implementation // DateType.cpp

#include "DateType.h"

void DateType::Initialize(int newMonth, int newDay, int newYear)

{

    year = newYear;

    month = newMonth;

    day = newDay;

}

int DateType::GetMonth() const

{

    return month;

}

int DateType::GetDay() const

{

    return day;

}

int DateType::GetYear() const

{

    return year;

}

testDriver.cpp

// To compile, type g++ DateType.cpp testDriver.cpp, this will generate an a.out executable.

// Or, type g++ DateType.cpp testDriver.cpp –o testdriver, this will generate an executable named testdriver.

#include <iostream>

#include "DateType.h"

using namespace std;

int main()

{

    DateType today;

    DateType anotherDay;

    today.Initialize(3, 20, 2003);

    anotherDay.Initialize(9, 13, 2006);

    cout << "Today is " << today.GetMonth() << "/" << today.GetDay() << "/" << today.GetYear() << endl;

    cout << "Anotherday is " << anotherDay.GetMonth() << "/" << anotherDay.GetDay() << "/" << anotherDay.GetYear() << endl;

    return 0;

}

Ouput:

After changing dates in testDriver.cpp


Related Solutions

In this programming assignment, you will implement a SimpleWebGet program for non- interactive download of files...
In this programming assignment, you will implement a SimpleWebGet program for non- interactive download of files from the Internet. This program is very similar to wget utility in Unix/Linux environment.The synopsis of SimpleWebGet is: java SimpleWebGet URL. The URL could be either a valid link on the Internet, e.g., www.asu.edu/index.html, or gaia.cs.umass.edu/wireshark-labs/alice.txt or an invalid link, e.g., www.asu.edu/inde.html. ww.asu.edu/inde.html. The output of SimpleWebGet for valid links should be the same as wget utility in Linux, except the progress line highlighted...
For our current programming assignment I need to create a CleanWord method that reads in one...
For our current programming assignment I need to create a CleanWord method that reads in one variable string at a time and returns a cleaned word without any non letters. The instructions given to us are listed below: “Clean word” method:  This is to be implemented as a separate method, so it can be called for either a dictionary word or book word.  The function will remove any non-letters, except an apostrophe (‘) and numbers from the word....
Modify programming problem 4 from Assignment 2. You will create a number of threads—for example, 100—and...
Modify programming problem 4 from Assignment 2. You will create a number of threads—for example, 100—and each thread will request a pid, sleep for a random period of time, and then release the pid. (Sleeping for a random period of time approximates the typical pid usage in which a pid is assigned to a new process, the process executes and then terminates, and the pid is released on the process's termination.) On UNIX and Linux systems, sleeping is accomplished through...
PROGRAMMING LANGUAGE : JAVA Problem specification. In this assignment, you will create a simulation for a...
PROGRAMMING LANGUAGE : JAVA Problem specification. In this assignment, you will create a simulation for a CPU scheduler. The number of CPU’s and the list of processes and their info will be read from a text file. The output, of your simulator will display the execution of the processes on the different available CPU’s. The simulator should also display: -   The given info of each process -   CPU utilization - The average wait time - Turnaround time for each process...
JAVA PROGRAMMING. In this assignment, you are to create a class named Payroll. In the class,...
JAVA PROGRAMMING. In this assignment, you are to create a class named Payroll. In the class, you are to have the following data members: name: String (5 pts) id: String   (5 pts) hours: int   (5 pts) rate: double (5 pts) private members (5 pts) You are to create no-arg and parameterized constructors and the appropriate setters(accessors) and getters (mutators). (20 pts) The class definition should also handle the following exceptions: An employee name should not be empty, otherwise an exception...
................................................ ................................................ This programming lab assignment requires that you create a class and use an equals...
................................................ ................................................ This programming lab assignment requires that you create a class and use an equals method to compare two or more objects. Your should use your QC5 as a reference. …………………………...…….. …………………………...……. Instructions LAB5 Instructions Using QC5 as a model, create a Rectangle class and a CompareUsingequalsMethod class that uses an   equals Method to determine if two rectangles are equal if and only if their areas are equal. The Rectangle class should have two instance variables length and width....
For this assignment you are expected to submit the following two files: 1. ????ℎ??????ℎ??????. ℎ 2....
For this assignment you are expected to submit the following two files: 1. ????ℎ??????ℎ??????. ℎ 2. ????ℎ??????ℎ??????. ??? You are being asked to write a class for simple weather data storage. Each instance of the class will hold data for exactly one month (30 days). Each day’s weather will be classified as either rainy (‘R’), cloudy (‘C’), or sunny (‘S’). To achieve this, your class will contain a character array of length 30. The class will provide three functions to...
Programming Assignment #3: SimpleFigure and CirclesProgram Description:This assignment will give you practice with value...
Programming Assignment #3: SimpleFigure and CirclesProgram Description:This assignment will give you practice with value parameters, using Java objects, and graphics. This assignment has 2 parts; therefore you should turn in two Java files.You will be using a special class called DrawingPanel written by the instructor, and classes called Graphics and Color that are part of the Java class libraries.Part 1 of 2 (4 points)Simple Figure, or your own drawingFor the first part of this assignment, turn in a file named...
C++ question. Need all cpp and header files. Part 1 - Polymorphism problem 3-1 You are...
C++ question. Need all cpp and header files. Part 1 - Polymorphism problem 3-1 You are going to build a C++ program which runs a single game of Rock, Paper, Scissors. Two players (a human player and a computer player) will compete and individually choose Rock, Paper, or Scissors. They will then simultaneously declare their choices and the winner is determined by comparing the players’ choices. Rock beats Scissors. Scissors beats Paper. Paper beats Rock. The learning objectives of this...
Java Programming In this assignment we are going to create our own programming language, and process...
Java Programming In this assignment we are going to create our own programming language, and process it Java. programming language has 6 commands enter add subtract multiply divide return enter, add, subtract, multiply, divide all take 1 parameter (a double value). return takes no parameters.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT