Need some guidance with this program. Never had experience with sentinels so I'm not sure where to start to calculate the multiple grade inputs.


Requirements:

  • Sentinel needs to be used to indicate when there are no more students to process
  • Will read data about a student one at a time
  • Will read the name of the students and their 10 grades
  • Each grade must be an integer between 0 and 100 inclusive
  • Output contains the student's name, average, and letter grade
  • When there are no more students to process, the user will type in the word "done"
  • The program must recognize "done" as the sentinel value used to indicate there are no more students to process

Example Input:

John Smith
90 90 78 89 90 55 66 90 90 90


Example Output:

Student Name: John Smith
Average Grade: 82.8
Letter Grade: B

My attempt for the setup:

#include <iostream>
#include <stdlib>
using namespace std;

// This function will display information about the program to the user.
void displayUserInstructions();


// Reads the test grades
int  getnumericGrades();


//Calculates the average
double computeAverage();


//Determines the letter grade based on the average
char computeLetterGrade();


//Outputs the average to the monitor
void displayOutput(int numeric_grade, double average, char letter_grade);



int main()
{
  char studentName[50];
  int numeric_grade;
  double average;
  char letter_grade;


  displayUserInstructions();


  cin.ignore(1);    // skip past the end-of-line character
  cout << "Enter the students's full name (first name followed by last name): ";
  cin.getline(studentName, 49);


  numberic_grade = getnumericGrades();
  average = computeAverage();
  letter_grade = computeLetterGrade();
  displayOutput(int numeric_grade, double average, char letter_grade);


  return 0;
}


void displayUserInstructions()
{
  cout << "\n\n";
  cout << "This program will read grades for\n";
  cout << "assignments completed by students and will\n";
  cout << "ouput the average for each student with\n";
  cout << "the equivalent letter grade for the average.\n\n";
}

Edited 5 Years Ago by pudge343: n/a

What is the exact error or help you need with this program?
And if you need to input 10 grades for each student, please use a loop.....

Ok, I don't have any experience with loops unfortunately. I tried reading up on the C++ forums but they were confusing. Is it possible to make that loop a function and call it to another one? If that's possible then I can probably figure it out from there.

well here is a example

for(i=0;i<10;i++)
      {   cin>>mark; } //here we enter the value for the mark(This should be declared first)

Well if you try making loop a function, you will have to put the function call in another loop, so that the function is called multiple time (Depends). Well for you case:
It 'function call' need not be in a loop.

int sum=0,marks,avg;

int forloop() //Here we need no argument, as we are sure about the number of marks
for(i=0;i<10;i++)
{ cin>>marks; 
  sum+=marks; 
  }
avg=sum/10;
return avg;//So the function returns the average

Call the function like this:

cout<<"average"<<forloop();

Well this should do it, Well if you have any doubt in any part, please do let me know. I will explain.....

Edited 5 Years Ago by PrimePackster: Just a logical error.....

Please forget the good Captain's 2nd and 3rd explanations. Even I would find them confusing if I was trying to learn loops. Just concentrate on his first example.

I'm sure there are multiple definitions of what a sentinel is, but I think of it as something that triggers an action. For example, if I want to do one thing if the variable called changeFunctions is true and another thing if the changeFunctions is false, then changeFunctions could be considered a sentinel. When sentinels occur within the () after a loop keyword, like while, then the phrase a loop conditional instead of sentinel could be used. The value of the sentinel/loop conditional will control whether the body of the loop is continues or not.

There are three types of loops:
1) for loops are most often used when you know the number of times you want to do something.
2) do/while loops are most often used if you want the body of the loop to be run at least once, no matter what the sentinel/loop conditional value is
3) and while loops are used most often when the body of the loop could be run an indefinite number of times depending on the value of the sentinel/loop conditional.

For a while loop the sentinel/loop conditional must be interpretable as true to get the loop to run the first time through so make sure the value is set to true before you begin the loop if you want it to run at least once. Each time while loop or do while loop you can determine whethet to run the loop again or not. If not, then change the value of the sentinel/loop conditional to be false.

Edited 5 Years Ago by Lerner: n/a

Please forget the good Captain's 2nd and 3rd explanations. Even I would find them confusing if I was trying to learn loops. Just concentrate on his first example.

Sorry If it was confusing....
Well I thought he can pick it up, afterall he can ask doubt if he didn't understand.
And If he is new to Loops, just telling how to start with a loop won't be enough, thats why i went for a working loop structure. Anyway thanks for pointing out.....:D

Edited 5 Years Ago by PrimePackster: To make things more clear

There are three types of loops:
1) for loops are most often used when you know the number of times you want to do something.
2) do/while loops are most often used if you want the body of the loop to be run at least once, no matter what the sentinel/loop conditional value is
3) and while loops are used most often when the body of the loop could be run an indefinite number of times depending on the value of the sentinel/loop conditional.

For a while loop the sentinel/loop conditional must be interpretable as true to get the loop to run the first time through so make sure the value is set to true before you begin the loop if you want it to run at least once. Each time while loop or do while loop you can determine whethet to run the loop again or not. If not, then change the value of the sentinel/loop conditional to be false.

Exactly :D
Well OP, if you need a structural example for each, just let us know.....

Actually, there is one more means of repetition, called recursion, but most C++ programmers consider recursive functions to be both too confusing and too inefficient to be used regularly. Being a Lisp programmer, I find this attitude silly, but there it is. :P

Recursion consists of writing a function that calls itself, with a test somewhere in the function to determine when to stop. A basic example of a recursive function would be the Euclid's Greatest Common Divisor algorithm:

int recursive_gcd(int a, int b)
{
    if (b == 0)
        return a;
    else
        return recursive_gcd(b, a % b);  // '%' is the 'modulo' (or 'remainder') operator
}

This can be compared to the iterative version of the same algorithm, which uses a while() loop to perform the repetition:

int iterative_gcd(int a, int b)
{
    int swap;

    while (b != 0)
    {
       swap = b;
       b = a % b;
       a = swap;
    }

    return a;
}

I don't know if this helps you or confuses you more, but I hope that it does at least explain something.

Edited 5 Years Ago by Schol-R-LEA: n/a

This article has been dead for over six months. Start a new discussion instead.