Go4Expert

Go4Expert (http://www.go4expert.com/)
-   C++ (http://www.go4expert.com/forums/cpp/)
-   -   can you help me with my c++ program!!!thnx... (http://www.go4expert.com/forums/help-cpp-programthnx-t23307/)

shadow0819 14Sep2010 18:04

can you help me with my c++ program!!!thnx...
 
i really need this because i will pass it on friday...
this is a class
the problem is to Input 2 dates ( month/date/year/century)
and print the date that is latest to what you inputted...
we got the program running and its alright...
but the problem is where do we put the weekday(monday tuesday, etc.)
when you input the dates only by numbers it will print:
like this perhaps...M=1, D=1, Y=2010, C=21
it'll print like,
Friday 1/1/2010 21 century
here's the code...
(date.h)
Code:

class Date
{
public:
    Date();
    void setDate1(int,int,int,int);
    void setDate2(int,int,int,int);
    void showLater();
    void showDay();
private:
    int day;
    int yr1;
    int yr2;
    int d1;
    int d2;
    int m1;
    int dd1;
    int cc1;
    int yy1;
    int m2;
    int dd2;
    int cc2;
    int yy2;
};
(date.cpp)
#include <iostream.h>
#include "date.h"
Date::Date()
{
    yr1=yr2=d1=d2=m1=m2=dd1=dd2=cc1=cc2=yy1=yy2=0;
}
void Date::setDate1(int a1,int b1,int c1, int d1)
{
    m1=a1;
    dd1=b1;
    cc1=c1;
    yy1=d1;

    yr1=c1*100+d1;
    d1=yr1*10000+a1*100+b1;
}
void Date::setDate2(int e2,int f2,int g2,int h2)
{
    m2=e2;
    dd2=f2;
    cc2=g2;
    yy2=h2;

    yr2=g2*100+h2;
    d2=yr2*10000+e2*100+f2;
}
void Date::showLater()
{
    if (d1>d2)
    {
        cout << "The later date is "<<m1<<"/"<<dd1<<"/"<<yy1<<" of "<<cc1<<" century."<<endl;
    }
    else
    {
        cout << "The later date is "<<m2<<"/"<<dd2<<"/"<<yy2<<" of "<<cc2<<" century."<<endl;
    }
}
(class.cpp)
#include <iostream.h>
#include "date.h"
int main()
{
    int a,b,c,d;
    cout<<"Enter the first date:"<<endl;
    cout<<"\n\tMonth:";
    cin>>a;
    cout<<"\tDay:";
    cin>>b;
    cout<<"\tCentury:";
    cin>>c;
    cout<<"\tYear:";
    cin>>d;

    cout<<"First Date:"<<endl;
    cout<<a<<"/"<<b<<"/"<<d<<"/"<<c<<endl;

    int e,f,g,h;
    cout<<"Enter the second date:"<<endl;
    cout<<"\n\tMonth:";
    cin>>e;
    cout<<"\tDay:";
    cin>>f;
    cout<<"\tCentury:";
    cin>>g;
    cout<<"\tYear:";
    cin>>h;
   
    cout<<"Second Date:"<<endl;
    cout<<e<<"/"<<f<<"/"<<h<<"/"<<g<<"\n"<<endl;

    Date date;
    date.setDate1(a,b,c,d);
    date.setDate2(e,f,g,h);
    date.showLater();
    return 0;
}

can you help me with that???

thnx...

xpi0t0s 15Sep2010 12:46

Re: can you help me with my c++ program!!!thnx...
 
You need to use better variable names. I have no idea what the difference is between day, dd1 and dd2, or why a Date class needs so many variables (it can be represented with a single integer). Also the code needs commenting to explain what you're doing and why; comments need to relate the code to the design (don't state the obvious, like "i++; // increment i").


All times are GMT +5.5. The time now is 03:04.