Posted by MindBreaker at 7:31 AM
Read our previous post
Object:
Create the Calender class in which user enter value of Day Month Year and if user not enter the values initialize the values of day month year by using Static function to the Default values.
Source Code:
#include <iostream>
#include <stdio.h>
#include <stdlib.h>
using namespace std;
class calender
{
private:
int day,month,year;
static int dday,dmonth,dyear;// d stand for default
public:
calender()
{};
void calculate(int a,int b,int c)
{day=a;
month=b;
year=c;
///////////////////////// Days ////////////////////
if(day>30)
{do
{
month=month+1;
day=day-30;
}while(day>30);
}
/////////////////////// Month ////////////////////
if(month>12)
{do
{
year=year++;
month=month-12;
}while(month>12);
if(month==0)
{
month++;
}
}
////////////////////// Year //////////////////////
}
void showdata()
{
system("cls");
cout<<" Current Date:"<<endl;
cout<<"\tMydays calender"<<endl;
cout<<"\t"<<day<<" "<<month<<" "<<year<<" "<<endl;
}
////////////////////// Static Class /////////////
static void defauLT()
{
system("cls");
cout<<"\tMydays calender\n"<<endl;
cout<<" Default Date:"<<endl;
cout<<"\t"<<dday<<" "<<dmonth<<" "<<dyear<<" "<<endl;
}
};
int calender::dday=30;
int calender::dmonth=12;
int calender::dyear=2012;
void main()
{
char select;
cout<<"Press 1 for set Current Date "<<endl;
cout<<"Press 2 for Defualt Date"<<endl;
cin>>select;
switch(select)
{
case '1':
{
calender cal;
int dd,mm,yy;
cout<<"Enter Days"<<endl;
cin>>dd;
cout<<"Enter Month"<<endl;
cin>>mm;
cout<<"Enter Year"<<endl;
cin>>yy;
cal.calculate(dd,mm,yy);
cal.showdata();
break;}
case '2':
{
calender::defauLT();
break;
}
}
}
Output:
Create the Calender class in which user enter value of Day Month Year and if user not enter the values initialize the values of day month year by using Static function to the Default values.
Source Code:
#include <iostream>
#include <stdio.h>
#include <stdlib.h>
using namespace std;
class calender
{
private:
int day,month,year;
static int dday,dmonth,dyear;// d stand for default
public:
calender()
{};
void calculate(int a,int b,int c)
{day=a;
month=b;
year=c;
///////////////////////// Days ////////////////////
if(day>30)
{do
{
month=month+1;
day=day-30;
}while(day>30);
}
/////////////////////// Month ////////////////////
if(month>12)
{do
{
year=year++;
month=month-12;
}while(month>12);
if(month==0)
{
month++;
}
}
////////////////////// Year //////////////////////
}
void showdata()
{
system("cls");
cout<<" Current Date:"<<endl;
cout<<"\tMydays calender"<<endl;
cout<<"\t"<<day<<" "<<month<<" "<<year<<" "<<endl;
}
////////////////////// Static Class /////////////
static void defauLT()
{
system("cls");
cout<<"\tMydays calender\n"<<endl;
cout<<" Default Date:"<<endl;
cout<<"\t"<<dday<<" "<<dmonth<<" "<<dyear<<" "<<endl;
}
};
int calender::dday=30;
int calender::dmonth=12;
int calender::dyear=2012;
void main()
{
char select;
cout<<"Press 1 for set Current Date "<<endl;
cout<<"Press 2 for Defualt Date"<<endl;
cin>>select;
switch(select)
{
case '1':
{
calender cal;
int dd,mm,yy;
cout<<"Enter Days"<<endl;
cin>>dd;
cout<<"Enter Month"<<endl;
cin>>mm;
cout<<"Enter Year"<<endl;
cin>>yy;
cal.calculate(dd,mm,yy);
cal.showdata();
break;}
case '2':
{
calender::defauLT();
break;
}
}
}
Output:
No comments:
Post a Comment
Note: Only a member of this blog may post a comment.