Fixing Date Class

I have to create an assignment that prints out the information that i set for the classes. I am having trouble printing the date on the program. I am not sure if i am putting what i was given in the right places or if i have it completely wrong. Can someone please help me?


//Contents of person.h

#ifndef PERSON_H
#define PERSON_H

class Person
{
public:

void setLastName(char *s);
void setFirstname(char *s);
void setMiddleInit(char c);
void setStreetAddress(char *s);
void setCity(char *s);
void setState(char *s);
void setZipcode(char *s);
void setHomephone(char *s);
void setWorkPhone(char *s);



char* getLastName();
char* getFirstname();
char getMiddleInit();
char* getStreetAddress();
char* getCity();
char* getState();
char* getZipcode();
char* getHomePhone();
char* getWorkPhone();


private:

char lastName[21];
char firstname[15];
char middleInit;
char streetAddress[25];
char city[20];
char state[2];
char zipcode[10];
char homePhone[12];
char workPhone[12];
Date dateOfBirth[11];



};
#endif

//Contents of person.cpp

#include <string.h>
#include "person.h"

void Person::setLastName(char *s)

{

strcpy (lastName, s);

}

void Person::setFirstname(char *s)

{

strcpy (firstname, s);

}

void Person::setMiddleInit(char c)

{

middleInit = c;

}

void Person::setStreetAddress(char *s)

{

strcpy (streetAddress, s);

}

void Person::setCity(char *s)

{

strcpy (city, s);

}

void Person::setState(char *s)

{

strcpy (state, s);

}

void Person::setZipcode(char *s)

{

strcpy (zipcode, s);

}

void Person::setHomephone(char *s)

{

strcpy (homePhone, s);

}

void Person::setWorkPhone(char *s)

{

strcpy (workPhone, s);

}



char* Person::getLastName()

{

static char temp[21];

strcpy (temp, lastName);

return temp;
}

char* Person::getFirstname()

{

static char temp[15];

strcpy (temp, firstname);

return temp;
}

char Person::getMiddleInit()

{

return middleInit;
}

char* Person::getStreetAddress()

{

static char temp[26];

strcpy (temp, streetAddress);

return temp;
}

char* Person::getCity()

{

static char temp[21];

strcpy (temp, city);

return temp;
}

char* Person::getState()

{

static char temp[3];

strcpy (temp, state);

return temp;
}

char* Person::getZipcode()

{

static char temp[11];

strcpy (temp, zipcode);

return temp;
}

char* Person::getHomePhone()

{

static char temp[13];

strcpy (temp, homePhone);

return temp;
}

char* Person::getWorkPhone()

{

static char temp[13];

strcpy (temp, workPhone);

return temp;
}

//Contents of prog04ex.cpp

#include <iostream>

using namespace std;

#include "person.h"
#include "date.h"

int main(int argc, char *argv[])

{

Person p1;
Date d1;

p1.setFirstname("johnny");
cout << p1.getFirstname()<< endl;

p1.setLastName("Smith");
cout << p1.getLastName() << endl;

p1.setCity("Pearl");
cout<<p1.getCity()<<endl;

p1.setHomephone("1234567");
cout << p1.getHomePhone()<< endl;

p1.setMiddleInit('C');
cout << p1.getMiddleInit()<< endl;

p1.setState("KS");
cout << p1.getState()<< endl;

p1.setStreetAddress("123 Johns Drive");
cout << p1.getStreetAddress()<< endl;

p1.setWorkPhone("8675309");
cout << p1.getWorkPhone()<< endl;

p1.setZipcode("39042");
cout << p1.getZipcode()<< endl;

d1.setDate(11/06/1996);
cout << d1.getDay() << endl;
cout << d1.getMonth() << endl;
cout << d1.getYear() << endl;


return 0;

}

//Contents of date.h

#include <iostream>

using namespace std;

class Date
{
public:
Date();
~Date();
void setDate( int, int, int );
int getDay();
int getMonth();
int getYear();
private:
int day;
int month;
int year;
};

Date::Date()
{
day = 1;
month = 1;
year = 1900;
}

//Contents of date.cpp

#include <string>
#include <iostream>
#include "Date.h"
using namespace std;

Date::~Date()
{
}
void Date::setDate( int d, int m, int y )
{
if ( y >= 1900 )
year = y; // validates that year is 1900 or greater
else
{
year = 1900;
cout << "Invalid year! " << y << endl;
}
if ( m >= 1 && m <= 12)
month = m;
else
{
month = 1;
day = 1;
cout << "Invalid month!" << endl;
}
{
if (m == 1 || m == 3 || m == 5 || m == 7 || m == 8 || m == 10 || m == 12)
{
if ( d >= 1 && d <= 31 )
day = d;
else
{
day = 1;
cout << "Invalid day! " << d << endl;
}
}
else
{
if ( m == 4 || m == 6 || m == 9 || m == 11 )
{
if ( d >= 1 && d <= 30 )
day = d;
else
{
day = 1;
cout << "Invalid day! " << d << endl;
}
}
else
{
if ( m = 2 )
{
if ( y % 4 == 0 && y % 400 != 0 )
{
if ( d >= 1 && d <= 29 )
day = d;
else
{
day = 1;
cout << "Invalid day! " << d << endl;
}
}
else
{
if ( d >= 1 && d <= 28 )
day = d;
else
{
day = 1;
cout << "Invalid day! " << d << endl;
}
}
}
}
}
}

int Date::getDay()
{
int temp;
temp = day;
return temp;
}

int Date::getMonth()
{
int temp;
temp = month;
return temp;
}

int Date::getYear()
{
int temp;
temp = year;
return temp;
}

1
2
//d1.setDate(11/06/1996);
d1.setDate(11, 6, 1996);


Date dateOfBirth[11];
ah, reincarnation
Topic archived. No new replies allowed.