1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
Blizzard [7]
3 years ago
6

The class dateType was designed to implement the date in a program, but the member function setDate and the constructor do not c

heck whether the date is valid before storing the date in the member variables. Rewrite the definitions of the function setDate and the constructor so that the values for the month, day, and year are checked before storing the date into the member variables. Add a member function, isLeapYear, to check whether a year is a leap year. Moreover, write a test program to test your class. Input should be format month day year with each separated by a space. Output should resemble the following:
Computers and Technology
2 answers:
ivanzaharov [21]3 years ago
5 0

Answer:

Check the explanation

Explanation:

Code:

dateType.h

#ifndef dateType_H

#define dateType_H

class dateType

{

public:

   void setDate(int month, int day, int year);

     //Function to set the date.

     //The member variables dMonth, dDay, and dYear are set

     //according to the parameters.

     //Postcondition: dMonth = month; dDay = day;

     //               dYear = year

   int getDay() const;

     //Function to return the day.

     //Postcondition: The value of dDay is returned.

   int getMonth() const;

     //Function to return the month.

     //Postcondition: The value of dMonth is returned.

   int getYear() const;

     //Function to return the year.    

     //Postcondition: The value of dYear is returned.

   void printDate() const;

     //Function to output the date in the form mm-dd-yyyy.

  void isLeapYear() const;

   dateType(int month = 1, int day = 1, int year = 1900);

     //Constructor to set the date

     //The member variables dMonth, dDay, and dYear are set

     //according to the parameters.

     //Postcondition: dMonth = month; dDay = day; dYear = year;

     //               If no values are specified, the default

     //               values are used to initialize the member

     //               variables.

private:

   int dMonth; //variable to store the month

   int dDay;   //variable to store the day

   int dYear; //variable to store the year

};

#endif

dateType.cpp

#include <iostream>

#include "dateType.h"

using namespace std;

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

{

  // Checking month is valid

  while(month<1 || month>12)

  {

      cout << "Enterd month "<<month<< " is wrong"<<endl;

      cout << "Enter correct month"<<endl;

      cin>>month;

  }

  dMonth = month;

 

  // Checking date is valid

  while(day<1 || day>31)

  {

      cout << "Enterd date "<<day<<" is wrong"<<endl;

      cout<<"Enter correct date"<<endl;

      cin>>day;

  }

  dDay = day;

  int count_digits = 0;

  int flag=0;

  int year1;

  // Counting number of digits in year

   while(flag==0)

  {

      year1=year;

      count_digits=0;

      while (year) {

          year /= 10;

          count_digits++;

      }

      if(count_digits != 4)

      {

          cout << "Enterd year "<<year1<<" is wrong"<<endl;

          cout<<"Enter correct year"<<endl;

          cin>>year;

          flag=0;

      }

      else

          flag=1;

  }

  dYear = year1;

}

 

int dateType::getDay() const

{

   return dDay;

}

int dateType::getMonth() const

{

   return dMonth;

}

int dateType::getYear() const

{

   return dYear;

}

void dateType::printDate() const

{

   cout << dMonth << "-" << dDay << "-" << dYear;

}

void dateType::isLeapYear() const

{

 

if ( dYear%400 == 0)

   cout<<endl<<dYear<< " is leap year.\n";

else if ( dYear%100 == 0)

   cout<<endl<<dYear<< " is leap year.\n";

else if ( dYear%4 == 0 )

   cout<<endl<<dYear<< " is leap year.\n";

else

   cout<<endl<<dYear<< " is not leap year.\n";

}

   //Constructor with parameters

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

{

  // Checking month is valid

  while(month<1 || month>12)

  {

      cout << "Enterd month "<<month<< " is wrong"<<endl;

      cout << "Enter correct month"<<endl;

      cin>>month;

  }

  dMonth = month;

 

  // Checking date is valid

  while(day<1 || day>31)

  {

      cout << "Enterd date "<<day<<" is wrong"<<endl;

      cout<<"Enter correct date"<<endl;

      cin>>day;

  }

  dDay = day;

  int count_digits = 0;

  int flag=0;

  int year1;

  // Counting number of digits in year

   while(flag==0)

  {

      year1=year;

      count_digits=0;

      while (year) {

          year /= 10;

          count_digits++;

      }

      if(count_digits != 4)

      {

          cout << "Enterd year "<<year1<<" is wrong"<<endl;

          cout<<"Enter correct year"<<endl;

          cin>>year;

          flag=0;

      }

      else

          flag=1;

  }

  dYear = year1;

}

#include<iostream>

#include "dateType.h"

using namespace std;

int main()

}

}

san4es73 [151]3 years ago
4 0

Answer:

see explaination

Explanation:

dateType.h

#ifndef dateType_H

#define dateType_H

class dateType

{

public:

void setDate(int month, int day, int year);

//Function to set the date.

//The member variables dMonth, dDay, and dYear are set

//according to the parameters.

//Postcondition: dMonth = month; dDay = day;

// dYear = year

int getDay() const;

//Function to return the day.

//Postcondition: The value of dDay is returned.

int getMonth() const;

//Function to return the month.

//Postcondition: The value of dMonth is returned.

int getYear() const;

//Function to return the year.

//Postcondition: The value of dYear is returned.

void printDate() const;

//Function to output the date in the form mm-dd-yyyy.

void isLeapYear() const;

dateType(int month = 1, int day = 1, int year = 1900);

//Constructor to set the date

//The member variables dMonth, dDay, and dYear are set

//according to the parameters.

//Postcondition: dMonth = month; dDay = day; dYear = year;

// If no values are specified, the default

// values are used to initialize the member

// variables.

private:

int dMonth; //variable to store the month

int dDay; //variable to store the day

int dYear; //variable to store the year

};

#endif

dateType.cpp

#include <iostream>

#include "dateType.h"

using namespace std;

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

{

// Checking month is valid

while(month<1 || month>12)

{

cout << "Enterd month "<<month<< " is wrong"<<endl;

cout << "Enter correct month"<<endl;

cin>>month;

}

dMonth = month;

// Checking date is valid

while(day<1 || day>31)

{

cout << "Enterd date "<<day<<" is wrong"<<endl;

cout<<"Enter correct date"<<endl;

cin>>day;

}

dDay = day;

int count_digits = 0;

int flag=0;

int year1;

// Counting number of digits in year

while(flag==0)

{

year1=year;

count_digits=0;

while (year) {

year /= 10;

count_digits++;

}

if(count_digits != 4)

{

cout << "Enterd year "<<year1<<" is wrong"<<endl;

cout<<"Enter correct year"<<endl;

cin>>year;

flag=0;

}

else

flag=1;

}

dYear = year1;

}

int dateType::getDay() const

{

return dDay;

}

int dateType::getMonth() const

{

return dMonth;

}

int dateType::getYear() const

{

return dYear;

}

void dateType::printDate() const

{

cout << dMonth << "-" << dDay << "-" << dYear;

}

void dateType::isLeapYear() const

{

if ( dYear%400 == 0)

cout<<endl<<dYear<< " is leap year.\n";

else if ( dYear%100 == 0)

cout<<endl<<dYear<< " is leap year.\n";

else if ( dYear%4 == 0 )

cout<<endl<<dYear<< " is leap year.\n";

else

cout<<endl<<dYear<< " is not leap year.\n";

}

//Constructor with parameters

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

{

// Checking month is valid

while(month<1 || month>12)

{

cout << "Enterd month "<<month<< " is wrong"<<endl;

cout << "Enter correct month"<<endl;

cin>>month;

}

dMonth = month;

// Checking date is valid

while(day<1 || day>31)

{

cout << "Enterd date "<<day<<" is wrong"<<endl;

cout<<"Enter correct date"<<endl;

cin>>day;

}

dDay = day;

int count_digits = 0;

int flag=0;

int year1;

// Counting number of digits in year

while(flag==0)

{

year1=year;

count_digits=0;

while (year) {

year /= 10;

count_digits++;

}

if(count_digits != 4)

{

cout << "Enterd year "<<year1<<" is wrong"<<endl;

cout<<"Enter correct year"<<endl;

cin>>year;

flag=0;

}

else

flag=1;

}

dYear = year1;

}

main.cpp

#include<iostream>

#include "dateType.h"

using namespace std;

int main()

{

dateType *dt1=new dateType();

cout<<"Date is "<<endl;

dt1->printDate();

cout<<endl;

dt1->isLeapYear();

cout<<endl;

dateType *dt2=new dateType(11,14,2019);

cout<<"Date is "<<endl;

dt2->printDate();

cout<<endl;

dt2->isLeapYear();

cout<<endl;

dt2->setDate(13,32,2016);

cout<<"Date is "<<endl;

dt2->printDate();

cout<<endl;

dt2->isLeapYear();

cout<<endl;

dt1->setDate(10,10,198);

cout<<"Date is "<<endl;

dt1->printDate();

cout<<endl;

dt1->isLeapYear();

cout<<endl;

system("pause");

return 0;

}

You might be interested in
Samuel is working on decimal and binary conversion for his college project. He is using the binary number 111011 and wants to ex
Contact [7]
<span>1 X 25 + 1 X 24 + 1 X 23 + 0 X 22 + 1 X 21 + 1 X 20 thus your Answer is C</span>
4 0
3 years ago
Read 2 more answers
Describe the difference between fuses and circuit breakers. where might each type of device find its best use? g
ycow [4]
Here i found this link that might help!
https://study.com/academy/lesson/the-differences-between-fuses-circuit-breakers.html

Have a nice day!
3 0
3 years ago
To pinpoint an earthquake's location, scientists need information from how many seismometers?
Mazyrski [523]
<span>C. 3
   Due to the different speeds of P and S waves, a single seismometers can determine the distance to an earthquake. So, for a single station, the localization is any point on a circle around the station. With 2 stations, you'll have two circles that intersect at two points. The 3rd station is needed in order to determine which of the 2 points is the actual earthquake.</span>
7 0
3 years ago
What is movie viewer, such as quicktime windows media player,an example of
Karo-lina-s [1.5K]
It is called the Databse
5 0
3 years ago
To ensure that the original value of an argument passed to a method remains unchanged after returning from the method, you shoul
lakkis [162]

Answer:

false

Explanation:

A reference parameter passed into the method can be changed by the method, when the method changes all of a parameter's variables, the parameter will keep the changes after the method is returned.

4 0
3 years ago
Other questions:
  • Casual or informal group meetings are common. Here youcasually chat over tea, meet after work, or get together for purelysocial
    5·1 answer
  • Which of the following function headings arevalid? If they are invalid, explain why.
    12·1 answer
  • Andy is trying to put together a holiday gift knapsack (with W=8) for Sarah. He has n items to choose from, each with infinitely
    15·1 answer
  • What is the description of a computer ram?
    7·1 answer
  • Michael needs to ensure that those items that are automatically archived are still easily accessible within Outlook. Which optio
    7·2 answers
  • Please explain this code line by line and how the values of each variable changes as you go down the code.
    8·1 answer
  • That’s what I have so far. I need help!
    5·1 answer
  • Instructions
    13·1 answer
  • When you create a new database using --------- , the database includes prebuilt tables and forms which you can populate with dat
    15·1 answer
  • and assuming main memory is initially unloaded, show the page faulting behavior using the following page replacement policies. h
    12·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!