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
Which of the following scenarios describes an IT professional using the Internet and computer system access in an unprofessional
pantera1 [17]

Answer:

All of the above

Explanation:

6 0
2 years ago
Which element of presentation software can you use to add callouts and banners?
Harrizon [31]
<span><span>1.)From the Insert tab, select the Shapes command. A drop-down menu will appear.
</span><span>2.)Select the desired shape
3.)</span></span>Click and drag<span> the slide to create the shape. You may need to move or resize the shape so it points to the desired part of the image.
4.)</span><span>f you want your callout to contain text, start typing while the shape is selected.
5.)</span><span>From the </span>Format<span> tab, you can use the options in the </span>Shape Styles<span> group to customize the appearance of the shape. You can also adjust the font from the Home tab</span>
7 0
3 years ago
Read 2 more answers
To get a page from the Web, a user must type in a URL, which stands for: a. Unknown Resource Locator b. Unknown Router Location
Afina-wow [57]

Answer:

Hey! The answer you're looking for is D. Uniform Resource Locator.

3 0
3 years ago
The security administrator for Corp wants to provide wireless access for employees as well as guests. Multiple wireless access p
Artemon [7]
It’s B I took the test
7 0
3 years ago
A hacker successfully modified the sale price of items purchased through your company's web site. During the investigation that
Korvikt [17]

Answer:

By modifying the hidden form values that is in a local copy of the company web page

Explanation:

In a situation were the hacker successful change the price of the items he/she purchased through the web site of the company's in which the company web server as well as the company Oracle database were not compromised directly which means that the most likely method in which the attacker used to modified the sale price of the items he/she purchased was by modifying the HIDDEN FORM VALUE that was in the local copy of the company web page making it easy for the HIDDEN FORM VALUE to be vulnerable to the hacker because the hidden form value did not store the company server side information or data but only store the company software state information which is why HIDDEN FORM VALUE should not be trusted.

5 0
3 years ago
Other questions:
  • Henry uploaded the photos of his birthday to a cloud storage system. He feels that it’s a safe option for data storage. His frie
    12·1 answer
  • What tool do you use to secure remote access by users who utilize the internet??
    7·1 answer
  • Write a (one) program for your microcontroller so that it:
    14·1 answer
  • Suppose you have one particular application that is trying to send data on the Internet but none of the data is making it to the
    15·2 answers
  • Using the Vigenere cipher, does the length of the key matter?
    8·1 answer
  • What is the output of adding 1001011 and 100000?
    7·1 answer
  • Having friends who cause you stress can decrease your happiness, which can in turn
    13·2 answers
  • PLEASE HELP!! WILL MARK BRAINLIEST!!
    15·1 answer
  • A reputable, world-renowned auction house uses blockchain to verify the authenticity of paintings prior to placing them up for s
    7·1 answer
  • The most serious security threat to Bluetooth-enabled devices is ____, which occurs when a hacker gains access to the device and
    10·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!