0% found this document useful (0 votes)
32 views2 pages

Exp3 3

The document defines a C++ class called "bday" that represents a person's date of birth. The class contains data members for the day, month, and year of birth. It includes accept() and display() methods - accept() prompts the user to enter their date of birth and display() validates the input date and either prints it or an error message depending on whether it is valid. The main() function creates a bday object, calls accept() to get the user's input, and then calls display() to output the validated date or error.

Uploaded by

sakharam_gawade
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
32 views2 pages

Exp3 3

The document defines a C++ class called "bday" that represents a person's date of birth. The class contains data members for the day, month, and year of birth. It includes accept() and display() methods - accept() prompts the user to enter their date of birth and display() validates the input date and either prints it or an error message depending on whether it is valid. The main() function creates a bday object, calls accept() to get the user's input, and then calls display() to output the validated date or error.

Uploaded by

sakharam_gawade
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

EXP3_3

#include<iostream.h>
#include<conio.h>
class bday
{
public:
int day,month,year,m;
void accept()
{
cout<<"Day of Birth:\t";
cin>>day;
cout<<"Month of Birth:\t";
cin>>month;
cout<<"Year of Birth:\t";
cin>>year;
}
void display()
{
m=month;
if(year<1900||year>9999)
{
cout<<"\nInvalid Date";
}
else if(month>12||month<0)
{
cout<<"\nInvalid Date";
}
else if(month==1&&day<0||day>31)
{
cout<<"\nInvalid Date";
}
else if(month==2)
{
if(day<0||day>29&&year%4==0)
{
cout<<"\nInvalid Date";
}
else if(day<0||day>28&&year%4!=0)
{
cout<<"\nInvalid Date";
}
else
{
cout<<"\nDate of Birth\t"<<day<<":"<<m<<":"<<year;
}
}
else if(month==3&&day<0||day>31)
{
cout<<"\nInvalid Date";
}
else if(month==4&&day<0||day>30)
{
cout<<"\nInvalid Date";
}
else if(month==5&&day<0||day>30)
{
cout<<"\nInvalid Date";
}
else if(month==6&&day<0||day>30)
{
cout<<"\nInvalid Date";
Page 1

Print to PDF without this message by purchasing novaPDF (http://www.novapdf.com/)

EXP3_3
}
else if(month==7&&day<0||day>31)
{
cout<<"Invalid Date";
}
else if(month==8&&day<0||day>31)
{
cout<<"Invalid Date";
}
else if(month==9&&day<0||day>30)
{
cout<<"Invalid Date";
}
else if(month==10&&day<0||day>31)
{
cout<<"Invalid Date";
}
else if(month==11&&day<0||day>30)
{
cout<<"\nInvalid Date";
}
else if(month==12&&day<0||day>31)
{
cout<<"\nInvalid Date";
}
else
{
cout<<"\nDate of Birth:\t"<<day<<":"<<m<<":"<<year;
}
}
};
void main()
{
clrscr();
bday b;
b.accept();
b.display();
getch();
}

Page 2

Print to PDF without this message by purchasing novaPDF (http://www.novapdf.com/)

You might also like