Image

Imageoge_retla wrote in Imagecpp

Alright here's what I'll do. I'm going to tell you what I'm trying to accomplish, and then I'll tell you my (really sucky) idea for accomplishing it.

I -know- there has got to be a better way of doing this... but um, if you respond, please don't just respond with a bunch of code doing it in the way you would do it... I mean, you can, but I'd also like an explanation of what is going on, because I really, really, really, really hate using code that I don't understand. So either give me an explanation here, or reply and let me know you're interested in helping out, and i'll give you my email and/or AIM sn so we can discuss at some point.

Thanks in advance.


Alright. Let's say there is a student. I would like to know the courses that this particular student has already taken. Let's say there are 25 total courses that are offered. A list of these classes appears on the screen, each preceeded by a number. The user selects the number for each course he, or she, has already taken. It then prints a list of only the courses the student has already taken. This is useful, of course, when you have a great number of students. I can pick a particular student and it will print:
Jones, Bob has already taken Algebra, US History, English Lit, Psychology.

My (probably stupid) way
Alright, I obviously already have a Student class which so far contains the first and last name of the student and an ID number. To accomplish this task, I would add an array of bools, and a static const string array containing the names of courses (static so that I only need to create one such array and const because the course list will not change).

In main(), I could have a similar bool array, all set to false of course. When a new Student is instantiated, the courses already taken would be selected from a list, using an int to represent each course. The ints selected would then change the bool array for those particular spots to true. Then this array of bools would be passed to the Student constructor, and would, of course, be a different array for each student, depending on which courses he, or she, had already taken.

Finally, when I wished to print the list of courses already taken by a particular student (found by his ID number), I would use a for loop:
for( i = 0, i < 25; i++ )
if( boolarray[ i ] == true )
cout << stringarray[ i ];
(with an overloaded << operator)
-----------------------------

Ok, so that's my stupid way. Let me know what you think, I'll be glad for any comments or suggestions!