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
What should you do when you are working on an unclassified system and receive an email.
koban [17]

Answer:

Don't respond to it. Either leave it there, or just delete it. It is most likely spam or a scammer trying to get your information. Don't respond, please.

3 0
2 years ago
Business customers pay $0.006 per gallon for the first 8000 gallons. If the usage is more than 8000 gallons, the rate will be $0
trasher [3.6K]

Answer:

#include <bits/stdc++.h>

using namespace std;

int main()

{

   // variables

   char cust_t;

   int no_gallon;

   double cost=0;

   cout<<"Enter the type of customer(B for business or R for residential):";

   // read the type of customer

   cin>>cust_t;

   // if type is business

   if(cust_t=='b'||cust_t=='B')

   {

       cout<<"please enter the number of gallons:";

       // read the number of gallons

       cin>>no_gallon;

       // if number of gallons are less or equal to 8000

       if(no_gallon<=8000)

       {

           // calculate cost

           cost=no_gallon*0.006;

           cout<<"total cost is: $"<<cost<<endl;

       }

       else

       {

           // if number of gallons is greater than 8000

           // calculate cost

           cost=(8000*0.006)+((no_gallon-8000)*0.008);

           cout<<"total cost is: $"<<cost<<endl;

           

       }

       

   }

   

   // if customer type is residential

   else if(cust_t=='r'||cust_t=='R')

        {

           

       cout<<"please enter the number of gallons:";

       // read the number of gallons

       cin>>no_gallon;

       // if number of gallons are less or equal to 8000

       if(no_gallon<=8000)

       {

           // calculate cost

           cost=no_gallon*0.007;

           cout<<"total cost is: $"<<cost<<endl;

       }

       else

       {// if number of gallons is greater than 8000

       // calculate cost

           cost=(8000*0.005)+((no_gallon-8000)*0.007);

           cout<<"total cost is: $"<<cost<<endl;      

       }        

   }

return 0;

}

Explanation:

Ask user to enter the type of customer and assign it to variable "cust_t". If the customer type is business then read the number of gallons from user and assign it to variable "no_gallon". Then calculate cost of gallons, if  gallons are less or equal to 800 then multiply it with 0.006.And if gallons are greater than 8000, cost for  first 8000 will be multiply by 0.006 and  for rest gallons multiply with 0.008.Similarly if customer type is residential then for first 8000 gallons cost will be multiply by 0.005 and for rest it will  multiply by 0.007. Then print the cost.

Output:

Enter the type of customer(B for business or R for residential):b                                                                                            

please enter the number of gallons:9000                                                                                                                      

total cost is: $56  

4 0
3 years ago
What is MS-Word? Write some versions of MS-Word.
shtirl [24]
Ms- word it is , hope it was helpful
8 0
3 years ago
Read 2 more answers
Write the syntax of FOR......NEXT loop​
anygoal [31]

Answer:

Syntax:

For variable_name As [Data Type] = start To end [ Step step ]

For variable_name As [Data Type] = start To end [ Step step ]

[ inner loop statements ]

Next.

[ Outer loop statements ]

Next.

Explanation:

4 0
3 years ago
Which type of systems development is characterized by significantly speeding up the design phase and the generation of informati
nydimaria [60]

Answer:

Joint Application Development (JAD)

Explanation:

Joint Application Development is a method of application development that  lay emphasis on the up-front aspect of the application development cycle whereby steady communication between the designers and the intended users of the application under development by coming together in collaborative workshop styled discussions known as JAD sessions involving the mediators, facilitator, observers, end users, experts, and developers. As such with JAD process application development result in fewer errors high quality and is completed in lesser time.

3 0
2 years ago
Other questions:
  • What is authentication?
    8·1 answer
  • Why computers are called "COMPUTER"?
    12·1 answer
  • Weber believed that there is an inevitable destructive quality to which one of the four types of action?
    8·1 answer
  • How can you logout your account and do not want to have this anymore
    12·2 answers
  • lance has three tables in his database. He wants to generate a report to show data from the three tables. Therefore, he decides
    7·2 answers
  • Which of the followings is not a testingtype? [2 marks]
    8·1 answer
  • What is the name for the size and style of text?
    8·2 answers
  • 17. What are the basic modes of operation of 8255?Write the features of mode 0 in 8255?
    8·1 answer
  • How do you copy a file​
    9·1 answer
  • Are tigers and goldfish related
    13·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!