Comments

Wednesday, November 21, 2012

OOP Create Calender Taking user data input from main

Posted by at 9:30 PM Read our previous post
Object 
 Start with the date structure in Exercise 5 in Chapter 4 and transform it into a date
class. Its member data should consist of three ints: month, day, and year. It should also
have two member functions: getdate(), which allows the user to enter a date in
12/31/02 format, and showdate(), which displays the date.

Source Code

#include <iostream>

using namespace std;



class calender

{
private:
       int day,month,year;
public:
      
       calender()
       {
       day=0;
       month=0;
       year=0;
      
       }

       void calculate(int a,int b,int c)
       {day=a;
       month=b;
       year=c;
       ///////////////////////// Days ////////////////////
              do
              {

              month=month+1;
              day=day-30;

              }while(day>30);
       /////////////////////// Month ////////////////////
              do
              {
              year=year++;
              month=month-12;
              }while(month>12);
             
              if(month==0)
              {
              month++;
              }
       ////////////////////// Year //////////////////////

       }
       void showdata()
       {
              system("cls");
              cout<<"\tMydays calender"<<endl;
       cout<<"\t"<<day<<" "<<month<<" "<<year<<" "<<endl;
       }

};

void main()
{
       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();
}

Output:


No comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Popular Posts

Labels

© Codepirate is powered by Blogger - Template designed by Stramaxon - Best SEO Template