Question

In: Computer Science

(Problem is from the textbook Data Structures using C++) Add a function to the dateType class....

(Problem is from the textbook Data Structures using C++)

Add a function to the dateType class.

The function's name is compareDates.

Its prototype is

int compareDates(const dateType& otherDate;

The function returns -1 if otherDate is greater than than this date

The function returns 0 if otherDate equals this date

The function returns 1 if otherDate is less than this date

Examples

dateType d1(1, 1, 2019);

dateType d2(11,1, 2019)

d1.compareDates(d2) returns -1

d2.compareDates(d1) returns 1

d2.compareDates(d2) returns 0

<<<<< dateType.h >>>>>>

#ifndef H_addressType

#define H_addressType

#include

#include

using namespace std;

class addressType

{

public:
void setStreet(string myStreet);
void setCity(string mCity);
void setState(string myState);
void setZIP(int myZIP);

string getStreet() const;

string getCity() const;

string getState() const;

int getZIP() const;

void printAddress() const;

addressType(string = "", string = "", string = "",

int = 0);

private:

string street;

string city;

string state;

int ZIP;

}

#endif

void addressType::setStreet(string myStreet)

{

street = myStreet;

} // end function setStreet

void addressType::setCity(string myCity)

{

city = myCity;

} // end function setCity

void addressType::setState(string myState)

{

state = myState;

} // end functioni setState

void addressType::setZIP(int myZIP)

{

ZIP = myZIP;

} // end function setZIP

string addressType::getStreet() const
{
return street;
} // end function getStreet

string addressType::getCity() const

{

return city;

} // end function getCity

string addressType::getState() const

{

return state;

} // end function getState

int addressType::getZIP() const

{
return ZIP;

} // end function getZIP

void addressType::printAddress() const

{

cout << "\n\t" << getStreet() << ", " << getCity()

<< "\n\t" << getState() << " - " << getZIP();

} // end function printAddress

addressType::addressType(string myStreet, string myCity,

string myState, int myZIP)

{

setStreet(myStreet);

setCity(myCity);

setState(myState);

setZIP(myZIP);

} // end constructor addressType

Solutions

Expert Solution

hi i have answered your question hope this will be helpful to you as i need to run the program and verify hence i have make a seprate class and function there so you too can verify the function if it working as expected ,hope you will understand , kindly give a thumbs up , and if need any clarification you can comment i will reply accordingly.

code:-

#include<iostream>
using namespace std;

class dateType
{
int day;
int month;
int year;
public:
int compareDates(const dateType& otherDate); //Function Prototype to compare date
dateType(int d,int m,int y) { // constructor to set the values of the variable so we ever a object will be creat this will set the value
this->day= d;
this->month= m;
this->year=y;
}
  
};
int dateType :: compareDates(const dateType& obj) { // Function to compare the dates comapring each day month and year
if(this->day== obj.day && this->month == obj.month && this->year == obj.year)
return 0;
else if(this->year <= obj.year && this->month <= obj.month && this->day < obj.day)
return -1;
else
return 1;
}
int main()
{
dateType d1(1,1,2019),d2(11,1,2019); //Creating objectes of the datetypes class
int res = d1.compareDates(d2);
cout<<"res is "<<res<<endl;
res = d2.compareDates(d1);
cout<<"res is "<<res<<endl;
res = d2.compareDates(d2);
cout<<"res is "<<res<<endl;
return 0;
}

output:-

\\\

happy to help :).


Related Solutions

Solve problem (P4.2) from the textbook using the following data instead of the data given in...
Solve problem (P4.2) from the textbook using the following data instead of the data given in the textbook. Solve only requirements under a, b and c. Show your assumptions and consequent calculations on how you catered for the fact that 1997 means first half of the year and 1997.5 means in the second half of the year; without such initial, your solution will not be considered as your own.   (Hint: you may use Excel or any software to conduct linear...
Write a C++ PROGRAM: Add the function min as an abstract function to the class arrayListType...
Write a C++ PROGRAM: Add the function min as an abstract function to the class arrayListType to return the smallest element of the list. Also, write the definition of the function min in the class unorderedArrayListType and write a program to test this function.
MUST BE DONE IN C (NOT C++) In this task, using a function, we will add...
MUST BE DONE IN C (NOT C++) In this task, using a function, we will add a range of values of an array. The range will be determined by the user. For example, if I have the following array … 1.5 -5.6 8.9 4.6 7.8 995.1 45.1 -5964.2 … and the user tells me to add from the 3rd element to the 6th element, my program would add the values 8.9, 4.6, 7.8 and 995.1. To do so, please follow...
C# Programming (Class Registration class) Add a Schedule property to the Person class. Add a new...
C# Programming (Class Registration class) Add a Schedule property to the Person class. Add a new behavior as well: add(Section s) this behavior will add a section to the Person’s schedule. The Person’s display() function will also need to be modified to display() the Person’s Schedule. Schedule class has Properties: An array of Sections and a Count. Constructors: only a default constructor is needed. Behaviors: add() and display(). This is my schedule class class Schedule     {         private int...
In C programming Generalize the to binary() function of Listing 9.8 (from your textbook) to a...
In C programming Generalize the to binary() function of Listing 9.8 (from your textbook) to a to base n(number, base) function that takes a second argument in the range 2–10. It then should convert (and print) the number that is its first argument to the number base given by the second argument. For example, to base n(129,8) would display 201, the base-8 equivalent of 129. Test the function in a complete program.
Working on a c++ data structures assignment.   Linked List add node. I have the head case...
Working on a c++ data structures assignment.   Linked List add node. I have the head case and the tail case working but the middle/general case I can not get to work for the life of me. I have included the header file and the data struct file below   #ifndef LINKEDLIST_H #define LINKEDLIST_H #include "data.h" #include <iostream>   //take this out using std::cout; class LinkedList{     public:         LinkedList();         ~LinkedList();         bool addNode(int, string);         bool deleteNode(int);         bool getNode(int, Data*);         void printList(bool = false);         int getCount();         void...
Using the data in Appendix C in the textbook and given the pressures listed, calculate ΔG...
Using the data in Appendix C in the textbook and given the pressures listed, calculate ΔG for each of the following reactions at 298 K. Part A) N2(g)+3H2(g)→2NH3(g) Part B) N2(g)+3H2(g)→2NH3(g) PN2 = 2.5 atm , PH2 = 7.2 atm , PNH3 = 1.7 atm Part C) 2N2H4(g)+2NO2(g)→3N2(g)+4H2O(g) Part D) 2N2H4(g)+2NO2(g)→3N2(g)+4H2O(g) PN2H4=PNO2=1.0×10−2atm, PN2 = 2.0 atm , PH2O = 1 atm Part E) N2H4(g)→N2(g)+2H2(g) Part F) N2H4(g)→N2(g)+2H2(g) PN2H4 = 0.6 atm , PN2 = 7.2 atm , PH2 = 9.1...
C++ Build a binary tree using a binary tree class member function from the following array...
C++ Build a binary tree using a binary tree class member function from the following array of preorder traversal 3,9,20,15,7 and inorder traversal 9,3,15,20,7. Implement the constructor, destructor and all member functions including print postorder traversal of the binary tree.
QA: (inspired by a problem from Stewart’s textbook) Suppose that there is some function f whose...
QA: (inspired by a problem from Stewart’s textbook) Suppose that there is some function f whose _derivative_ is f ’ =sin(x)/x, with f ‘(0)=1 by definition rather than DNE. Draw that, on the interval [-4pi,+4pi]. (i) On what intervals is the original f increasing? Decreasing? Indicate the intervals on the graph as well as writing them in interval notation like [0,pi] (ii) At what x values does f have a local max? A local min? Indicate them on the graph...
In this lab, using C++, you will create two data structures: a stack and a queue....
In this lab, using C++, you will create two data structures: a stack and a queue. You will use STL containers to demonstrate basic ADTs. Queue For the queue, you will simulate a buffer. Remember it is first-in-first-out. The user will enter a number for the number of rounds to run your simulation. You need one function that randomly generates a number. You will also have a user specified percentage, and the function uses this percentage to randomly put the...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT