Question

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

n 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.

https://www.onlinegdb.com/online_c++_compiler

0 0
Add a comment Improve this question Transcribed image text
Answer #1

In the given code, in testDriver.cpp file two different dates are given ('today' and 'anotherDay').

To compile and execute the code:
command1 : generate the object code of DataType.cpp (creates DataType.o)
g++ -c DateType.cpp

command2 : generate the object code of testDriver.cpp (creates testDriver.o)
g++ -c testDriver.cpp

command3 : make executable file 'testdriver' by linking DataType.o and testDriver.o
g++ DateType.o testDriver.o -o testdriver

command4 : execute 'testdriver'
./testdriver

Code screenshot and output:

DateType.h

DateType.cpp

testDriver.cpp

Output file

As asked in the question, if we modify the dates, the modified dates will be printed.

Code:

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

#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

#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;
}

Add a comment
Know the answer?
Add Answer to:
n this programming assignment, you need to create 3 files. 1. DateType.h 2. DateType.cpp 3. A...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • 1.) Add a data member, currentTime into the DataType.h 2.) Add a member function, GetCurrentTime(). Modify...

    1.) Add a data member, currentTime into the DataType.h 2.) Add a member function, GetCurrentTime(). Modify the initialize function. ESIGN PAGE LAYOUT REFERENCES an-E4_]Ka"!Aa.le' | =.=-'E- 恒栏1순↓ | T Font Paragraph // 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; search

  • #include "stdafx.h" #include <iostream> using namespace std; class dateType {    private:        int dmonth;...

    #include "stdafx.h" #include <iostream> using namespace std; class dateType {    private:        int dmonth;        int dday;        int dyear;       public:       void setdate (int month, int day, int year);    int getday()const;    int getmonth()const;    int getyear()const;    int printdate()const;    bool isleapyear(int year);    dateType (int month=0, int day=0, int year=0); }; void dateType::setdate(int month, int day, int year) {    int numofdays;    if (year<=2008)    {    dyear=year;...

  • Can someone please help me. i keep getting an error in my code. I need it...

    Can someone please help me. i keep getting an error in my code. I need it to be on three seperate files! attached is my assignment and my code. c++ The class date Type implements the date in a program. Write the class functions as specified in the UML class diagram. The values for the month, day, and year should be validated (in the class functions) before storing the date into the data members. Set the invalid member data to...

  • Programming Exercise 11-8 PROBLEM:The class dateType defined in Programming Exercise 6 prints the date in numerical...

    Programming Exercise 11-8 PROBLEM:The class dateType defined in Programming Exercise 6 prints the date in numerical form. Some applications might require the date to be printed in another form, such as March 24, 2019. Derive the class extDateType so that the date can be printed in either form. Add a member variable to the class extDateType so that the month can also be stored in string form. Add a member function to output the month in the string format, followed...

  • The class dateType is designed to implement the date in a program, but the member function...

    The class dateType is designed to implement the date in a program, but the member function setDate and the constructor do not check whether the date is valid before storing the date in the data members. Rewrite the definitions of the function setDate and the constructor so that the values for the month, day, and the year are checked before storing the date into the data members. Add a function member, isLeapYear, to check whether a year is a leap...

  • Hello, I have a bug in my code, and when I run it should ask the...

    Hello, I have a bug in my code, and when I run it should ask the user to enter the month and then the year and then print out the calendar for the chosen month and year. My problem with my code is that when I run it and I enter the month, it doesn't ask me for the year and it prints all the years of the month I chose. Please help! Code: #include "calendarType.h" #include <iostream> using namespace...

  • C++ problem 11-6 In Programming Exercise 2, the class dateType was designed and implemented to keep...

    C++ problem 11-6 In Programming Exercise 2, the class dateType was designed and implemented to keep track of a date, but it has very limited operations. Redefine the class dateType so that it can perform the following operations on a date, in addition to the operations already defined: Set the month. Set the day. Set the year. Return the month. Return the day. Return the year. Test whether the year is a leap year. Return the number of days in...

  • Write a C++ Program. You have a following class as a header file (dayType.h) and main()....

    Write a C++ Program. You have a following class as a header file (dayType.h) and main(). #ifndef H_dayType #define H_dayType #include <string> using namespace std; class dayType { public:     static string weekDays[7];     void print() const;     string nextDay() const;     string prevDay() const;     void addDay(int nDays);     void setDay(string d);     string getDay() const;     dayType();     dayType(string d); private:     string weekDay; }; #endif /* // Name: Your Name // ID: Your ID */ #include <iostream>...

  • Show the compilation of Programming Challenge below in separate header and implementation files and show a...

    Show the compilation of Programming Challenge below in separate header and implementation files and show a UML diagram of this class. #include “Car.h” Int main() { Car car(2015, “Volkswagon”); Cout<<”Car’s Make: “ << car.getMake() <<endl; Cout<< “Car’s Year:” << car.getYear() <<endl; Cout<< “Car’s Speed : “ <<car.getSpeed()<<endl; Cout<< endl; For(int I =0; I < 5; i++) { Car.acceleration(); Cout<< “Speed after accelerate: “ << car.getSpeed() << endl; } For(int I = 0; i < 5; i++) { Car.brake(); Cout <<...

  • Assignment Overview In Part 1 of this assignment, you will write a main program and several...

    Assignment Overview In Part 1 of this assignment, you will write a main program and several classes to create and print a small database of baseball player data. The assignment has been split into two parts to encourage you to code your program in an incremental fashion, a technique that will be increasingly important as the semester goes on. Purpose This assignment reviews object-oriented programming concepts such as classes, methods, constructors, accessor methods, and access modifiers. It makes use of...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT