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
umka21 [38]
3 years ago
11

Instructions

Computers and Technology
1 answer:
e-lub [12.9K]3 years ago
6 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
My code get an input of 1900 and it should output not a leap year but it fails first line of code. It should output not a Leap a
marshall27 [118]

Answer:

Explanation:

The code does not fail on the first step since 1900 divided by 4 is actually 475 and has no remainder, meaning that it should return True. The code won't work because the if statements need to be nested in a different format. The correct algorithm would be the following, which can also be seen in the picture attached below that if we input 1900 it would output is not a leap year as it fails on the division by 400 which gives a remainder of 0.75

input_year = int(input())

if input_year % 4 == 0:

   if input_year % 100 == 0:

       if input_year % 400 == 0:

           print(input_year, "is a leap year")

       else:

           print(input_year, "- not a leap year")

   else:

       print(input_year, "is a leap year")

else:

   print(input_year, "- not a leap year")

3 0
2 years ago
Write. A program to fine the difference of two number 25 and 17 . Also displays the output
Anon25 [30]

Answer:

Answer = 25-17

print("25-17", Answer)

Explanation:

You put the sum into a variable which in this case would be Answer and then you can output it with the question.

6 0
2 years ago
Graphics you can select to reinforce the goal of your document include ____.
Tanya [424]
The answer would be D all of the above.
8 0
2 years ago
Which of the following peripheral devices can be used for both input and output? mouse printer CPU touch screen on a tablet comp
solong [7]
CPU carries out both input and output
7 0
2 years ago
Read 2 more answers
To communicate with the operating system running on the computer, each device also requires a software element known as what?
Elina [12.6K]
<span>To communicate with the operating system running on the computer, each device also requires a software element known as what? Answer: </span>The device driver 
5 0
2 years ago
Other questions:
  • Given variables first and last, each of which is associated with a str, representing a first and a last name, respectively. Writ
    13·1 answer
  • A nonpipelined system takes 300ns to process a task. The same task can be processed in a 5-segment pipeline with a clock cycle o
    10·1 answer
  • If a user wished to insert a triangle or a callout figure in a document, he or she should select the _____ option.
    8·1 answer
  • Some classes, like the ArrayList class, use angle brackets in their documentation and their declaration. For example, the Java d
    5·1 answer
  • WHAT 1 + 1 ???? ???????????????????
    15·2 answers
  • Which of the following is a default letter assigned for the primary hard drive
    6·2 answers
  • _ models are non visual ways of communicating how someone thinks about something in the natural world
    12·1 answer
  • 4. An abstract data type is defined as _____.
    14·1 answer
  • Student aid is based on either financial need or _____ need.
    12·2 answers
  • Do you get notified if someone follows you on Spotify like your email or do you just have to find out on your own
    14·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!