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

1. Copy the files from Assignment 1 to Assignment 2. Relabel as necessary 2. Create 3...
1. Copy the files from Assignment 1 to Assignment 2. Relabel as necessary 2. Create 3 instances of the PetFoodCompany class - dogFoodMaker, catFoodMaker, fishFoodMaker. 3. Internally set the division name for each instance. (I.E. "Alpo" for dogFoorMaker, "Purina" for CatFoodMaker, "GloFish" for fishFoodMater) 4. Prompt me to enter the Company Name and Quarter only once. 5. For each of the above instances, prompt me for total sales and total expenses. A loop is not expected. 6. For each instance...
1. Copy the files from Assignment 1 to Assignment 3. 2. Modify the PetFoodCompany header to...
1. Copy the files from Assignment 1 to Assignment 3. 2. Modify the PetFoodCompany header to mention a friend function called "computeBonusBudget". This method should compute the bonus budget as netIncome() * BonusBudgetRate and this method should exist in the driver program - not the Class defintion. 3. Modify the output of the program to display the results of the computeBonusBudget. Enter Total Sales: 1000 Enter Total Expenses: 600 Net Income = 400 Bonus Budget = 8 Here is the...
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....
Write a program: For this assignment, you will need to write three source code files as...
Write a program: For this assignment, you will need to write three source code files as well as two header files. Each of these files is relatively short, but many inexperienced programmers are overwhelmed by the idea of writing a program as multiple files. "Where do I start?!!" is a common refrain. This assignment sheet attempts to walk you through the steps of writing a multi-file program. The steps outlined below should not be thought of as a purely linear...
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...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT