943,997 Members | Top Members by Rank

Ad:
  • C++ Discussion Thread
  • Unsolved
  • Views: 2325
  • C++ RSS
Mar 26th, 2005
0

after a very unproductive day! - code bugs

Expand Post »
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:


Quote ...

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?
Similar Threads
Reputation Points: 12
Solved Threads: 5
Posting Pro
Acidburn is offline Offline
510 posts
since Dec 2004
Mar 26th, 2005
0

Re: after a very unproductive day! - code bugs

>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:
C++ Syntax (Toggle Plain Text)
  1. void getjobnumber()
Don't you think that should be:
C++ Syntax (Toggle Plain Text)
  1. void job::getjobnumber()
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.
Administrator
Reputation Points: 6442
Solved Threads: 1393
Bad Cop
Narue is offline Offline
11,807 posts
since Sep 2004
Mar 26th, 2005
0

Re: after a very unproductive day! - code bugs

whoopies. I'm gonna get to bed, perhaps spending a constant 6 -8 hours on the code isnt a good idea!! I'll begin debuggin 2moro
Reputation Points: 12
Solved Threads: 5
Posting Pro
Acidburn is offline Offline
510 posts
since Dec 2004

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in C++ Forum Timeline: Free C++ Book available Online!!!
Next Thread in C++ Forum Timeline: Mortgage Calculations





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC