60 322
Assignments Done
Successfully Done
In April 2018

Answer to Question #50452 in C++ for Goerge

Question #50452
Write a program that can enter marks for number of students and calculate their Total and class
average with the following format

((((((((((((((((((((((((((((((((((((WITHOUT using functions)0))))))))))))))))))))))))))))))))

The inputs:

ID (As 1 dimension array of Integers), First (As1 dimension array of Doubles), Second (As 1 dimension
array of Doubles), Final (As 1 dimension array of Doubles), Total (As 1 dimension array of Doubles), 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.

Example of 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
#include <cstdlib>
#include <iostream>
#include <stdio.h>
using namespace std;
int main() {
    int n;
    printf("Input number of students: ");
    /*Create array to store data of each student.*/
    int ID[n];
    float first[n];
    float second[n];
    float final[n];
    float total[n];
    char grade[n];
    float sum = 0;
    /*Read data for each student.*/
    for (int i = 0; i < n; i++) {
        printf("Enter data for students %d: \n", i + 1);
        printf(" - ID: ");
        cin >> ID[i];
        printf(" - First mark: ");
        cin >> first[i];
        printf(" - Second mark: ");
        cin >> second[i];
        printf(" - Final mark: ");
        cin >> final[i];
        /* Compute total mark.*/
        total[i] = first[i] + second[i] + final[i];
        /* Calculate the sum.*/
        sum += total[i];
        /* Calculate the grate using total mark.*/
        if (total[i] >= 90)
            grade[i] = 'A';
        else if (total[i] >= 80)
            grade[i] = 'B';
        else if (total[i] >= 70)
            grade[i] = 'C';
        else if (total[i] >= 60)
            grade[i] = 'D';
        else grade[i] = 'F';
    /* Calculate average mark. */
    float classAveMark = sum / n;
    printf("%6s %9s %6s %6s %6s %6s %4s\n", "St_Nm", "ID", "Fisrt", "Second", "Final", "Total", "Grade");
    for (int i = 0; i < n; i++)
        printf("%6d %9d %6.1f %6.1f %6.1f %6.1f %5c\n", i + 1, ID[i], first[i], second[i], final[i], total[i], grade[i]);
    /* Print class mark.*/
    printf("\nClass average for %d students is: %.2f\n", n, classAveMark);
    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!


No comments. Be first!

Leave a comment

Ask Your question

Privacy policy Terms and Conditions