| | |
after a very unproductive day! - code bugs
Please support our C++ advertiser: Intel Parallel Studio Home
![]() |
•
•
Join Date: Dec 2004
Posts: 489
Reputation:
Solved Threads: 5
This is gonna take some time, anyway here it is:
the student class :
[PHP]
#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
[/PHP]
the student class functions:
[PHP]
#include "student.h"
Student:
tudent(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();
}
[/PHP]
the date class
[PHP]
#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
[/PHP]
the date class functions:
[PHP]
#include "date.h"
Date:
ate(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;
}
[/PHP]
and now the new class that im trying to put in:
[PHP]
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;
}
[/PHP]
and heres main:
[PHP]
#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;
}
[/PHP]
but I get around 9 errors:
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?
the student class :
[PHP]
#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
[/PHP]
the student class functions:
[PHP]
#include "student.h"
Student:
tudent(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();
}
[/PHP]
the date class
[PHP]
#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
[/PHP]
the date class functions:
[PHP]
#include "date.h"
Date:
ate(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;
}
[/PHP]
and now the new class that im trying to put in:
[PHP]
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;
}
[/PHP]
and heres main:
[PHP]
#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;
}
[/PHP]
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.
>Everything works if i take away the job class
So the problem is with job.h and you can focus your debugging there. For example:
Don't you think that should be:
It's also a good idea to tell your compiler to produce preprocessed output so that you can make sure everything is kosher after it's all put together.
So the problem is with job.h and you can focus your debugging there. For example:
C++ Syntax (Toggle Plain Text)
void getjobnumber()
C++ Syntax (Toggle Plain Text)
void job::getjobnumber()
New members chased away this month: 4
![]() |
Similar Threads
- Collins: Why this scientist believes in God (Geeks' Lounge)
- suggestion for [code] (DaniWeb Community Feedback)
- dateType class + increment day function (C)
- MFC Code bugs (C)
- Exercise using: unsigned int datecode(int year, int month, int day); (C++)
- this code isn't working...why..plz help (C++)
Other Threads in the C++ Forum
- Previous Thread: Free C++ Book available Online!!!
- Next Thread: Mortgage Calculations
Views: 2170 | Replies: 2
| Thread Tools | Search this Thread |
Tag cloud for C++
6 api application array arrays assignment beginner binary bitmap c++ c/c++ calculator char class classes code coding compile compiler console conversion convert count data database delete developer display dll email encryption error file forms fstream function functions game generator getline givemetehcodez graph homeworkhelper iamthwee ifstream image input int integer java lazy lib loop looping loops map math matrix memory multidimensional multiple newbie news node number output parameter pointer problem program programming project proxy python random read recursion recursive reference return sort string strings struct template templates text tree url variable vector video visual visualstudio win32 windows winsock word wordfrequency wxwidgets






