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]
2 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]2 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]2 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
Please solve in 5 mins very fast​
Dmitriy789 [7]

Answer:

a. virtual reality

b. Master Boot Records

c. Primary function of a router

d. zoom

Explanation:

4 0
2 years ago
Read 2 more answers
What is the command to disable any Processes in linix??
stiks02 [169]

Answer: killall[process_name]  or kill[PID]

Explanation:

Killall is a tool for disabling running processes on the system. It will disable all programs that matches the name mentioned.

kill disables processes based on process id numbers. it does not disable the process directly. The process recieves a signal where the process will follow instructions which it has to follow if it receives the signal.

7 0
2 years ago
Write a program that prompts the user to input a number. The program should then output the number and a message saying whether
Gala2k [10]

Answer:

Following is the program in C++ Language

#include <iostream> // header file

using namespace std; // namespace std

int main() // main method

{

   int n;  // variable declaration

   cout<<" Please enter the number :";

   cin>>n; // Read the number

   if(n>0) // check the condition when number is positive

   {

cout<<n<<endl<<"The number is Positive"; // Display number

   }

  else if(n<0) // check the condition when number is Negative

  {

cout<<n<<endl<<"The number is Negative";// Display number

  }

  else // check the condition when number is Zero

  {

cout<<n<<endl<<"The number is Zero";// Display number

  }

   return 0;

  }

Output:

Please enter the number:

64

The number is Positive

Explanation:

Following are the description of the program

  • Declared a variable "n" of int type.
  • Read the value of "n" by user.
  • Check the condition of positive number by using if block statement .If n>0 it print the number is positive.
  • Check the condition of negative number by using else if block statement If n<0 it print the number is negative.
  • Finally if both the above condition is fail it print the message " The number is Zero"

7 0
3 years ago
The _____ provides a basis for creating the project schedule and performing earned value management for measuring and forecastin
inna [77]

Answer:

WBS

Explanation:

<h2><u>Fill in the blanks</u></h2>

The <u>WBS</u> provides a basis for creating the project schedule and performing earned value management for measuring and forecasting project performance.

6 0
2 years ago
What is the quickest way to remove all filters that have been applied to a worksheet?
RSB [31]

Answer:

Select the worksheet and click Delete All Filters.

Explanation:

5 0
2 years ago
Read 2 more answers
Other questions:
  • Exposing employee and customer personal data to an untrusted environment is an example of:
    9·1 answer
  • The purpose of the ________ element is used to configure the main content of a web page document.
    5·1 answer
  • Which statement reflects inherent bias in reading and learning about our world?
    12·1 answer
  • 3. Before you get ready to go diving, you want to explore the area. You see a small snowpack across a small bridge, a short walk
    11·1 answer
  • Windows 1.0 was not considered to be a "true" operating system but rather an operating environment because _____.
    13·1 answer
  • Read the argument below and determine the underlying principle that was used to come to the conclusion presented: It is recommen
    5·1 answer
  • Please complete the following questions. It is important that you use complete sentences and present the questions and answers w
    12·2 answers
  • What is the result when you run the following line of code after a prompt??
    5·1 answer
  • Your team has provisioned an Auto Scaling Groups in a single Region. The Auto Scaling Group at max capacity would total 40 EC2 i
    14·1 answer
  • Which type of data is most sensitive and should be protected from malware?
    7·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!