SlideShare a Scribd company logo
1 of 7
Download to read offline
Modify the Time class(attached) to be able to work with Date class. The Time object should
always remain in a consistent state.
Modify the Date class(attached) to include a Time class object as a composition, a tick member
function that increments the time stored in a Date object by one second, and increaseADay
function to increase day, month and year when it is proper. Please use CISP400V10A4.cpp that
tests the tick member function in a loop that prints the time in standard format during iteration of
the loop to illustrate that the tick member function works correctly. Be aware that we are testing
the following cases:
a) Incrementing into the next minute.
b) Incrementing into the next hour.
c) Incrementing into the next day (i.e., 11:59:59 PM to 12:00:00 AM).
d) Incrementing into the next month and next year.
You can adjust only programs (Date.cpp, Date.h, Time.cpp and Time.h) to generate the
required result but not the code in CISP400V10A4.cpp file.
Expecting results:
// Date.cpp
// Date class member-function definitions.
#include <array>
#include <string>
#include <iostream>
#include <stdexcept>
#include "Date.h" // include Date class definition
using namespace std;
// constructor confirms proper value for month; calls
// utility function checkDay to confirm proper value for day
Date::Date(int mn, int dy, int yr, Time time)
: time01(time)
{
if (mn > 0 && mn <= monthsPerYear) // validate the month
month = mn;
else
throw invalid_argument("month must be 1-12");
year = yr; // could validate yr
day = checkDay(dy); // validate the day
// output Date object to show when its constructor is called
cout << "Date object constructor for date ";
print();
cout << endl;
} // end Date constructor
// print Date object in form month/day/year
void Date::print() const
{
cout << month << '/' << day << '/' << year;
cout << "t";
time01.printStandard();
cout << "t";
time01.printUniversal();
cout << "n";
} // end function print
// output Date object to show when its destructor is called
Date::~Date()
{
cout << "Date object destructor for date ";
print();
cout << endl;
} // end ~Date destructor
// utility function to confirm proper day value based on
// month and year; handles leap years, too
unsigned int Date::checkDay(int testDay) const
{
static const array< int, monthsPerYear + 1 > daysPerMonth =
{ 0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };
// determine whether testDay is valid for specified month
if (testDay > 0 && testDay <= daysPerMonth[month])
{
return testDay;
} // end if
// February 29 check for leap year
if (month == 2 && testDay == 29 && (year % 400 == 0 || (year % 4 == 0 && year
% 100 != 0)))
{
return testDay;
} // end if
cout << "day (" << testDay << ") set to 1." << endl;
return 1;
} // end function checkDay
// adjust data if day is not proper
void Date::increaseADay()
{
day = checkDay(day + 1);
if (day == 1) // if day wasn't accurate, its value is one
{
month = month + 1; // increase month by 1
if (month > 0 && month >= monthsPerYear) // if month is > 12
{
month = 1;
if (month == 1) // if month wasn't accurate, its value is one
{
year = year + 1; // increment year by 1
} // end if
} // end if
} // end if
} // end function increaseADay
// adjust data if second is not proper
void Date::tick()
{
time01.setSecond(time01.getSecond() + 1); // increment second by 1
if (time01.getSecond() == 0) // if second went over boundary, its value is 0
{
time01.setMinute(time01.getMinute() + 1); // increment minute by 1
if (time01.getMinute() == 0) // if minute went over boundary, its value is 0
{
time01.setHour(time01.getHour() + 1); // increment hour by 1
if (time01.getHour() == 0) // if hour went over boundary, its value is 0
{
increaseADay(); // change the date
} // end if
} // end if
} // end if
} // end function tick
// Date.h
// Date class definition; Member functions defined in Date.cpp
#ifndef DATE_H
#define DATE_H
#include "Time.h" // include Time class definition
class Date
{
public:
static const unsigned int monthsPerYear = 12; // months in a year
Date(int, int, int, Time); // default constructor
void print() const; // print date in month/day/year format
~Date(); // provided to confirm destruction order
void increaseADay(); // increases private data member day by one
void tick(); // increases one second to the Time object
private:
unsigned int month; // 1-12 (January-December)
unsigned int day; // 1-31 based on month
unsigned int year; // any year
// utility function to check if day is proper for month and year
unsigned int checkDay(int) const;
// Time object
Time time01;
}; // end class Date
#endif
// Time.cpp
// Member-function definitions for class Time.
#include <iostream>
#include <iomanip>
#include <stdexcept>
#include "Time.h" // include definition of class Time from Time.h
using namespace std;
// Time constructor initializes each data member
Time::Time(int hour, int minute, int second)
{
setTime(hour, minute, second); // validate and set time
cout << "Time object constructor is called ";
printStandard();
cout << "t";
printUniversal();
cout << "n";
} // end Time constructor
// set new Time value using universal time
void Time::setTime(int h, int m, int s)
{
setHour(h); // set private field hour
setMinute(m); // set private field minute
setSecond(s); // set private field second
} // end function setTime
// set hour value
void Time::setHour(int h)
{
hour = (h >= 0 && h < 24) ? h : 0;
} // end function setHour
// set minute value
void Time::setMinute(int m)
{
minute = (m >= 0 && m < 60) ? m : 0;
} // end function setMinute
// set second value
void Time::setSecond(int s)
{
second = (s >= 0 && s < 60) ? s : 0;
} // end function setSecond
// return hour value
unsigned int Time::getHour() const
{
return hour;
} // end function getHour
// return minute value
unsigned int Time::getMinute() const
{
return minute;
} // end function getMinute
// return second value
unsigned int Time::getSecond() const
{
return second;
} // end function getSecond
// print Time in universal-time format (HH:MM:SS)
void Time::printUniversal() const
{
cout << setfill('0') << setw(2) << getHour() << ":"
<< setw(2) << getMinute() << ":" << setw(2) << getSecond();
} // end function printUniversal
// print Time in standard-time format (HH:MM:SS AM or PM)
void Time::printStandard() const
{
cout << ((getHour() == 0 || getHour() == 12) ? 12 : getHour() % 12)
<< ":" << setfill('0') << setw(2) << getMinute()
<< ":" << setw(2) << getSecond() << (hour < 12 ? " AM" : " PM");
} // end function printStandard
// Time destructor displays message
Time::~Time()
{
cout << "Time object destructor is called ";
printStandard();
cout << "t";
printUniversal();
cout << "n";
} // end Time destructor
// Time.h
// Time class containing a constructor with default arguments.
// Member functions defined in Time.cpp.
// prevent multiple inclusions of header
#ifndef TIME_H
#define TIME_H
// Time class definition
class Time
{
public:
explicit Time(int = 0, int = 0, int = 0); // default constructor
~Time(); // destructor
// set functions
void setTime(int, int, int); // set hour, minute, second
void setHour(int); // set hour (after validation)
void setMinute(int); // set minute (after validation)
void setSecond(int); // set second (after validation)
// get functions
unsigned int getHour() const; // return hour
unsigned int getMinute() const; // return minute
unsigned int getSecond() const; // return second
void printUniversal() const; // output time in universal-time format
void printStandard() const; // output time in standard-time format
private:
unsigned int hour; // 0 - 23 (24-hour clock format)
unsigned int minute; // 0 - 59
unsigned int second; // 0 - 59
}; // end class Time
#endif
// CISP400V10A4.cpp
#include <iostream>
using std::cout;
using std::endl;
#include "Time.h" // include Time class definition
#include "Date.h" // include Date class definition
const int MAX_TICKS = 30000;
int main()
{
Time t(23, 59, 58);// time object
Date d(12, 31, 2017, t); // date object
// output Time object t's values
for ( int ticks = 1; ticks < MAX_TICKS; ++ticks )
{
d.print(); // invokes print
cout << endl;
d.tick(); // invokes function tick
} // end for
d.~Date();// call Date destructor
system("PAUSE");
return 0;
} // end main

More Related Content

Similar to Modify the Time classattached to be able to work with Date.pdf

CMPSC 122 Project 1 Back End Report
CMPSC 122 Project 1 Back End ReportCMPSC 122 Project 1 Back End Report
CMPSC 122 Project 1 Back End ReportMatthew Zackschewski
 
Csphtp1 08
Csphtp1 08Csphtp1 08
Csphtp1 08HUST
 
#include iostream #includeData.h #includePerson.h#in.pdf
#include iostream #includeData.h #includePerson.h#in.pdf#include iostream #includeData.h #includePerson.h#in.pdf
#include iostream #includeData.h #includePerson.h#in.pdfannucommunication1
 
lecture10.ppt fir class ibect fir c++ fr opps
lecture10.ppt fir class ibect fir c++ fr oppslecture10.ppt fir class ibect fir c++ fr opps
lecture10.ppt fir class ibect fir c++ fr oppsmanomkpsg
 
struct procedure {    Date dateOfProcedure;    int procedureID.pdf
struct procedure {    Date dateOfProcedure;    int procedureID.pdfstruct procedure {    Date dateOfProcedure;    int procedureID.pdf
struct procedure {    Date dateOfProcedure;    int procedureID.pdfanonaeon
 
friends functionToshu
friends functionToshufriends functionToshu
friends functionToshuSidd Singh
 
How to Create a Countdown Timer in Python.pdf
How to Create a Countdown Timer in Python.pdfHow to Create a Countdown Timer in Python.pdf
How to Create a Countdown Timer in Python.pdfabhishekdf3
 
Chapter21 separate-header-and-implementation-files
Chapter21 separate-header-and-implementation-filesChapter21 separate-header-and-implementation-files
Chapter21 separate-header-and-implementation-filesDeepak Singh
 
Implement angular calendar component how to drag &amp; create events
Implement angular calendar component how to drag &amp; create eventsImplement angular calendar component how to drag &amp; create events
Implement angular calendar component how to drag &amp; create eventsKaty Slemon
 
enum_comp_exercicio01.docx
enum_comp_exercicio01.docxenum_comp_exercicio01.docx
enum_comp_exercicio01.docxMichel Valentim
 
package reservation; import java.util.; For Scanner Class .pdf
 package reservation; import java.util.; For Scanner Class .pdf package reservation; import java.util.; For Scanner Class .pdf
package reservation; import java.util.; For Scanner Class .pdfanitasahani11
 

Similar to Modify the Time classattached to be able to work with Date.pdf (20)

CMPSC 122 Project 1 Back End Report
CMPSC 122 Project 1 Back End ReportCMPSC 122 Project 1 Back End Report
CMPSC 122 Project 1 Back End Report
 
Oop assignment 02
Oop assignment 02Oop assignment 02
Oop assignment 02
 
Csphtp1 08
Csphtp1 08Csphtp1 08
Csphtp1 08
 
#include iostream #includeData.h #includePerson.h#in.pdf
#include iostream #includeData.h #includePerson.h#in.pdf#include iostream #includeData.h #includePerson.h#in.pdf
#include iostream #includeData.h #includePerson.h#in.pdf
 
lecture10.ppt
lecture10.pptlecture10.ppt
lecture10.ppt
 
lecture10.ppt fir class ibect fir c++ fr opps
lecture10.ppt fir class ibect fir c++ fr oppslecture10.ppt fir class ibect fir c++ fr opps
lecture10.ppt fir class ibect fir c++ fr opps
 
lecture10.ppt
lecture10.pptlecture10.ppt
lecture10.ppt
 
struct procedure {    Date dateOfProcedure;    int procedureID.pdf
struct procedure {    Date dateOfProcedure;    int procedureID.pdfstruct procedure {    Date dateOfProcedure;    int procedureID.pdf
struct procedure {    Date dateOfProcedure;    int procedureID.pdf
 
friends functionToshu
friends functionToshufriends functionToshu
friends functionToshu
 
Functional C++
Functional C++Functional C++
Functional C++
 
C++ L08-Classes Part1
C++ L08-Classes Part1C++ L08-Classes Part1
C++ L08-Classes Part1
 
PROGRAMMING QUESTIONS.docx
PROGRAMMING QUESTIONS.docxPROGRAMMING QUESTIONS.docx
PROGRAMMING QUESTIONS.docx
 
How to Create a Countdown Timer in Python.pdf
How to Create a Countdown Timer in Python.pdfHow to Create a Countdown Timer in Python.pdf
How to Create a Countdown Timer in Python.pdf
 
12
1212
12
 
I os 06
I os 06I os 06
I os 06
 
Chapter21 separate-header-and-implementation-files
Chapter21 separate-header-and-implementation-filesChapter21 separate-header-and-implementation-files
Chapter21 separate-header-and-implementation-files
 
Implement angular calendar component how to drag &amp; create events
Implement angular calendar component how to drag &amp; create eventsImplement angular calendar component how to drag &amp; create events
Implement angular calendar component how to drag &amp; create events
 
enum_comp_exercicio01.docx
enum_comp_exercicio01.docxenum_comp_exercicio01.docx
enum_comp_exercicio01.docx
 
package reservation; import java.util.; For Scanner Class .pdf
 package reservation; import java.util.; For Scanner Class .pdf package reservation; import java.util.; For Scanner Class .pdf
package reservation; import java.util.; For Scanner Class .pdf
 
Lab 1 izz
Lab 1 izzLab 1 izz
Lab 1 izz
 

More from aaseletronics2013

why Tesla was excluded from the iShares MSCI World ESG Enhan.pdf
why Tesla was excluded from the iShares MSCI World ESG Enhan.pdfwhy Tesla was excluded from the iShares MSCI World ESG Enhan.pdf
why Tesla was excluded from the iShares MSCI World ESG Enhan.pdfaaseletronics2013
 
What is the average wait time for the following processes us.pdf
What is the average wait time for the following processes us.pdfWhat is the average wait time for the following processes us.pdf
What is the average wait time for the following processes us.pdfaaseletronics2013
 
Which of the following statement is INCORRECT a Net proper.pdf
Which of the following statement is INCORRECT a Net proper.pdfWhich of the following statement is INCORRECT a Net proper.pdf
Which of the following statement is INCORRECT a Net proper.pdfaaseletronics2013
 
The Magazine Mass Marketing Company has received 14 entries .pdf
The Magazine Mass Marketing Company has received 14 entries .pdfThe Magazine Mass Marketing Company has received 14 entries .pdf
The Magazine Mass Marketing Company has received 14 entries .pdfaaseletronics2013
 
Susan is the president of United Food Corporation a wholesa.pdf
Susan is the president of United Food Corporation a wholesa.pdfSusan is the president of United Food Corporation a wholesa.pdf
Susan is the president of United Food Corporation a wholesa.pdfaaseletronics2013
 
Seleccione la afirmacin que describa correctamente un error.pdf
Seleccione la afirmacin que describa correctamente un error.pdfSeleccione la afirmacin que describa correctamente un error.pdf
Seleccione la afirmacin que describa correctamente un error.pdfaaseletronics2013
 
Required information Skip to question The following infor.pdf
Required information Skip to question   The following infor.pdfRequired information Skip to question   The following infor.pdf
Required information Skip to question The following infor.pdfaaseletronics2013
 
Proje Ynetimi Durum raporunuzda u EV bilgilerini saladnz .pdf
Proje Ynetimi  Durum raporunuzda u EV bilgilerini saladnz .pdfProje Ynetimi  Durum raporunuzda u EV bilgilerini saladnz .pdf
Proje Ynetimi Durum raporunuzda u EV bilgilerini saladnz .pdfaaseletronics2013
 
Principles of Quality Management in Clinical Laboratory.pdf
Principles of Quality Management in Clinical Laboratory.pdfPrinciples of Quality Management in Clinical Laboratory.pdf
Principles of Quality Management in Clinical Laboratory.pdfaaseletronics2013
 
Please Create a Level 1 dfd diagram based on the usecase bel.pdf
Please Create a Level 1 dfd diagram based on the usecase bel.pdfPlease Create a Level 1 dfd diagram based on the usecase bel.pdf
Please Create a Level 1 dfd diagram based on the usecase bel.pdfaaseletronics2013
 
La cavidad peritoneal es el espacio hueco presente entre el .pdf
La cavidad peritoneal es el espacio hueco presente entre el .pdfLa cavidad peritoneal es el espacio hueco presente entre el .pdf
La cavidad peritoneal es el espacio hueco presente entre el .pdfaaseletronics2013
 
Lotsa Lenses pag un dividendo de 121 el ao pasado y plan.pdf
Lotsa Lenses pag un dividendo de 121 el ao pasado y plan.pdfLotsa Lenses pag un dividendo de 121 el ao pasado y plan.pdf
Lotsa Lenses pag un dividendo de 121 el ao pasado y plan.pdfaaseletronics2013
 
KUHampS Corp has 200000 shares of preferred stock outstan.pdf
KUHampS Corp has 200000 shares of preferred stock outstan.pdfKUHampS Corp has 200000 shares of preferred stock outstan.pdf
KUHampS Corp has 200000 shares of preferred stock outstan.pdfaaseletronics2013
 
Kaputun Altndan Bakmak ORION UPSte Yeni Navigasyon Sistem.pdf
Kaputun Altndan Bakmak ORION  UPSte Yeni Navigasyon Sistem.pdfKaputun Altndan Bakmak ORION  UPSte Yeni Navigasyon Sistem.pdf
Kaputun Altndan Bakmak ORION UPSte Yeni Navigasyon Sistem.pdfaaseletronics2013
 
In one month Sri Lankas floatingrate currency the rupee .pdf
In one month Sri Lankas floatingrate currency the rupee .pdfIn one month Sri Lankas floatingrate currency the rupee .pdf
In one month Sri Lankas floatingrate currency the rupee .pdfaaseletronics2013
 
Harriet saw Josephine cheating on a test in their OB class .pdf
Harriet saw Josephine cheating on a test in their OB class .pdfHarriet saw Josephine cheating on a test in their OB class .pdf
Harriet saw Josephine cheating on a test in their OB class .pdfaaseletronics2013
 
For your discussion this week I would like you to carefully .pdf
For your discussion this week I would like you to carefully .pdfFor your discussion this week I would like you to carefully .pdf
For your discussion this week I would like you to carefully .pdfaaseletronics2013
 
Cul es el mejor ejemplo de un tipo de cambio de patrn de .pdf
Cul es el mejor ejemplo de un tipo de cambio de patrn de .pdfCul es el mejor ejemplo de un tipo de cambio de patrn de .pdf
Cul es el mejor ejemplo de un tipo de cambio de patrn de .pdfaaseletronics2013
 
Given the following information about events A B and C de.pdf
Given the following information about events A B and C de.pdfGiven the following information about events A B and C de.pdf
Given the following information about events A B and C de.pdfaaseletronics2013
 
Golden Enterprise Ltd ha estado operando un restaurante dur.pdf
Golden Enterprise Ltd ha estado operando un restaurante dur.pdfGolden Enterprise Ltd ha estado operando un restaurante dur.pdf
Golden Enterprise Ltd ha estado operando un restaurante dur.pdfaaseletronics2013
 

More from aaseletronics2013 (20)

why Tesla was excluded from the iShares MSCI World ESG Enhan.pdf
why Tesla was excluded from the iShares MSCI World ESG Enhan.pdfwhy Tesla was excluded from the iShares MSCI World ESG Enhan.pdf
why Tesla was excluded from the iShares MSCI World ESG Enhan.pdf
 
What is the average wait time for the following processes us.pdf
What is the average wait time for the following processes us.pdfWhat is the average wait time for the following processes us.pdf
What is the average wait time for the following processes us.pdf
 
Which of the following statement is INCORRECT a Net proper.pdf
Which of the following statement is INCORRECT a Net proper.pdfWhich of the following statement is INCORRECT a Net proper.pdf
Which of the following statement is INCORRECT a Net proper.pdf
 
The Magazine Mass Marketing Company has received 14 entries .pdf
The Magazine Mass Marketing Company has received 14 entries .pdfThe Magazine Mass Marketing Company has received 14 entries .pdf
The Magazine Mass Marketing Company has received 14 entries .pdf
 
Susan is the president of United Food Corporation a wholesa.pdf
Susan is the president of United Food Corporation a wholesa.pdfSusan is the president of United Food Corporation a wholesa.pdf
Susan is the president of United Food Corporation a wholesa.pdf
 
Seleccione la afirmacin que describa correctamente un error.pdf
Seleccione la afirmacin que describa correctamente un error.pdfSeleccione la afirmacin que describa correctamente un error.pdf
Seleccione la afirmacin que describa correctamente un error.pdf
 
Required information Skip to question The following infor.pdf
Required information Skip to question   The following infor.pdfRequired information Skip to question   The following infor.pdf
Required information Skip to question The following infor.pdf
 
Proje Ynetimi Durum raporunuzda u EV bilgilerini saladnz .pdf
Proje Ynetimi  Durum raporunuzda u EV bilgilerini saladnz .pdfProje Ynetimi  Durum raporunuzda u EV bilgilerini saladnz .pdf
Proje Ynetimi Durum raporunuzda u EV bilgilerini saladnz .pdf
 
Principles of Quality Management in Clinical Laboratory.pdf
Principles of Quality Management in Clinical Laboratory.pdfPrinciples of Quality Management in Clinical Laboratory.pdf
Principles of Quality Management in Clinical Laboratory.pdf
 
Please Create a Level 1 dfd diagram based on the usecase bel.pdf
Please Create a Level 1 dfd diagram based on the usecase bel.pdfPlease Create a Level 1 dfd diagram based on the usecase bel.pdf
Please Create a Level 1 dfd diagram based on the usecase bel.pdf
 
La cavidad peritoneal es el espacio hueco presente entre el .pdf
La cavidad peritoneal es el espacio hueco presente entre el .pdfLa cavidad peritoneal es el espacio hueco presente entre el .pdf
La cavidad peritoneal es el espacio hueco presente entre el .pdf
 
Lotsa Lenses pag un dividendo de 121 el ao pasado y plan.pdf
Lotsa Lenses pag un dividendo de 121 el ao pasado y plan.pdfLotsa Lenses pag un dividendo de 121 el ao pasado y plan.pdf
Lotsa Lenses pag un dividendo de 121 el ao pasado y plan.pdf
 
KUHampS Corp has 200000 shares of preferred stock outstan.pdf
KUHampS Corp has 200000 shares of preferred stock outstan.pdfKUHampS Corp has 200000 shares of preferred stock outstan.pdf
KUHampS Corp has 200000 shares of preferred stock outstan.pdf
 
Kaputun Altndan Bakmak ORION UPSte Yeni Navigasyon Sistem.pdf
Kaputun Altndan Bakmak ORION  UPSte Yeni Navigasyon Sistem.pdfKaputun Altndan Bakmak ORION  UPSte Yeni Navigasyon Sistem.pdf
Kaputun Altndan Bakmak ORION UPSte Yeni Navigasyon Sistem.pdf
 
In one month Sri Lankas floatingrate currency the rupee .pdf
In one month Sri Lankas floatingrate currency the rupee .pdfIn one month Sri Lankas floatingrate currency the rupee .pdf
In one month Sri Lankas floatingrate currency the rupee .pdf
 
Harriet saw Josephine cheating on a test in their OB class .pdf
Harriet saw Josephine cheating on a test in their OB class .pdfHarriet saw Josephine cheating on a test in their OB class .pdf
Harriet saw Josephine cheating on a test in their OB class .pdf
 
For your discussion this week I would like you to carefully .pdf
For your discussion this week I would like you to carefully .pdfFor your discussion this week I would like you to carefully .pdf
For your discussion this week I would like you to carefully .pdf
 
Cul es el mejor ejemplo de un tipo de cambio de patrn de .pdf
Cul es el mejor ejemplo de un tipo de cambio de patrn de .pdfCul es el mejor ejemplo de un tipo de cambio de patrn de .pdf
Cul es el mejor ejemplo de un tipo de cambio de patrn de .pdf
 
Given the following information about events A B and C de.pdf
Given the following information about events A B and C de.pdfGiven the following information about events A B and C de.pdf
Given the following information about events A B and C de.pdf
 
Golden Enterprise Ltd ha estado operando un restaurante dur.pdf
Golden Enterprise Ltd ha estado operando un restaurante dur.pdfGolden Enterprise Ltd ha estado operando un restaurante dur.pdf
Golden Enterprise Ltd ha estado operando un restaurante dur.pdf
 

Recently uploaded

Roles & Responsibilities in Pharmacovigilance
Roles & Responsibilities in PharmacovigilanceRoles & Responsibilities in Pharmacovigilance
Roles & Responsibilities in PharmacovigilanceSamikshaHamane
 
Biting mechanism of poisonous snakes.pdf
Biting mechanism of poisonous snakes.pdfBiting mechanism of poisonous snakes.pdf
Biting mechanism of poisonous snakes.pdfadityarao40181
 
Painted Grey Ware.pptx, PGW Culture of India
Painted Grey Ware.pptx, PGW Culture of IndiaPainted Grey Ware.pptx, PGW Culture of India
Painted Grey Ware.pptx, PGW Culture of IndiaVirag Sontakke
 
MARGINALIZATION (Different learners in Marginalized Group
MARGINALIZATION (Different learners in Marginalized GroupMARGINALIZATION (Different learners in Marginalized Group
MARGINALIZATION (Different learners in Marginalized GroupJonathanParaisoCruz
 
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxPOINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxSayali Powar
 
CELL CYCLE Division Science 8 quarter IV.pptx
CELL CYCLE Division Science 8 quarter IV.pptxCELL CYCLE Division Science 8 quarter IV.pptx
CELL CYCLE Division Science 8 quarter IV.pptxJiesonDelaCerna
 
Solving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptxSolving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptxOH TEIK BIN
 
Crayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon ACrayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon AUnboundStockton
 
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️9953056974 Low Rate Call Girls In Saket, Delhi NCR
 
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptxECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptxiammrhaywood
 
How to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxHow to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxmanuelaromero2013
 
Employee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxEmployee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxNirmalaLoungPoorunde1
 
Pharmacognosy Flower 3. Compositae 2023.pdf
Pharmacognosy Flower 3. Compositae 2023.pdfPharmacognosy Flower 3. Compositae 2023.pdf
Pharmacognosy Flower 3. Compositae 2023.pdfMahmoud M. Sallam
 
KSHARA STURA .pptx---KSHARA KARMA THERAPY (CAUSTIC THERAPY)————IMP.OF KSHARA ...
KSHARA STURA .pptx---KSHARA KARMA THERAPY (CAUSTIC THERAPY)————IMP.OF KSHARA ...KSHARA STURA .pptx---KSHARA KARMA THERAPY (CAUSTIC THERAPY)————IMP.OF KSHARA ...
KSHARA STURA .pptx---KSHARA KARMA THERAPY (CAUSTIC THERAPY)————IMP.OF KSHARA ...M56BOOKSTORE PRODUCT/SERVICE
 
Historical philosophical, theoretical, and legal foundations of special and i...
Historical philosophical, theoretical, and legal foundations of special and i...Historical philosophical, theoretical, and legal foundations of special and i...
Historical philosophical, theoretical, and legal foundations of special and i...jaredbarbolino94
 
Introduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher EducationIntroduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher Educationpboyjonauth
 
DATA STRUCTURE AND ALGORITHM for beginners
DATA STRUCTURE AND ALGORITHM for beginnersDATA STRUCTURE AND ALGORITHM for beginners
DATA STRUCTURE AND ALGORITHM for beginnersSabitha Banu
 
Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)eniolaolutunde
 

Recently uploaded (20)

Roles & Responsibilities in Pharmacovigilance
Roles & Responsibilities in PharmacovigilanceRoles & Responsibilities in Pharmacovigilance
Roles & Responsibilities in Pharmacovigilance
 
Biting mechanism of poisonous snakes.pdf
Biting mechanism of poisonous snakes.pdfBiting mechanism of poisonous snakes.pdf
Biting mechanism of poisonous snakes.pdf
 
9953330565 Low Rate Call Girls In Rohini Delhi NCR
9953330565 Low Rate Call Girls In Rohini  Delhi NCR9953330565 Low Rate Call Girls In Rohini  Delhi NCR
9953330565 Low Rate Call Girls In Rohini Delhi NCR
 
Painted Grey Ware.pptx, PGW Culture of India
Painted Grey Ware.pptx, PGW Culture of IndiaPainted Grey Ware.pptx, PGW Culture of India
Painted Grey Ware.pptx, PGW Culture of India
 
MARGINALIZATION (Different learners in Marginalized Group
MARGINALIZATION (Different learners in Marginalized GroupMARGINALIZATION (Different learners in Marginalized Group
MARGINALIZATION (Different learners in Marginalized Group
 
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxPOINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
 
CELL CYCLE Division Science 8 quarter IV.pptx
CELL CYCLE Division Science 8 quarter IV.pptxCELL CYCLE Division Science 8 quarter IV.pptx
CELL CYCLE Division Science 8 quarter IV.pptx
 
Solving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptxSolving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptx
 
Crayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon ACrayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon A
 
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
 
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptxECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
 
How to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxHow to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptx
 
Employee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxEmployee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptx
 
Pharmacognosy Flower 3. Compositae 2023.pdf
Pharmacognosy Flower 3. Compositae 2023.pdfPharmacognosy Flower 3. Compositae 2023.pdf
Pharmacognosy Flower 3. Compositae 2023.pdf
 
KSHARA STURA .pptx---KSHARA KARMA THERAPY (CAUSTIC THERAPY)————IMP.OF KSHARA ...
KSHARA STURA .pptx---KSHARA KARMA THERAPY (CAUSTIC THERAPY)————IMP.OF KSHARA ...KSHARA STURA .pptx---KSHARA KARMA THERAPY (CAUSTIC THERAPY)————IMP.OF KSHARA ...
KSHARA STURA .pptx---KSHARA KARMA THERAPY (CAUSTIC THERAPY)————IMP.OF KSHARA ...
 
Historical philosophical, theoretical, and legal foundations of special and i...
Historical philosophical, theoretical, and legal foundations of special and i...Historical philosophical, theoretical, and legal foundations of special and i...
Historical philosophical, theoretical, and legal foundations of special and i...
 
Introduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher EducationIntroduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher Education
 
DATA STRUCTURE AND ALGORITHM for beginners
DATA STRUCTURE AND ALGORITHM for beginnersDATA STRUCTURE AND ALGORITHM for beginners
DATA STRUCTURE AND ALGORITHM for beginners
 
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
 
Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)
 

Modify the Time classattached to be able to work with Date.pdf

  • 1. Modify the Time class(attached) to be able to work with Date class. The Time object should always remain in a consistent state. Modify the Date class(attached) to include a Time class object as a composition, a tick member function that increments the time stored in a Date object by one second, and increaseADay function to increase day, month and year when it is proper. Please use CISP400V10A4.cpp that tests the tick member function in a loop that prints the time in standard format during iteration of the loop to illustrate that the tick member function works correctly. Be aware that we are testing the following cases: a) Incrementing into the next minute. b) Incrementing into the next hour. c) Incrementing into the next day (i.e., 11:59:59 PM to 12:00:00 AM). d) Incrementing into the next month and next year. You can adjust only programs (Date.cpp, Date.h, Time.cpp and Time.h) to generate the required result but not the code in CISP400V10A4.cpp file. Expecting results: // Date.cpp // Date class member-function definitions. #include <array> #include <string> #include <iostream> #include <stdexcept> #include "Date.h" // include Date class definition using namespace std; // constructor confirms proper value for month; calls // utility function checkDay to confirm proper value for day Date::Date(int mn, int dy, int yr, Time time) : time01(time) { if (mn > 0 && mn <= monthsPerYear) // validate the month month = mn; else throw invalid_argument("month must be 1-12"); year = yr; // could validate yr day = checkDay(dy); // validate the day // output Date object to show when its constructor is called cout << "Date object constructor for date "; print(); cout << endl; } // end Date constructor // print Date object in form month/day/year void Date::print() const {
  • 2. cout << month << '/' << day << '/' << year; cout << "t"; time01.printStandard(); cout << "t"; time01.printUniversal(); cout << "n"; } // end function print // output Date object to show when its destructor is called Date::~Date() { cout << "Date object destructor for date "; print(); cout << endl; } // end ~Date destructor // utility function to confirm proper day value based on // month and year; handles leap years, too unsigned int Date::checkDay(int testDay) const { static const array< int, monthsPerYear + 1 > daysPerMonth = { 0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 }; // determine whether testDay is valid for specified month if (testDay > 0 && testDay <= daysPerMonth[month]) { return testDay; } // end if // February 29 check for leap year if (month == 2 && testDay == 29 && (year % 400 == 0 || (year % 4 == 0 && year % 100 != 0))) { return testDay; } // end if cout << "day (" << testDay << ") set to 1." << endl; return 1; } // end function checkDay // adjust data if day is not proper void Date::increaseADay() { day = checkDay(day + 1); if (day == 1) // if day wasn't accurate, its value is one { month = month + 1; // increase month by 1 if (month > 0 && month >= monthsPerYear) // if month is > 12
  • 3. { month = 1; if (month == 1) // if month wasn't accurate, its value is one { year = year + 1; // increment year by 1 } // end if } // end if } // end if } // end function increaseADay // adjust data if second is not proper void Date::tick() { time01.setSecond(time01.getSecond() + 1); // increment second by 1 if (time01.getSecond() == 0) // if second went over boundary, its value is 0 { time01.setMinute(time01.getMinute() + 1); // increment minute by 1 if (time01.getMinute() == 0) // if minute went over boundary, its value is 0 { time01.setHour(time01.getHour() + 1); // increment hour by 1 if (time01.getHour() == 0) // if hour went over boundary, its value is 0 { increaseADay(); // change the date } // end if } // end if } // end if } // end function tick // Date.h // Date class definition; Member functions defined in Date.cpp #ifndef DATE_H #define DATE_H #include "Time.h" // include Time class definition class Date { public: static const unsigned int monthsPerYear = 12; // months in a year Date(int, int, int, Time); // default constructor void print() const; // print date in month/day/year format ~Date(); // provided to confirm destruction order void increaseADay(); // increases private data member day by one void tick(); // increases one second to the Time object private: unsigned int month; // 1-12 (January-December)
  • 4. unsigned int day; // 1-31 based on month unsigned int year; // any year // utility function to check if day is proper for month and year unsigned int checkDay(int) const; // Time object Time time01; }; // end class Date #endif // Time.cpp // Member-function definitions for class Time. #include <iostream> #include <iomanip> #include <stdexcept> #include "Time.h" // include definition of class Time from Time.h using namespace std; // Time constructor initializes each data member Time::Time(int hour, int minute, int second) { setTime(hour, minute, second); // validate and set time cout << "Time object constructor is called "; printStandard(); cout << "t"; printUniversal(); cout << "n"; } // end Time constructor // set new Time value using universal time void Time::setTime(int h, int m, int s) { setHour(h); // set private field hour setMinute(m); // set private field minute setSecond(s); // set private field second } // end function setTime // set hour value void Time::setHour(int h) { hour = (h >= 0 && h < 24) ? h : 0; } // end function setHour // set minute value void Time::setMinute(int m) { minute = (m >= 0 && m < 60) ? m : 0; } // end function setMinute
  • 5. // set second value void Time::setSecond(int s) { second = (s >= 0 && s < 60) ? s : 0; } // end function setSecond // return hour value unsigned int Time::getHour() const { return hour; } // end function getHour // return minute value unsigned int Time::getMinute() const { return minute; } // end function getMinute // return second value unsigned int Time::getSecond() const { return second; } // end function getSecond // print Time in universal-time format (HH:MM:SS) void Time::printUniversal() const { cout << setfill('0') << setw(2) << getHour() << ":" << setw(2) << getMinute() << ":" << setw(2) << getSecond(); } // end function printUniversal // print Time in standard-time format (HH:MM:SS AM or PM) void Time::printStandard() const { cout << ((getHour() == 0 || getHour() == 12) ? 12 : getHour() % 12) << ":" << setfill('0') << setw(2) << getMinute() << ":" << setw(2) << getSecond() << (hour < 12 ? " AM" : " PM"); } // end function printStandard // Time destructor displays message Time::~Time() { cout << "Time object destructor is called "; printStandard(); cout << "t"; printUniversal(); cout << "n"; } // end Time destructor
  • 6. // Time.h // Time class containing a constructor with default arguments. // Member functions defined in Time.cpp. // prevent multiple inclusions of header #ifndef TIME_H #define TIME_H // Time class definition class Time { public: explicit Time(int = 0, int = 0, int = 0); // default constructor ~Time(); // destructor // set functions void setTime(int, int, int); // set hour, minute, second void setHour(int); // set hour (after validation) void setMinute(int); // set minute (after validation) void setSecond(int); // set second (after validation) // get functions unsigned int getHour() const; // return hour unsigned int getMinute() const; // return minute unsigned int getSecond() const; // return second void printUniversal() const; // output time in universal-time format void printStandard() const; // output time in standard-time format private: unsigned int hour; // 0 - 23 (24-hour clock format) unsigned int minute; // 0 - 59 unsigned int second; // 0 - 59 }; // end class Time #endif // CISP400V10A4.cpp #include <iostream> using std::cout; using std::endl; #include "Time.h" // include Time class definition #include "Date.h" // include Date class definition const int MAX_TICKS = 30000; int main() { Time t(23, 59, 58);// time object Date d(12, 31, 2017, t); // date object // output Time object t's values for ( int ticks = 1; ticks < MAX_TICKS; ++ticks )
  • 7. { d.print(); // invokes print cout << endl; d.tick(); // invokes function tick } // end for d.~Date();// call Date destructor system("PAUSE"); return 0; } // end main