Question

Write the code using C++ ( from the TEXTBOOK Data Structure using C++) Add a function...

Write the code using C++ ( from the TEXTBOOK Data Structure 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

Homework Answers

Answer #1

int compareDates(const dateType& otherDate) {

if (this->day == otherDate.day && this->month == otherDate.month && this->year == otherDate.year) {

return 0;

}

if (this->year > otherDate.year) {

return 1;

} else if (this->year < otherDate.year) {

return -1;

} else {

if (this->month > otherDate.month) {

return 1;

} else if (this->month < otherDate.month) {

return -1;

} else {

if (this->day > otherDate.day) {

return 1;

} else if (this->day < otherDate.day) {

return -1;

} else {

return 0;

}

}

}

}

Know the answer?
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
Similar Questions
C++ Write a function that returns a string of 1's and 0's. This needs to be...
C++ Write a function that returns a string of 1's and 0's. This needs to be the binary representation of a number. Do not use loops. Use only recursion. Do not change the function's parameters or add more parameters. Do not change the main program. #include #include string bin(int number) { //Code here } int main() {    cout << bin(43) << endl; // Should be 101011    return 0; }
In main.cpp, write a templated function more which takes in two variables of the same type...
In main.cpp, write a templated function more which takes in two variables of the same type and returns whichever variable is greater than (>) the other. You can and may need to add something to the food class in order for more to be able to be called properly. //food.h #ifndef _FOOD_H #define _FOOD_H #include <iostream> #include <string> using namespace std; class Food { private: string name; int quantity; public: Food(); void setName(string newName); void setQuantity(int newQuantity); string getName(); int...
C++ //StudentDataStructure.txt //Student records are stored in a parallel-array Data Structure. Here is the code to...
C++ //StudentDataStructure.txt //Student records are stored in a parallel-array Data Structure. Here is the code to generate and populate Parallel-Array Data Structure: const int NG = 4; //Number of Grades string names[] = {"Amy Adams", "Bob Barr", "Carla Carr", "Dan Dobbs", "Elena Evans" }; int exams[][NG]= { {98,87,93,88}, {78,86,82,91}, {66,71,85,94}, {72,63,77,69}, {91,83,76,60} };    --------------------------------------------------------------------------------- 1 A) Create and Populate a Parallel-Array Data Structure using the code described in "StudentDataStructure.txt". B) Define a Record Data Structure for student records. It...
1. Please write the following in C++ also please show all output code and comment on...
1. Please write the following in C++ also please show all output code and comment on code. 2. Also, use CPPUnitLite to write all test and show outputs for each test. Write CppUnitLite tests to verify correct behavior for all the exercises. The modifications are aimed at making the exercises more conducive to unit tests. Write a function that swaps (exchanges the values of two integers). Use int* as the argument type. Write a second swap function using a reference...
Using c++ You may #include only: <iostream> <cmath> “functions.h” Write the function void readForceValuesFromStdIn(double* leftTeam, double*...
Using c++ You may #include only: <iostream> <cmath> “functions.h” Write the function void readForceValuesFromStdIn(double* leftTeam, double* rightTeam, unsigned const int noParticipants) that will read the list of forces exerted by each wizard alternating by the team into the correct array of doubles (see example in problem description) Define the function bool validForces(const double* forces, unsigned const int noParticipants) using the provided code. This function will be used to ensure that the forces exerted by each team’s wizard are non-negative The...
// Write a function that returns 0 if x is 0, returns -1 // if x...
// Write a function that returns 0 if x is 0, returns -1 // if x < 0, returns 1 if x > 0 // Your code must follow the Bit-Level Integer Coding Rules // on the textbook (located between hw 2.60 and 2.61). // You can assume w = 32. // The only allowed operations in your code are: // ! ~ & ^ | + << >> // This requirement is more restrictive than the coding rules. //...
Write ARMv8 Assembly code and C++ code for a function called int grade(int n) that returns...
Write ARMv8 Assembly code and C++ code for a function called int grade(int n) that returns the character 'A' if n >= 90, 'B' if 90 > n >= 80, etc. (Use the ASCII code.)
USING JAVA: I was asked to write a function that obtains a name from the user...
USING JAVA: I was asked to write a function that obtains a name from the user and returns it in reverse order (So if the user inputs "MIKE" the function returns "EKIM"). You can't use string variables it can only be done using a Char Array. Additionally, you can use a temporary Char Array but you are supposed to return the reverse order in the same char array that the user input, this is for hypothetical cost purposes -we are...
IN C PROGRAMMING A Tv_show structure keeps track of a tv show’s name and the channels...
IN C PROGRAMMING A Tv_show structure keeps track of a tv show’s name and the channels (integer values) that broadcast the show. For this problem you can ONLY use the following string library functions: strcpy, strlen, strcmp. You MAY not use memcpy, memset, memmove. You can assume memory allocations are successful (you do not need to check values returned by malloc nor calloc). typedef struct tv_show { char *name; int num_channels, *channels; } Tv_show; a. Implement the init_tv_show function that...
FOR C PROGRAMMING LANGUAGE Write a recursive C PROGRAMMING LANGUAGE function int sumStrlens(const char* str1, const...
FOR C PROGRAMMING LANGUAGE Write a recursive C PROGRAMMING LANGUAGE function int sumStrlens(const char* str1, const char* str2) which returns the sum of strlen(str1) and strlen(str2). You can assume that strlen(str2) is always strictly greater than strlen(str1) (strlen(str2) > strlen(str1)). You MAY NOT use any function from string.h. You MAY NOT use any square brackets([]) or any type of loops in function.
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT