![]() |
|
#1
|
|||
|
|||
Problem with programHi! I have this problem with my program... I'm making a program which you add students into and their grades, and the program calculates average score for boys and girls and all students. However, when I try running it, I can add students without trouble, but when I check on the statistics, it just says that I havent added any students...
Could someone please help me? example run Code:
My current code is: main.cpp CPP / C++ / C Code:
calc.cpp CPP / C++ / C Code:
student.cpp CPP / C++ / C Code:
calc.h CPP / C++ / C Code:
student.h CPP / C++ / C Code:
Last edited by LuciWiz : 08-Jun-2005 at 08:40.
Reason: Please insert your C++ code between [c++] & [/c++] tags
|
|
#2
|
|||
|
|||
|
Ok in klass::addstudent() you call student::setGender() and student::giveGrade(). So these infos are going to be stored in the student objects, not in the klass object. In printing the info you call klass::numBo() but the problem is that
Quote:
you should modify klass::addstudent like this: Code:
And if I may comment the general logic of your software. Your class klass seems to be the holder of statistical data and student is information about one student. The structuring seems very complicated to me. main function holds the klass object which holds multiple student objects in an array. In my opinion simple is better so you could have the array of student objects in the main function (if you really need the student class in the first place) also directly in the main function you could hold an object of class Statistics which includes all your statistics data. Then you ask the data in a loop as you do now and update directly the statistics object as well as manipulate the student objects in your array. Also it is cryptic to code everything with numbers. Using enumerations would make the code more nice to read. |
|
#3
|
|||
|
|||
|
Thanks alot for the help!
Okey, perhaps my logic sucks, but this is my first attempt at using nested classes, and thats why I thought I had to put the student in klass. I didn't really understand what you said to me, I tried changing the addStudent() and the printout to stud[numofstud], but it keeps complaining about neither stud nor numofstud being declared. Don't take this as me just being lazy, but I'm fed up with this program now, It just keep getting me errors... Would anyone perhaps try and take on the program to make it work? Post a working version? I really don't want to abandon this project, I really want to learn this, but as things are now, I'm very discuraged. Could someone please help me? |
|
#4
|
|||
|
|||
|
Ok.. because I had nothing much to do, and it seems that you have tried really hard, I decided to make an exception of the rule and write quickly some skeleton program that simulates the functionality in your program. Adding functionality will remain your task. And I dropped away that student class. You can add it if you feel that you need it.
Anyway here it is in 3 files: statistics.h CPP / C++ / C Code:
statistics.cpp CPP / C++ / C Code:
main.cpp CPP / C++ / C Code:
|
Recent GIDBlog
Last Week of IA Training by crystalattice
| Thread Tools | Search this Thread |
| Rate This Thread | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Airport Log program using 3D linked List : problem reading from file | batrsau | C Programming Language | 11 | 29-Feb-2008 07:44 |
| [TUTORIAL] Calling an external program in C (Linux) | dsmith | C Programming Language | 4 | 22-Apr-2005 13:30 |
| fltk-2.0 cvs | Plumb | FLTK Forum | 20 | 13-Nov-2004 07:10 |
| Having a small problem with this program | Krc784 | C++ Forum | 1 | 04-Nov-2004 22:25 |
| problem with the program under Borland | awmp-jansen | C Programming Language | 3 | 01-Jul-2004 17:05 |
Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The