This is gonna take some time, anyway here it is:
the student class :
#ifndef STUDENT_H
#define STUDENT_H
class Student
{
public:
Student(const char *, const char *, const Date&, const job&);
char * getfirstName();
char * getlastName();
void getbirthdate();
void getjobnumber();
private:
char firstname[25];
char lastname[25];
Date birthdate;
job jobnumber;
};
#endif
the student class functions:
#include "student.h"
Student::Student(const char *first, const char *last, const Date &dateOfbirth, const job &jobs):birthdate(dateOfbirth), jobnumber(jobs)
{
strcpy(firstname , first );
strcpy(lastname, last);
} //constructor
char *Student::getfirstName()
{
return firstname;
}
char *Student::getlastName()
{
return lastname;
}
void Student::getbirthdate()
{
birthdate.getDate();
}
void Student::getjobnumber()
{
jobnumber.getjobnumber();
}
the date class
#ifndef DATE_H
#define DATE_H
class Date
{
public:
Date(int = 1, int = 1 , int = 1900);
int getday();
int getmonth();
int getyear();
void getDate();
private:
int month, day, year;
};
#endif
the date class functions:
#include "date.h"
Date::Date(int dy, int mn, int yr):month(mn), day(dy), year(yr)
{
}
int Date::getday()
{
return day;
}
int Date::getmonth()
{
return month;
}
int Date::getyear()
{
return year;
}
void Date::getDate()
{
cout << day << "/" << month << "/" << year;
}
and now the new class that im trying to put in:
class job
{
public:
job(int = 1);
int getjob();
void setjob(int);
void printjob();
void getjobnumber():
private:
int jobnumber;
};
job::job(int a ) :jobnumber(a)
{
cout << "constructor call" << endl << "The value is :" << jobnumber;
}
int job::getjob()
{
cout << "job is: "<<endl;
return jobnumber;
}
void job::printjob()
{
cout << jobnumber;
}
void job::setjob(int a)
{
jobnumber = a;
}
void getjobnumber()
{
cout << "the job number is: "<<jobnumber;
}
and heres main:
#include <iostream>
using namespace std;
#include "date.h"
#include "job.h"
#include "student.h"
int main()
{
char firstname [25];
char secondname[25];
int day = 0, month = 0, year = 0;
cout << "\n\n --------------------------------------------------------------\n" <<endl;
cout << "please enter your students details - " << endl;
cout << "D.O.B ";
cin >> day >> month >> year;
Date birth(day , month , year);
cout << "Please enter that students name" << endl;
job job1(1);
cin >> firstname >> secondname;
Student student1(firstname, secondname, birth, job1);
cout << "please enter there transaction number: "<<endl;
cout << "the details you entered are :" <<endl;
cout << "name is : " << student1.getfirstName() << " "<< student1.getlastName();
cout << ", and there birthdate is : "; student1.getbirthdate();
return 0;
}
but I get around 9 errors:
d:\extra programming\temp\class\student.h(5) : error C2236: unexpected 'class' 'Student'
d:\extra programming\temp\class\student.h(5) : error C2143: syntax error : missing ';' before '{'
d:\extra programming\temp\class\student.h(5) : error C2447: missing function header (old-style formal list?)
D:\extra programming\temp\Class\class2.cpp(35) : error C2065: 'Student' : undeclared identifier
D:\extra programming\temp\Class\class2.cpp(35) : error C2146: syntax error : missing ';' before identifier 'student1'
D:\extra programming\temp\Class\class2.cpp(35) : error C2065: 'student1' : undeclared identifier
D:\extra programming\temp\Class\class2.cpp(43) : error C2228: left of '.getfirstName' must have class/struct/union type
D:\extra programming\temp\Class\class2.cpp(43) : error C2228: left of '.getlastName' must have class/struct/union type
D:\extra programming\temp\Class\class2.cpp(45) : error C2228: left of '.getbirthdate' must have class/struct/union type
Error executing cl.exe.
looking at the code I cant see whats wrong! Everything works if i take away the job class and restore it. So its obviuosly nothing wrong with date class. Any ideas?