![]() |
|
#1
|
|||
|
|||
GradeBook ProgramI Am new to C++. This is supposed to create a grade book using structs that takes in an id number a student name and a student grade and have to use an arrary to include multiple inputs. I also need to create functions to average and sum the grades of all the students.
So the output is supposed to be like the roster student name, id and grade if you hit the coresponding number. But I am having trouble figuring this out. I included the text file. Any help would be greatley appreciated. |
|
#2
|
|||
|
|||
|
Quote:
Sometimes people can help, sometimes not. I suggest that a way to increase the probability that someone can (and will) help is to do this: 1. Copy/paste the code in your post. Some of us won't download attachments. Be sure to read this CodeTags Reference to see how to get properly formatted code. 2. Compile the code. If there are any error or warning messages that you don't understand, ask. Copy/paste the exact error message into your post so that we can see what you see. (Tell us what operating system and what compiler you are using. Sometimes it makes a difference.) 3. If there is some task that you have defined (or has been defined for you) and you understand the task but don't understand how to incorporate various processes into your C or C++ code, tell us what you know and what you don't know. Be specific. 4. In general: Ask specific questions. When you ask for help, you should tell us what you are trying to do (What is the program input and expected output? What happened? What did you expect to happen? What do you understand or not understand about what happened?) Regards, Dave |
|
#3
|
|||
|
|||
|
Ok
Here is the code CPP / C++ / C Code:
Here are the error messages error C2664: 'populate_grade' : cannot convert parameter 1 from 'book [2]' to 'book *[]' error C2664: 'print_roster' : cannot convert parameter 1 from 'book [2]' to 'book *[]' Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast I had it working for a second earlier but, it wasnt going into an array. |
|
#4
|
|||
|
|||
|
Quote:
Thanks for using code tags!!!!! Here is your function prototype: CPP / C++ / C Code:
That says the first argument is an array of pointers to the struct. Here is where you call the function: CPP / C++ / C Code:
Where BookArray is the name of an array of structs, not an array of pointers to struct. When you use the name of an array of "something" by itself it is treated as a pointer to that "something". That's what the compiler is complaining about. Now, here is your function definition: CPP / C++ / C Code:
And inside the function you treat the argument as a pointer to struct, which is consistent with the way you called it. So ... change the prototype to match the function definition. Regards, Dave |
|
#5
|
|||
|
|||
|
Thanks for your help I can now run it, but Im still having trouble ill explain were below:
CPP / C++ / C Code:
1. Populate Grade Book 2. Show grade Statistics 3. Print student Roster 4. quit 1 Enter a name2 Enter a student id3 Enter a grade4 Enter a name5 Enter a student id6 Enter a grade7 Name: 5 ID: 6 Grade: 7 Name: 5 ID: 6 Grade: 7 ///Here it Prints out the same thing twice? Dont /// know why 1. Populate Grade Book 2. Show grade Statistics 3. Print student Roster 4. quit 3 ///After I Hit 3 the Program brings up that is has ///encounterd a problem and needs to end. Press any key to continue |
|
#6
|
||||
|
||||
|
Be careful. You loop trough your array from 0 to size, using i. But when you fill your array in populate_grade and when you try to acquire the data in print_roster you use size for your array's index. You should use i.
CPP / C++ / C Code:
This will print the elements at the indexes 0 and 1. By x[size], you try to use the element at index 2. That is not your memory! You declared BookArray like this: CPP / C++ / C Code:
I hope this solves your problem (I didn't look through your entire code). Best regards, Lucian __________________
Please read these Guidelines before posting on the forum "A person who never made a mistake never tried anything new." Einstein |
|
#7
|
|||
|
|||
|
So far so good.
But now I have another problem. I am not able to cin the size of the array. CPP / C++ / C Code:
I get these errors error C2593: 'operator >>' is ambiguous error C2466: cannot allocate an array of constant size 0 error C2133: 'BookArray' : unknown size I figured out that size had to be decleared as a constant. But now the cin statement for size will not work says >> is ambiguous. |
|
#8
|
||||
|
||||
|
Quote:
If you want to have size be a const you need to go through the whole process at the same time. CPP / C++ / C Code:
One other thing, you create your book object but your function needs a pointer to a book. Maybe you already caught this. Code:
CPP / C++ / C Code:
Or something of that nature. Mark __________________
"Opportunity is missed by most people because it comes dressed in overalls and looks like work." --Thomas Alva Edison "Those who would give up essential liberty to purchase a little temporary safety, deserve neither liberty nor safety." --Benjamin Franklin "A happy person is not a person in a certain set of circumstances, but rather a person with a certain set of attitudes." --Hugh Downs |
|
#9
|
|||
|
|||
|
CPP / C++ / C Code:
now im getting error C2133: 'BookArray' : unknown size error C2057: expected constant expression error C2466: cannot allocate an array of constant size 0 I seem to have no luck today. |
|
#10
|
||||
|
||||
|
Quote:
That's odd. I am using g++ (cygwin) to compile. Here is what I had to test with. CPP / C++ / C Code:
This gives me the following output: Code:
Granted, I am not doing anything useful with it, I just was illustrating the const trouble you were having. Run this version I posted and see if you get the same error. Mark __________________
"Opportunity is missed by most people because it comes dressed in overalls and looks like work." --Thomas Alva Edison "Those who would give up essential liberty to purchase a little temporary safety, deserve neither liberty nor safety." --Benjamin Franklin "A happy person is not a person in a certain set of circumstances, but rather a person with a certain set of attitudes." --Hugh Downs |
Recent GIDBlog
NARMY 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 |
| Anyone can write a program code for this??? | chriskan76 | C Programming Language | 1 | 19-Oct-2004 20:25 |
| Need help with a C program (Long) | McFury | C Programming Language | 3 | 29-Apr-2004 20:06 |
Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The