I need your help with functions

Please support our C++ advertiser: Intel Parallel Studio Home
Reply

Join Date: Apr 2007
Posts: 17
Reputation: MarzenaM is an unknown quantity at this point 
Solved Threads: 0
MarzenaM MarzenaM is offline Offline
Newbie Poster

I need your help with functions

 
0
  #1
May 24th, 2007
I need to write program with five different functins. Teacher wants to input the names and exam marks for her students. She wants to determine symbol (A-F) she should assign to each. She wants to display the symbol as well as an appropriate message. Finally she would like to display the highest mark as well as the averae mark of the class. So far I did this:

1st function to input nameAndMark
  1. void InputName(string & nameP, int & markP)
  2. {
  3. cout << "Type the student's name: ";
  4. cin >> nameP;
  5.  
  6. cout << "Enter the stuedent's mark: ";
  7. cin >> markP;
  8. }

2nd function to determine the symbol
  1. char symbol(char symbolP, int markP)
  2. {
  3. if (markP > 0 && markP < 40)
  4. return symbolP = 'F';
  5. else if (markP >= 40 && markP < 50)
  6. return symbolP = 'E';
  7. else if (markP >= 50 && markP < 60)
  8. return symbolP = 'D';
  9. else if (markP >= 60 && markP < 70)
  10. return symbolP = 'C';
  11. else if (markP >= 70 && markP < 80)
  12. return symbolP = 'B';
  13. else if (markP >= 80 && markP <= 100)
  14. return symbolP = 'A';
  15. else
  16. cout << "The range of mark is 0 - 100" << endl;
  17. }

3rd function to display message
  1. void displayMessage(char symbolP, string nameP)
  2. {
  3. switch(symbolP)
  4. {
  5. case 'F':
  6. cout << "Unfortunately you will have to repeat the course, " << nameP << "." << endl;
  7. break;
  8. case 'E':
  9. cout << "You nearly passed. Keep trying, " << nameP << "." << endl;
  10. break;
  11. case 'D':
  12. cout << "Congratulations! You passed, " << nameP << "." << endl;
  13. break;
  14. case 'C':
  15. cout << "Congratulations! You got 60%, " << nameP << "." << endl;
  16. break;
  17. case 'B':
  18. cout << "Well done! Congratulations, " << nameP << "." << endl;
  19. break;
  20. case 'A':
  21. cout << "Excellent! Congratulations, " << nameP << "." << endl;
  22. break;
  23. }
  24. }

4th main function
  1. int main() {
  2. string name;
  3. int mark, totalMark, highestMark;
  4. float averagMark;
  5. char sym;
  6.  
  7. totalMark = 0;
  8.  
  9. for (int i = 1; i <= 3; i++)
  10. {
  11. InputName( name, mark);
  12. symbol( sym, mark);
  13. displayMessage(sym, name);
  14.  
  15.  
  16. }
  17.  
  18. cout << endl;
  19. cout << "Highest mark is: ";
  20. return 0;
  21. }

But its all I could do. Please help me. Tell me what I am doing wrong so far that my functions don't work properly?
Need urgante help. Today its my finale day.
Reply With Quote Quick reply to this message  
Join Date: May 2005
Posts: 86
Reputation: vicky_dev is an unknown quantity at this point 
Solved Threads: 2
vicky_dev's Avatar
vicky_dev vicky_dev is offline Offline
Junior Poster in Training

Re: I need your help with functions

 
0
  #2
May 24th, 2007
You have to write two more functions to compute the total marks and the highest marks.

I can suggest the prototypes as:


  1. void totalmarks( int &currentTotal, int &marks );
  2. void highestmarks( int &currentHighest, int marks );

Its really simple to implement these functions. Hope that helps.
Reply With Quote Quick reply to this message  
Join Date: Feb 2006
Posts: 488
Reputation: Bench has a spectacular aura about Bench has a spectacular aura about Bench has a spectacular aura about 
Solved Threads: 49
Bench's Avatar
Bench Bench is offline Offline
Posting Pro in Training

Re: I need your help with functions

 
0
  #3
May 24th, 2007
  for (int i = 1; i <= 3; i++)
  {
  InputName( name,  mark);
  symbol( sym, mark);
  displayMessage(sym, name);
 
 
  }
You've called your symbol function, but you haven't done anything with the returned value.

If you don't wish to use the return value, then you will need to pass sym by reference, ie
char symbol(char & symbolP, int markP)
Last edited by Bench; May 24th, 2007 at 7:39 am.
¿umop apisdn upside down?
Reply With Quote Quick reply to this message  
Join Date: Dec 2006
Posts: 8
Reputation: Gel is an unknown quantity at this point 
Solved Threads: 2
Gel's Avatar
Gel Gel is offline Offline
Newbie Poster

Re: I need your help with functions

 
0
  #4
May 24th, 2007
is there only one mark per person???

if not you will have to add your marks ... otherwise its ok...
People will accept your ideas much more readily if you tell them Benjamin Franklin said it first.
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC