# Answer to Question #50326 in C++ for John

Question #50326

Write a program that can enter marks for number of students and calculate their Total and class

average with the following format

The inputs:

ID (As 1 dimension array of Integers),marks(as 2 dimensional array of double), Grad (As 1 dimension

array of Chars)

The Grades are: A for 90’s, B for 80’s, C for 70’s, D for 60’s and F for less than 60.

Use the following functions to find

1. void inputID(int[]);

2. void inputMarks(double [][4]);

3. void Total(double[][4]);

4. void Grade(double[][4],char[]);

5. double ClassAverage(double[][4]);

6. void print(int[],double[][4],char[]);

The output:

St_Nm ID First Second Final Total Grade

1 20071156 15.5 16.5 30.1 62.1 D

2 20071154 15.0 16.5 30.1 62.6 D

Class average for 10 students is: 72.5

average with the following format

The inputs:

ID (As 1 dimension array of Integers),marks(as 2 dimensional array of double), Grad (As 1 dimension

array of Chars)

The Grades are: A for 90’s, B for 80’s, C for 70’s, D for 60’s and F for less than 60.

Use the following functions to find

1. void inputID(int[]);

2. void inputMarks(double [][4]);

3. void Total(double[][4]);

4. void Grade(double[][4],char[]);

5. double ClassAverage(double[][4]);

6. void print(int[],double[][4],char[]);

The output:

St_Nm ID First Second Final Total Grade

1 20071156 15.5 16.5 30.1 62.1 D

2 20071154 15.0 16.5 30.1 62.6 D

Class average for 10 students is: 72.5

Expert's answer

//Question #50326, Programming, C++

#include <iostream>

#include <conio.h>

using namespace std;

int n; // general number of students

//function prototypes

void inputID(int[]);

void inputMarks(double [][4]);

void Total(double[][4]);

void Grade(double[][4],char[]);

double ClassAverage(double[][4]);

void print(int[],double[][4],char[]);

void inputID(int idArray[]) {

cout << "Enter id's of students :\n";

for (int i = 0; i < n; i++) {

cin >> idArray[i];

}

}

void inputMarks(double marks[][4]) {

for (int i = 0; i < n; i++) {

cout << "Enter first, second and final marks for " << i + 1 << " student:\n";

cin >> marks[i][0] >> marks[i][1] >> marks[i][2];

}

}

void Total(double marks[][4]) {

for (int i = 0; i < n; i++) {

marks[i][3] = marks[i][0] + marks[i][1] + marks[i][2];

}

}

void Grade(double marks[][4],char grad[]) {

for (int i = 0; i < n; i++) {

if (marks[i][3] < 60) {

grad[i] = 'F';

continue;

}

if (marks[i][3] >= 60 && marks[i][3] < 70) {

grad[i] = 'D';

continue;

}

if (marks[i][3] >= 70 && marks[i][3] < 80) {

grad[i] = 'C';

continue;

}

if (marks[i][3] >= 80 && marks[i][3] < 90) {

grad[i] = 'B';

continue;

}

if (marks[i][3] >= 90) {

grad[i] = 'A';

continue;

}

}

}

double ClassAverage(double marks[][4]) {

double average = 0;

for (int i = 0; i < n; i++) {

average += marks[i][3];

}

return (average / n);

}

void print(int idArray[], double marks[][4], char grade[]) {

cout << "St_Nm\tID\tFirst\tSecond\tFinal\tTotal\tGrade" << endl;

for (int i = 0; i < n; i++) {

cout << i + 1 << "\t" << idArray[i] << "\t" << marks[i][0] << "\t" << marks[i][1] << "\t" << marks[i][2] << "\t" << marks[i][3] << "\t" << grade[i] << endl;

}

cout << endl;

cout << endl;

cout << "Class average for " << n <<" students is: " << ClassAverage(marks) << endl;;

}

void main() {

cout << "Enter general number of students:\n";

cin >> n;

cout << endl;

int *idArray = new int[n];

inputID(idArray);

double marks[100][4];

inputMarks(marks);

Total(marks);

char grade[100];

Grade(marks,grade);

print(idArray, marks, grade);

_getch();

}

#include <iostream>

#include <conio.h>

using namespace std;

int n; // general number of students

//function prototypes

void inputID(int[]);

void inputMarks(double [][4]);

void Total(double[][4]);

void Grade(double[][4],char[]);

double ClassAverage(double[][4]);

void print(int[],double[][4],char[]);

void inputID(int idArray[]) {

cout << "Enter id's of students :\n";

for (int i = 0; i < n; i++) {

cin >> idArray[i];

}

}

void inputMarks(double marks[][4]) {

for (int i = 0; i < n; i++) {

cout << "Enter first, second and final marks for " << i + 1 << " student:\n";

cin >> marks[i][0] >> marks[i][1] >> marks[i][2];

}

}

void Total(double marks[][4]) {

for (int i = 0; i < n; i++) {

marks[i][3] = marks[i][0] + marks[i][1] + marks[i][2];

}

}

void Grade(double marks[][4],char grad[]) {

for (int i = 0; i < n; i++) {

if (marks[i][3] < 60) {

grad[i] = 'F';

continue;

}

if (marks[i][3] >= 60 && marks[i][3] < 70) {

grad[i] = 'D';

continue;

}

if (marks[i][3] >= 70 && marks[i][3] < 80) {

grad[i] = 'C';

continue;

}

if (marks[i][3] >= 80 && marks[i][3] < 90) {

grad[i] = 'B';

continue;

}

if (marks[i][3] >= 90) {

grad[i] = 'A';

continue;

}

}

}

double ClassAverage(double marks[][4]) {

double average = 0;

for (int i = 0; i < n; i++) {

average += marks[i][3];

}

return (average / n);

}

void print(int idArray[], double marks[][4], char grade[]) {

cout << "St_Nm\tID\tFirst\tSecond\tFinal\tTotal\tGrade" << endl;

for (int i = 0; i < n; i++) {

cout << i + 1 << "\t" << idArray[i] << "\t" << marks[i][0] << "\t" << marks[i][1] << "\t" << marks[i][2] << "\t" << marks[i][3] << "\t" << grade[i] << endl;

}

cout << endl;

cout << endl;

cout << "Class average for " << n <<" students is: " << ClassAverage(marks) << endl;;

}

void main() {

cout << "Enter general number of students:\n";

cin >> n;

cout << endl;

int *idArray = new int[n];

inputID(idArray);

double marks[100][4];

inputMarks(marks);

Total(marks);

char grade[100];

Grade(marks,grade);

print(idArray, marks, grade);

_getch();

}

``

## Comments

## Leave a comment