943,568 Members | Top Members by Rank

Ad:
  • C++ Discussion Thread
  • Marked Solved
  • Views: 1791
  • C++ RSS
You are currently viewing page 3 of this multi-page discussion thread; Jump to the first page
Apr 16th, 2009
0

Re: help with assignment

i do need to count the total credit units before inserting them to the student array. and part two of the question requires me to read out from the array and display it.
Last edited by halfnode; Apr 16th, 2009 at 7:40 am.
Reputation Points: 15
Solved Threads: 0
Light Poster
halfnode is offline Offline
27 posts
since Feb 2009
Apr 16th, 2009
0

Re: help with assignment

You could create a function that accepts a reference to a student and outputs it's data?

cpp Syntax (Toggle Plain Text)
  1. void output_student(Student &stud){
  2. //put the output code here
  3. }
  4. //....
  5. int main(){
  6. //loop each of your students here, one loop for reading in the data, the other one for outputting the data
  7. }
Reputation Points: 69
Solved Threads: 28
Posting Whiz
Clockowl is offline Offline
376 posts
since May 2008
Apr 16th, 2009
0

Re: help with assignment

problem is i not supposed to create any functions. its a bit stupid but yar it is that way.
Reputation Points: 15
Solved Threads: 0
Light Poster
halfnode is offline Offline
27 posts
since Feb 2009
Apr 16th, 2009
0

Re: help with assignment

That sucks. But still, just loop the student array then, one time for input, one time for output. So no more extra variables representing members in class Student!
Last edited by Clockowl; Apr 16th, 2009 at 7:46 am.
Reputation Points: 69
Solved Threads: 28
Posting Whiz
Clockowl is offline Offline
376 posts
since May 2008
Apr 16th, 2009
0

Re: help with assignment

but for the multiple subjects its correct for me to have the multiple inputs??
C++ Syntax (Toggle Plain Text)
  1. // 1st subject
  2. inFile >> code[i];
  3. inFile >> cu[i];
  4. inFile >> pf[i];
  5. //subject2
  6. inFile >> codel[i];
  7. inFile >> cul[i];
  8. inFile >> pfl[i];
  9. //subject3
  10. inFile >> codell[i];
  11. inFile >> cull[i];
  12. inFile >> pfll[i];
  13. //subject4
  14. inFile >> codelll[i];
  15. inFile >> culll[i];
  16. inFile >> pflll[i];
Reputation Points: 15
Solved Threads: 0
Light Poster
halfnode is offline Offline
27 posts
since Feb 2009
Apr 16th, 2009
0

Re: help with assignment

No, student already has 4 subjects: use those.

cpp Syntax (Toggle Plain Text)
  1. Student::Subjects::setVar();
Reputation Points: 69
Solved Threads: 28
Posting Whiz
Clockowl is offline Offline
376 posts
since May 2008
Apr 16th, 2009
0

Re: help with assignment

do u mean this?

C++ Syntax (Toggle Plain Text)
  1. Student::subjects::students[4]

sorry if i'm being dumb...
Last edited by halfnode; Apr 16th, 2009 at 8:05 am.
Reputation Points: 15
Solved Threads: 0
Light Poster
halfnode is offline Offline
27 posts
since Feb 2009
Apr 16th, 2009
1

Re: help with assignment

Errr, ignore that last part. Sometimes I'm unclear.

cpp Syntax (Toggle Plain Text)
  1. Student student;
  2. for(int subject = 0; subject < 4; subject++){
  3. string code;
  4. int cu;
  5. char pass_or_fail;
  6. inFile >> code;
  7. inFile >> cu;
  8. inFile >> pass_or_fail;
  9.  
  10. //subject == loop variable
  11. subjects[subject].setCode(code);
  12. subjects[subject].setCU(cu);
  13. subjects[subject].setPF(pass_or_fail);
  14. }

I meant something like that. That's the "input" loop. Now, as you can see, this one is for subjects, but you should also create one for students for their variables. Same goes for output. If you don't know how, first write the code for reading in 1 student, then simply loop that.
Reputation Points: 69
Solved Threads: 28
Posting Whiz
Clockowl is offline Offline
376 posts
since May 2008
Apr 16th, 2009
0

Re: help with assignment

ya ok. i can get the name to be displayed now i just have to count the scores and display it.
but something tells me that i'm inserting the code,cu and pf wrongly.
C++ Syntax (Toggle Plain Text)
  1.  
  2. i = 0;
  3. k = 0;
  4. while( (ch = inFile.peek()) != EOF)
  5. {
  6. k = i;
  7. inFile >> name;
  8. students[k].setName(name);
  9. for(k = 0; k < 4; k++){
  10. inFile >> code;
  11. inFile >> cu;
  12. inFile >> pf;
  13.  
  14. //subject == loop variable
  15. students[k].setSCode(code,k);
  16. students[k].setSCU(cu,k);
  17. students[k].setSpf(pf,k);
  18. }
Last edited by halfnode; Apr 16th, 2009 at 9:33 am.
Reputation Points: 15
Solved Threads: 0
Light Poster
halfnode is offline Offline
27 posts
since Feb 2009
Apr 16th, 2009
0

Re: help with assignment

Hi all,

thanks for all the great help =). i've finished the qns.
Reputation Points: 15
Solved Threads: 0
Light Poster
halfnode is offline Offline
27 posts
since Feb 2009

This thread is solved

Either the thread starter or a moderator has marked this thread as solved. You can most likely trust the responses and answers given. There is most likely no reason for any further responses to be posted here. If you have a related question, please start a new thread in this forum instead.

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in C++ Forum Timeline: A Curious Thing...
Next Thread in C++ Forum Timeline: Fraction Problem





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC