after a very unproductive day! - code bugs

Please support our C++ advertiser: Intel Parallel Studio Home
Reply

Join Date: Dec 2004
Posts: 489
Reputation: Acidburn is an unknown quantity at this point 
Solved Threads: 5
Acidburn Acidburn is offline Offline
Posting Pro in Training

after a very unproductive day! - code bugs

 
0
  #1
Mar 26th, 2005
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:



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?
Reply With Quote Quick reply to this message  
Join Date: Sep 2004
Posts: 7,849
Reputation: Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute 
Solved Threads: 754
Team Colleague
Narue's Avatar
Narue Narue is online now Online
Senior Bitch

Re: after a very unproductive day! - code bugs

 
0
  #2
Mar 26th, 2005
>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:
  1. void getjobnumber()
Don't you think that should be:
  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.
New members chased away this month: 4
Reply With Quote Quick reply to this message  
Join Date: Dec 2004
Posts: 489
Reputation: Acidburn is an unknown quantity at this point 
Solved Threads: 5
Acidburn Acidburn is offline Offline
Posting Pro in Training

Re: after a very unproductive day! - code bugs

 
0
  #3
Mar 26th, 2005
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
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:




Views: 2170 | Replies: 2
Thread Tools Search this Thread



Tag cloud for C++
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC