help with assignment

Please support our C++ advertiser: Intel Parallel Studio Home
Thread Solved

Join Date: Feb 2009
Posts: 25
Reputation: halfnode is an unknown quantity at this point 
Solved Threads: 0
halfnode halfnode is offline Offline
Light Poster

Re: help with assignment

 
0
  #21
Apr 16th, 2009
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.
Reply With Quote Quick reply to this message  
Join Date: May 2008
Posts: 376
Reputation: Clockowl is on a distinguished road 
Solved Threads: 27
Clockowl's Avatar
Clockowl Clockowl is offline Offline
Posting Whiz

Re: help with assignment

 
0
  #22
Apr 16th, 2009
You could create a function that accepts a reference to a student and outputs it's data?

  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. }
Reply With Quote Quick reply to this message  
Join Date: Feb 2009
Posts: 25
Reputation: halfnode is an unknown quantity at this point 
Solved Threads: 0
halfnode halfnode is offline Offline
Light Poster

Re: help with assignment

 
0
  #23
Apr 16th, 2009
problem is i not supposed to create any functions. its a bit stupid but yar it is that way.
Reply With Quote Quick reply to this message  
Join Date: May 2008
Posts: 376
Reputation: Clockowl is on a distinguished road 
Solved Threads: 27
Clockowl's Avatar
Clockowl Clockowl is offline Offline
Posting Whiz

Re: help with assignment

 
0
  #24
Apr 16th, 2009
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.
Reply With Quote Quick reply to this message  
Join Date: Feb 2009
Posts: 25
Reputation: halfnode is an unknown quantity at this point 
Solved Threads: 0
halfnode halfnode is offline Offline
Light Poster

Re: help with assignment

 
0
  #25
Apr 16th, 2009
but for the multiple subjects its correct for me to have the multiple inputs??
  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];
Reply With Quote Quick reply to this message  
Join Date: May 2008
Posts: 376
Reputation: Clockowl is on a distinguished road 
Solved Threads: 27
Clockowl's Avatar
Clockowl Clockowl is offline Offline
Posting Whiz

Re: help with assignment

 
0
  #26
Apr 16th, 2009
No, student already has 4 subjects: use those.

  1. Student::Subjects::setVar();
Reply With Quote Quick reply to this message  
Join Date: Feb 2009
Posts: 25
Reputation: halfnode is an unknown quantity at this point 
Solved Threads: 0
halfnode halfnode is offline Offline
Light Poster

Re: help with assignment

 
0
  #27
Apr 16th, 2009
do u mean this?

  1. Student::subjects::students[4]

sorry if i'm being dumb...
Last edited by halfnode; Apr 16th, 2009 at 8:05 am.
Reply With Quote Quick reply to this message  
Join Date: May 2008
Posts: 376
Reputation: Clockowl is on a distinguished road 
Solved Threads: 27
Clockowl's Avatar
Clockowl Clockowl is offline Offline
Posting Whiz

Re: help with assignment

 
1
  #28
Apr 16th, 2009
Errr, ignore that last part. Sometimes I'm unclear.

  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.
Reply With Quote Quick reply to this message  
Join Date: Feb 2009
Posts: 25
Reputation: halfnode is an unknown quantity at this point 
Solved Threads: 0
halfnode halfnode is offline Offline
Light Poster

Re: help with assignment

 
0
  #29
Apr 16th, 2009
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.
  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.
Reply With Quote Quick reply to this message  
Join Date: Feb 2009
Posts: 25
Reputation: halfnode is an unknown quantity at this point 
Solved Threads: 0
halfnode halfnode is offline Offline
Light Poster

Re: help with assignment

 
0
  #30
Apr 16th, 2009
Hi all,

thanks for all the great help =). i've finished the qns.
Reply With Quote Quick reply to this message  
Reply

This thread has been marked solved.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



Tag cloud for C++
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC