Answer to Question #203751 in C++ for she

Question #203751

After test 1, a lecturer would like to analyze the students’ performance. As a programmer you are asked to write a program which will input the student’s name and mark (0-100) until a negative value is keyed in as the value of mark. The program will then display

a) The average mark.

b) The name and mark of student with the lowest mark.

c) The name and mark of student with the highest mark.

The passing mark is 25. Calculate and display the number of student that fails the test. What is sentinel value?


1
Expert's answer
2021-06-05T23:56:27-0400
#include <iostream>


using namespace std;


int main()
{
    int i=0;
    int marks[1000];
    string name[1000];
    while(true){
        cout<<"\nEnter the names of student "<<i+1<<": ";
        cin>>name[i];
        cout<<"\nEnter marks of student between 0 and 100 "<<i+1<<": ";
        cin>>marks[i];
        if (marks[i]<0)
            break;
        i++;
    }
    //The average mark
    int sum=0;
    int min=marks[0];
    int max=marks[0];
    for (int m=0;m<i;m++){
        sum=sum+marks[m];
    }
    cout<<"\nThe average mark is "<<sum/i<<endl;
    //The name and mark of student with the lowest mark.
    int mn;
    for (int m=0;m<i;m++){
        if (marks[m]<=min){
            min=marks[m];
            mn=m;
        }
    }
    cout<<"\nThe name and mark of student with the lowest mark:\n";
    cout<<"Name: "<<name[mn]<<endl;
    cout<<"Mark: "<<min<<endl;
    
    //The name and mark of student with the highest mark.
    int mn2;
    for (int m=0;m<i;m++){
        if (marks[m]>=max){
            max=marks[m];
            mn2=m;
        }
    }
    cout<<"\nThe name and mark of student with the highest mark:\n";
    cout<<"Name: "<<name[mn2]<<endl;
    cout<<"Mark: "<<max<<endl;
    
    //The passing mark is 25. Calculate and display the number of student that fails the test
    int count_fail=0;
    for (int m=0;m<i;m++){
        if(marks[m]<25){
            count_fail++;
        }
    }
    cout<<"\nThe number of student that fails the test is "<<count_fail<<endl;
    return 0;
   
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog