Answer to Question #212422 in C++ for Dikeledi Matlala

Question #212422

A training center selects applicants into their apprenticeships program based on the needs fir apprentices in the industry. Only 5 applicants were enrolled for the year. The final mark for the student is determined by the final exam mark plus 5 Mark's if the student submitted all the assessments. Otherwise, the final mark of the student is the exam mark


Write a c++ program to determine the final mark of the student. The program should:

•Hold the names of the students and their final mark in a parallel array

•Display the names and their final Mark's in a tabular format

•Calculate and display the average mark of the student

•Calculate the highest and lowest final mark and display the name and the mark of the student with the highest and lowest final mark.


1
Expert's answer
2021-07-01T01:11:54-0400
#include <iostream>
#include <string>
#include <iomanip>
using namespace std;


const int N=5;


void ReadMarks(string names[], int finalMarks[]) {
    for (int i=0; i<N; i++) {
        cout << "Enter a name of " << i+1 << "th applicat: ";
        cin >> names[i];
        cout << "Enter his/her exam mark: ";
        cin >> finalMarks[i];
        char ans;
        cout << "does he/she submitted all the assessment (y/n)? ";
        cin >> ans;
        if (ans == 'y' || ans == 'Y') {
            finalMarks[i] += 5;
        }
    }
}


void PrintMarks(string names[], int finalMarks[]) {
    cout << "Name                 : Final" << endl;
    cout << "---------------------+------" << endl;
    for (int i=0;  i<N; i++) {
        cout << setw(20) << left << names[i] << " : " << finalMarks[i] << endl;
    }
}


double AvarageMark(int marks[]) {
    int s = 0;


    for (int i=0; i<N; i++) {
        s += marks[i];
    }
    return static_cast<double>(s) / N;
}


int HighestMarks(int marks[]) {
    int indx = 0;
    for (int i=1; i<N; i++) {
        if (marks[i] > marks[indx]) {
            indx = i;
        }
    }
    return indx;
}


int LowestMarks(int marks[]) {
    int indx = 0;
    for (int i=1; i<N; i++) {
        if (marks[i] < marks[indx]) {
            indx = i;
        }
    }
    return indx;
}


int main() {
    string names[N];
    int finalMarks[N];


    ReadMarks(names, finalMarks);


    cout << endl;
    PrintMarks(names, finalMarks);
    cout << endl << "The average mark is " << AvarageMark(finalMarks) << endl;
    int indx = HighestMarks(finalMarks);
    cout <<"The highest score " << finalMarks[indx] << " has " << names[indx] << endl;
    indx = LowestMarks(finalMarks);
    cout <<"The lowest score " << finalMarks[indx] << " has " << names[indx] << endl;
}

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

Dikeledi Matlala
01.07.21, 12:13

Your help means a lot. I now understand programming with your help. Thank You

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS