Question

Programming language is C++. Show finished code and an example of the output on PuTTY when done. Use g++ -std=c++17 to compile the code with the chrono.cpp and chrono.h file on PuTTY.

3. (20 points) Start with Chrono,h and Chrono.cpp in section 9.8; for now put a dummy return Sunday; or return d in the last 3 functions on pages 337-338. Add a prefix operator to the Date class by putting the declaration in the Date class in Chrono,h and the definition in Chrono.cpp. The prefix operator should change a date to tomorrow using the following pseudocode: Date& operator ++0{ /addlto d //tomorrow, unless we were at the end ofthe month //if is date is false //need to change to first of next month set d to 1 if m is December Ineed to change to next year too set m to January increment y else increment m return this

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

Answer

main.cpp

#include <iostream>
#include "Chrono.h"
using namespace std;
int main()
{
Date T1;
cout<<"\n---T1---";
T1.displayTime();
++T1;
cout<<"\n---T1---";
T1.displayTime();
  
Date T2(28,2,2000);
cout<<"\n---T2---";
T2.displayTime();
++T2;
cout<<"\n---T2---";
T2.displayTime();
cout<<endl;
return 0;
}

Chrono.h

class Date
{
private:
int day; // 1 to 31
int month; // 1 to 12
int year;   
public:
Date();
Date(int d, int m,int y);
void displayTime(); // method to display time
Date& operator++(); // overloaded prefix ++ operator
};

Chrono.cpp

#include <iostream>
#include "Chrono.h"
using namespace std;
Date::Date()
{
day=1; //default date
month=1;
year=1900;
}
Date::Date(int d, int m,int y)
{
day=d;
month=m;
year=y;
}
// method to display time
void Date::displayTime()
{
cout<<"\nDate : "<<day<<"-"<<month<<"-"<<year;
}
// overloaded prefix ++ operator
Date& Date::operator++()
{
day++; // increment this object
if(month==1||month==3||month==5||month==7||month==8||month==10||month==12)
{
if(day > 31)
{
day=1;
month++;
if(month > 12)
{
month=1;
year++;
}
}
}
else if(month==2)
{
if(day > 28)
{
day=1;
month++;
if(month > 12)
{
month=1;
year++;
}
}
}
else
{
if(day > 30)
{
day=1;
month++;
if(month > 12)
{
month=1;
year++;
}
}
}
return *this;
}

OUTPUT

Add a comment
Know the answer?
Add Answer to:
Programming language is C++. Show finished code and an example of the output on PuTTY when...
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
  • Please help with Java programming! This code is to implement a Clock class. Use my beginning...

    Please help with Java programming! This code is to implement a Clock class. Use my beginning code below to test your implementation. public class Clock { // Declare your fields here /** * The constructor builds a Clock object and sets time to 00:00 * and the alarm to 00:00, also. * */ public Clock() { setHr(0); setMin(0); setAlarmHr(0); setAlarmMin(0); } /** * setHr() will validate and set the value of the hr field * for the clock. * *...

  • Programming in C/C++ Submit your source code files (all .h and .cpp files) NO GLOBAL VARIABLES...

    Programming in C/C++ Submit your source code files (all .h and .cpp files) NO GLOBAL VARIABLES Program: Use operator overloaded functions for a birthday club – Based on Chapter 11 lecture (25 pts) Make a class called Birthday that will have a date of month, day, and year and the name. Need to have overloaded operators to compare values along with regular functions like: Overload operator == that takes a Birthdate, compares against the current date values, and returns a...

  • Object Oriented Programming Please write the code in C++ Please answer the question in text form...

    Object Oriented Programming Please write the code in C++ Please answer the question in text form 9.5 (complex Class) Create a class called complex for performing arithmetic with complex numbers. Write a program to test your class. Complex numbers have the form where i is V-I Use double variables to represent the private data of the class. Provide a constructor that enables an object of this class to be initialized when it's declared. The constructor should contain default values in...

  • Introduction to Data Structures programming assignments can be completed either in C++ (preferred) or in Java....

    Introduction to Data Structures programming assignments can be completed either in C++ (preferred) or in Java. In both cases you cannot use libraries or packages that contain pre-built data structures, other than built-in support for objects, arrays, references, and pointers. Classes in C++ and Java can represent anything in the real world. This assignment is to write a class to represent a Date in a Calendar. Date Class Member Variables The following table identifies and describes the purpose of each...

  • Please create a C++ class called myDate. It should have the following operations: myDate() – default...

    Please create a C++ class called myDate. It should have the following operations: myDate() – default constructor. This will set the date to May 10, 1959. myDate(int M, int D, int Y) – overloaded constructor. This will set the date to the values passed in through the parameter list represented by Month, Day and Year. void display() – display the date in the following format (May 11, 1959) Do NOT print a linefeed after the date. void incrDate(int N) –...

  • In Java You are to write a program that determines the day of the week for...

    In Java You are to write a program that determines the day of the week for New Year's Day in the year 3000. To do this, you must create your own date class (MyDate) and use the following interface and main program: /** Interface for Date objects to be used by the Year3000 driver program. @author Jon Sorenson */ public interface DateInterface { /** @return the day of the month (1-31) */ public int getDay(); /** @return the day of...

  • Java Programming The program template represents a complete working Java program with one or more key...

    Java Programming The program template represents a complete working Java program with one or more key lines of code replaced with comments. Read the problem description and examine the output, then study the template code. Using the problem-solving tips as a guide, replace the /* */ comments with Java code. Compile and execute the program. Compare your output with the sample output provided. Modify class Time2 to include a tick method that increments the time stored in a Time2 object...

  • Please write this code in C++ Object-Oriented Programming, specify which files are .h, and .cpp, and...

    Please write this code in C++ Object-Oriented Programming, specify which files are .h, and .cpp, and please add comments for the whole code. Include a class diagrams, and explain the approach you used for the project and how you implemented that, briefly in a few sentences. Please note the following: -Names chosen for classes, functions, and variables should effectively convey the purpose and meaning of the named entity. - Code duplication should be avoided by factoring out common code into...

  • Code to be written in C++: Initially, you will be given symbols printed in a preorder...

    Code to be written in C++: Initially, you will be given symbols printed in a preorder traversal of a boolean expression tree. The internal nodes of the tree will contain one of the following operators: & (and), | (or), ^ (exclusive-or), or ! (not). The nodes containing the first three operators will have two children, while the nodes containing the ! operator will contain only a left child. The leaves of the tree will contain an operand - either f...

  • This is for my c++ class and im stuck. Complete the Multiplex.cpp file with definitions for a fun...

    This is for my c++ class and im stuck. Complete the Multiplex.cpp file with definitions for a function and three overloaded operators. You don't need to change anything in the Multiplex.h file or the main.cpp, though if you want to change the names of the movies or concession stands set up in main, that's fine. Project Description: A Multiplex is a complex with multiple movie theater screens and a variety of concession stands. It includes two vectors: screenings holds pointers...

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