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:
For dataType.h
//dataType.h
#ifndef dateType_H
#define dateType_H
class dateType{
public:
void setDate(int, int, int);
void setMonth(int);
void setDay(int);
void setYear(int);
void print() const;
int numberOfDaysPassed();
int numberOfDaysLeft();
void incrementDate(int nDays);
int getMonth();
int getDay();
int getYear();
int getDaysInMonth();
bool isLeapYear();
dateType(int month = 1, int day = 1, int year = 1900);
private:
int dMonth;
int dDay;
int dYear;
};
#endif
//dateType.h
#ifndef dateType_H
#define dateType_H
class dateType{
public:
void setDate(int, int, int);
void setMonth(int);
void setDay(int);
void setYear(int);
void print() const;
int numberOfDaysPassed();
int numberOfDaysLeft();
void incrementDate(int nDays);
int getMonth();
int getDay();
int getYear();
int getDaysInMonth();
bool isLeapYear();
dateType(int month = 1, int day = 1, int year = 1900);
private:
int dMonth;
int dDay;
int dYear;
};
#endif
//dateType.cpp
#include"dateType.h"
#include<iostream>
using namespace std;
void dateType::setDate(int month, int day, int year){
dMonth = month;
dDay = day;
dYear = year;
}
void dateType::setMonth(int month){
dMonth = month;
}
void dateType::setDay(int day){
dDay = day;
}
void dateType::setYear(int year){
dYear = year;
}
void dateType::print() const{
cout<<dMonth<<"-"<<dDay<<"-"<<dYear<<endl;
}
int dateType::numberOfDaysPassed(){
int numDays=0;
int
monthDays[13]={0,31,28,31,30,31,30,31,31,30,31,30,31};
for(int i=1;i<dMonth;i++){
if(i==2 &&
this->isLeapYear())numDays++;
numDays+=monthDays[i];
}
numDays+=dDay;
return numDays;
}
int dateType::numberOfDaysLeft(){
if(this->isLeapYear()){
if(dMonth == 1 || (dMonth==2
&& dDay<29))return 366 -
this->numberOfDaysPassed();
}
return 365 - this->numberOfDaysPassed();
}
void dateType::incrementDate(int nDays){
bool endofMonth;
int
monthDays[13]={0,31,28,31,30,31,30,31,31,30,31,30,31};
for(int i=0;i<nDays;i++){
endofMonth = false;
if (dMonth == 2 &&
this->isLeapYear()) endofMonth = (dDay == 29);
else endofMonth = (dDay ==
monthDays[dMonth]);
if (!endofMonth)
++dDay;
else{
if (dMonth < 12)
{
++dMonth;
dDay = 1;
}
else
{
++dYear;
dMonth = 1;
dDay = 1;
}
}
}
}
int dateType::getMonth(){
return dMonth;
}
int dateType::getDay(){
return dDay;
}
int dateType::getYear(){
return dYear;
}
int dateType::getDaysInMonth(){
int
monthDays[13]={0,31,28,31,30,31,30,31,31,30,31,30,31};
return monthDays[dMonth];
}
bool dateType::isLeapYear(){
if ((dYear % 4 == 0 && dYear % 100 != 0) ||
dYear % 400 == 0) return true;
return false;
}
dateType::dateType(int month , int day , int year ){
dMonth = month;
dDay = day;
dYear = year;
}
//main.cpp
#include"dateType.cpp"
int main(){
dateType date1(3,12,2019);
cout<<"number of days in month :
"<<date1.getDaysInMonth()<<"\n";
dateType date2(3,18,2019);
cout<<"number of days passed :
"<<date2.numberOfDaysPassed()<<"\n";
cout<<"number of days remaining :
"<<date2.numberOfDaysLeft()<<"\n";
date2.incrementDate(25);
date2.print();
return 0;
}
//sample output
C++ problem 11-6 In Programming Exercise 2, the class dateType was designed and implemented to keep...
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...
(IN JAVA ) Given the class Date that can prints the date in numerical form. Some applications might require the date to be printed in another form, such as March 24, 2005. Please do the following: Derive the class ExtDate so that the date can be printed either form. Add a data member to the class ExtDate so that the month can also be stored in string form. Add a method to output the month in the string format followed...
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...
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...
#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;...
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...
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>...
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) –...
Need help figuring out what would be the all 12 days output public class Date { private int day; private int month; private int year; private static int tracker; public Date() { this(1, 1, 2000); System.out.println("4"); } public Date(int year) { this(1, 1, year); System.out.println("3"); } public Date(int month, int year) { this(1, month,...
Need some help on the following problem. Write a class MortgageCalculator that extends the FinancialCalculator class. The compute method of this class prints out the total interest paid on a mortgage. The monthly payment is computed using this formula: Monthy payment = Axr/n divided by 1 -[1/(1+r/n)nT] where A is the mortgage amount, r is the interest rate, n is the number of payments in a year, and T is the term of the mortgage in years. The total interest...