Question

#include "stdafx.h" #include <iostream> using namespace std; class dateType {    private:        int dmonth;...

#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;
   if(month<=12)
   {
       dmonth=month;
   if
  
   (month=1||3||5||7||8||10||12)
       numofdays =31;
   else
       (month= 4||6||9||11);
       numofdays =30;
while
       (month = 2)
   if   (isleapyear(year))
       numofdays=29;
               else
               numofdays=28;
  

  
   }
   if(day!=numofdays)
   {
  
       {
           cout << "invalid day"<<endl;
           dday=0;
       }
   }
   else
   {
       cout << "invalid month" << endl;
       dmonth=0;
   }              
   }
   else
   cout<<"invalid year"<<endl;
   dyear=0;
   }
bool isleapyear(int year)
{

if (year%4==0)
return true;
else
return false;
}
int dateType::printdate()const
{

   cout<<dmonth<<"-"<<dday<<"-"<<dyear;
   int datetype::getmonth()const
   {
   return dmonth;
}
   int datetype::getday()const
   {
       return dday;
   }
   int datetype::getyear()const
   {
       return dyear;
      
   }
   datetype::datetype(int month, int day, int year)
   {
       dmonth=month;
       dday=day;
       dyear=year;
   }
   void main()
   {
   int m,d,y;
   datetype date(0,0,0)
cout <<" enter month";
cin >>m;
   cout <<" enter day";
cin >>d;
cout <<" enter year";
cin >>y;
date.setdate(m,d,y)
bool check=date.isLeapYear(y);
if(check)
cout <<"LEAP YEAR:";
date.printdate();
system("pause");
   }
}

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

//Given Code has been fixed

//do comment if any problem arises

//do thumbs up if it helps

//Code

#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;

void 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 = 0;

if (year <= 2008)

{

dyear = year;

if (month <= 12)

{

dmonth = month;

if (month == 1 || month == 3 || month == 5 || month == 7 || month == 8 || month == 10 || month == 12)

numofdays = 31;

else if (month == 4 || month == 6 || month == 9 || month == 11)

numofdays = 30;

if (month == 2)

if (isleapyear(year))

numofdays = 29;

else

numofdays = 28;

}

else

{

cout << "invalid month" << endl;

dmonth = 0;

}

if (day > numofdays)

{

{

cout << "invalid day" << endl;

dday = 0;

}

}

else

dday = day;

}

else

{

cout << "invalid year" << endl;

dyear = 0;

}

}

bool dateType::isleapyear(int year)

{

if (year % 4 == 0)

return true;

else

return false;

}

void dateType::printdate() const

{

cout << dmonth << "-" << dday << "-" << dyear << endl;

}

int dateType::getmonth() const

{

return dmonth;

}

int dateType::getday() const

{

return dday;

}

int dateType::getyear() const

{

return dyear;

}

dateType::dateType(int month, int day, int year)

{

dmonth = month;

dday = day;

dyear = year;

}

int main()

{

int m, d, y;

dateType date(0, 0, 0);

cout << " enter month: ";

cin >> m;

cout << " enter day: ";

cin >> d;

cout << " enter year: ";

cin >> y;

date.setdate(m, d, y);

bool check = date.isleapyear(y);

if (check)

cout << "LEAP YEAR: ";

date.printdate();

system("pause");

}

Output on sample runs:

Add a comment
Know the answer?
Add Answer to:
#include "stdafx.h" #include <iostream> using namespace std; class dateType {    private:        int dmonth;...
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
  • Programming Exercise 11-8 PROBLEM:The class dateType defined in Programming Exercise 6 prints the date in numerical...

    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...

  • The class dateType is designed to implement the date in a program, but the member function...

    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...

  • Can someone please help me. i keep getting an error in my code. I need it...

    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...

  • Hello, I have a bug in my code, and when I run it should ask the...

    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...

  • C++ problem 11-6 In Programming Exercise 2, the class dateType was designed and implemented to keep...

    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: Set the month. Set the day. Set the year. Return the month. Return the day. Return the year. Test whether the year is a leap year. Return the number of days in...

  • #include<iostream> #include<string> #include<iomanip> using namespace std; /* ********* Class Car ************* ********************************* */ class Car {...

    #include<iostream> #include<string> #include<iomanip> using namespace std; /* ********* Class Car ************* ********************************* */ class Car { private: string reportingMark; int carNumber; string kind; bool loaded; string choice; string destination; public: Car() { reportingMark = ""; carNumber = 0; kind = "Others"; loaded = 0; destination = "NONE"; } ~Car() { } void setUpCar(string &reportingMark, int &carNumber, string &kind, bool &loaded, string &destination); }; void input(string &reportingMark, int &carNumber, string &kind, bool &loaded,string choice, string &destination); void output(string &reportingMark, int &carNumber,...

  • #include <iostream> using namespace std; bool binarySearch(int arr[], int start, int end, int target){ //your code...

    #include <iostream> using namespace std; bool binarySearch(int arr[], int start, int end, int target){ //your code here } void fill(int arr[], int count){ for(int i = 0; i < count; i++){ cout << "Enter number: "; cin >> arr[i]; } } void display(int arr[], int count){ for(int i = 0; i < count; i++){ cout << arr[i] << endl; } } int main() { cout << "How many items: "; int count; cin >> count; int * arr = new...

  • #include <iostream> #include <chrono> using namespace std; double improvedPow(double x, int y) { // To be...

    #include <iostream> #include <chrono> using namespace std; double improvedPow(double x, int y) { // To be implemented by you } int main() { cout << "To calculate x^y ..." << endl; double x; int y; cout << "Please enter x: "; cin >> x; cout << "Please enter y: "; cin >> y; if(x == 0) { if (y > 0) cout << 0 << endl; else cout << "x^y is not defined" <<endl; } else { cout << improvedPow(x,y)...

  • In C++ Consider the following Date class: #include <iostream> using namespace std; class MyDate { private:...

    In C++ Consider the following Date class: #include <iostream> using namespace std; class MyDate { private: int month, day, year; public: MyDate() {setDate(2,27,2006);} MyDate(int, int, int); void setDate(int mm, int dd, int yyyy); void showDate(); }; MyDate::MyDate(int mm, int dd, int yyyy) { month = mm; day = dd; year = yyyy; }; void MyDate::setDate(int mm, int dd, int yyyy) { month = mm; day = dd; year = yyyy; }; void MyDate::showDate() { cout << "The date is "...

  • #include <iostream> #include <cstdlib> using namespace std; int **dynArray(int row, int cols) { int **myPtr; int...

    #include <iostream> #include <cstdlib> using namespace std; int **dynArray(int row, int cols) { int **myPtr; int lab[4]; myPtr = new int *[row]; for(int i = 0; i < row; i++) myPtr[i] = new int[lab[i]]; for(int i = 0; i<row ; i++) if(myPtr[i] == 0) cout<<"empty"; return myPtr; } void getinput(int ID,int &Station,int &labnumb) { cout<<" Enter your ID number: "<<endl; cin>>ID; cout<<" Enter your station number: "<<endl; cin>>Station; cout<<" Enter your lab number: "<<endl; cin>>labnumb; return; } void logout(int ID,int...

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
ADVERTISEMENT