| Felicia123 (156) | |
| Any senior help? | |
|
|
|
| coder777 (2378) | ||||||||
use your already existing void enrollStudent( Course *theCourse , int sizeCourse ), but different. like so:
enrollStudent() you must check if the maximum number of students is already reached
I recommend doing the same for readRecord(). I.e. having a global void readRecord( ifstream &inFile ,Course *theCourse, int &sizeCourse )for all courses and a class member void readRecord( ifstream &inFile )to read the course details. Which would greatly improve the legibility of your code | ||||||||
|
|
||||||||
| Felicia123 (156) | |||||||||
|
@code777 sorry and i shall take your advise . sorry for that for my readfunction() i change it instead of a class member . here my class
and here my read function
and here is my enroll function
my main.cpp
| |||||||||
|
|
|||||||||
| Felicia123 (156) | |
my question is . i having some errorfatal error LNK1120: 1 unresolved externalsand i feel that when i pass the parameter isn't wrong already? i saw that u using only void Course :: enrollStudent()without passing any parameter . but i think they should pass a numOfCourse ? of am i declaring in wrong way already ? | |
|
|
|
| Moschops (5959) | |
| What is the unresolved external? It should give you the name of the function it cannot find. | |
|
|
|
| Felicia123 (156) | |
1>main.obj : error LNK2019: unresolved external symbol "public: void __thiscall Course::readRecord(class std::basic_ifstream<char,struct std::char_traits<char> > &,int &)" (?readRecord@Course@@QAEXAAV?$basic_ifstream@DU?$char_traits@D@std@@@std@@AAH@Z) referenced in function _mainthis my error function? | |
|
|
|
| Moschops (5959) | |
readRecord is not a class function of the class Course. You missed out a Course:: in the definition.Alternatively, if it isn't meant to be a class function of the class Course, don't try to call it as one. | |
|
Last edited on
|
|
| Felicia123 (156) | |
|
okay. but i having an error in my readfunction() it's say my theCourse is using without been initialized . thats why i having the problem of my course . if i put my [b]readRecord()[/code] in my class function . how should i change inside my code? | |
|
|
|
| Moschops (5959) | |||||
That's true. It isn't. Look:
In bold, you can see where you create a pointer and then you start using it, but you never made it point at anything! It's juts some random pointer. What is it meant to be pointing at? If this is meant to be a class function, belong to the Course class, then it's already inside a Course object. You can just use the object variables:
| |||||
|
|
|||||
| Felicia123 (156) | |
| i already make it point to theCourse[i].courseCode and the courseName already . from my cout . but i having problem when readFunction(). it's say my theCourse is being use without initialized | |
|
|
|
| Moschops (5959) | ||||
I disagree. Look at the code.
The first line in bold is where you create the pointer named theCourse. The second line in bold is where you try to use what it is pointing at. Which line of code between those two do you think is setting the pointer to point at something? The pointer that you set in main.cpp, like this:theCourse = new Course[numOfCourse];//dynamic array created
does not exist inside the functions. The variables that exist inside class functions are:1) variables you pass in as parameters 2) variables you create in the function 3) class variables that are part of the class 4) Global variables You are creating a brand new pointer named theCourse in the functions, and it is not being set to point at anything. | ||||
|
Last edited on
|
||||
| Felicia123 (156) | |
| erm.. mind to provide a sentences of code? that can refer to? sorry for it | |
|
|
|
| Moschops (5959) | |||
There are many solutions. Here is one:
called like this: theCourse->enrollStudent( numOfCourse, theCourse );and similarly for other functions. | |||
|
Last edited on
|
|||
| Felicia123 (156) | |||
|
erm . i get what you mean. because i already create dynamic array in my main , so i have to use it . sorry for it . as @code777 teaching me the code and he giving me the way to do like this . i have some problem for my enroll function
from the code we can know that if we press the choice 1 . the function will be recall back . so it will keep call user to input the choice . so what's the advise can give ? @code777 and @Moschops , both seniors. | |||
|
|
|||
| Felicia123 (156) | |
| erm? | |
|
|
|
| CosminNTG (180) | |
| Excuse me I ask you but...are you from Romania? | |
|
|
|
| coder777 (2378) | |||
The point is that you have two enrollStudent() functions. One for the course and one for all courses:
| |||
|
|
|||
| Felicia123 (156) | |||
this is what i done so far for it
got a senior told me , my readRecord is in wrong state already . isn't? do my readRecord() should be in member of class , of should it declare as a outside function ? because last time u told me that i only should have 1 parameter which is ifstream & but then now my read function is have 3 parameters. isn't wrong ? | |||
|
|
|||
| coder777 (2378) | ||
The loop on line 51 is wrong. numOfStudent must be < 30 otherwise it's out of bounds. This loop will force the user to enter 31 students until he gets an error message
| ||
|
|
||
| Felicia123 (156) | |||||
|
i get it d. i using if else statement to do it
now for my enroll student. after i enroll the newstudent. i go back to my readRecord() . but then . now the problem is . while i read back my file. it's output is like this
| |||||
|
|
|||||