Question

In: Computer Science

On Lab 10 you did Chapter 8’s Programming Exercise 13, using the name Lab10TestScores and assuming...

On Lab 10 you did Chapter 8’s Programming Exercise 13, using the name Lab10TestScores and assuming that the class has ten students and five tests. Now let’s rewrite it to use dynamic arrays so that it will work for any number of students and any number of tests. Call this new program Lab11TestScores. Modify the program so that it asks the user to enter the number of students and the number of tests before it reads the data from the file named Lab11ScoresData.txt. (Two data files, Lab11ScoresData_5_3.txt and Lab11ScoresData_11_6.txt, are provided so you can use to test your program.). Let me know if you have questions. #include #include using namespace std; void readFile(string names[10], int scores[][5]) { ifstream in("Lab10ScoresData.txt"); for (int i = 0; i < 10; i++) { in >> names[i] >> scores[i][0] >> scores[i][1] >> scores[i][2] >> scores[i][3] >> scores[i][4]; } } void average(int scores[][5], float avg[], char grade[]) { int total; for (int i = 0; i < 10; i++) { total = 0; for (int j = 0; j < 5; j++) total += scores[i][j]; avg[i] = (float)total / (float)5; } for (int i = 0; i < 10; i++) { if (avg[i] >= 90) grade[i] = 'A'; if (avg[i] < 90 && avg[i] >= 80) grade[i] = 'B'; if (avg[i] < 80 && avg[i] >= 70) grade[i] = 'C'; if (avg[i] < 70 && avg[i] >= 60) grade[i] = 'D'; if (avg[i] < 60 && avg[i] >= 50) grade[i] = 'E'; if (avg[i] < 50) grade[i] = 'F'; } } void sortByName(string names[], float avg[], char grade[]) { for (int i = 0; i < 9; i++) { for (int j = i + 1; j < 10; j++) { if (names[i] > names[j]) { string n = names[i]; names[i] = names[j]; names[j] = n; float a = avg[i]; avg[i] = avg[j]; avg[j] = a; char g = grade[i]; grade[i] = grade[j]; grade[j] = g; } } } } void output(string names[], float avg[], char grade[]) { cout << "Name\tAverage\tGrade\n"; for (int i = 0; i < 10; i++) { cout << names[i] << "\t" << avg[i] << "\t" << grade[i] << endl; } } void countGrade(char grade[]) { int a = 0, b = 0, c = 0, d = 0, e = 0, f = 0; cout << "\n\nGrade\tCount\n"; for (int i = 0; i < 10; i++) { if (grade[i] == 'A') a++; if (grade[i] == 'B') b++; if (grade[i] == 'C') c++; if (grade[i] == 'D') d++; if (grade[i] == 'E') e++; if (grade[i] == 'F') f++; } cout << "A\t" << a << endl; cout << "B\t" << b << endl; cout << "C\t" << c << endl; cout << "D\t" << d << endl; cout << "E\t" << e << endl; cout << "F\t" << f << endl; } int main() { string names[10]; int scores[10][5]; float avg[10]; char grade[10]; readFile(names, scores); average(scores, avg, grade); sortByName(names, avg, grade); output(names, avg, grade); countGrade(grade); system(" pause "); return 0; }

Lab11ScoresData_11_6.txt.

Johnson 85 83 77 91 76 99
Aniston 80 90 95 93 48 100
Cooper 78 81 11 90 73 54
Gupta 92 83 30 69 87 78
Blair 23 45 96 38 59 82
Clark 60 85 45 39 67 67
Kennedy 77 31 52 74 83 77
Bronson 93 94 89 77 97 80
Sunny 79 85 28 93 82 45
Smith 85 72 49 75 63 92
Groot 90 87 94 75 100 100

Lab11ScoresData_5_3.txt

Johnson 85 83 77
Aniston 80 90 95
Cooper 78 81 11
Gupta 92 83 30
Blair 23 45 96

Solutions

Expert Solution

If you have any doubts, please give me comment...

#include <iostream>

#include <fstream>

using namespace std;

void readFile(string *names, int **scores, int num_studs, int num_tests)

{

    ifstream in("Lab11ScoresData.txt");

    for (int i = 0; i < num_studs; i++)

    {

        in >> names[i];

        for(int j=0; j<num_tests; j++)

            in>>scores[i][j];

    }

}

void average(int **scores, int num_studs, int num_tests, float *avg, char *grade)

{

    int total;

    for (int i = 0; i < num_studs; i++)

    {

        total = 0;

        for (int j = 0; j < num_tests; j++)

            total += scores[i][j];

        avg[i] = (float)total / (float)num_tests;

    }

    for (int i = 0; i < num_studs; i++)

    {

        if (avg[i] >= 90)

            grade[i] = 'A';

        if (avg[i] < 90 && avg[i] >= 80)

            grade[i] = 'B';

        if (avg[i] < 80 && avg[i] >= 70)

            grade[i] = 'C';

        if (avg[i] < 70 && avg[i] >= 60)

            grade[i] = 'D';

        if (avg[i] < 60 && avg[i] >= 50)

            grade[i] = 'E';

        if (avg[i] < 50)

            grade[i] = 'F';

    }

}

void sortByName(string *names, int num_studs, float *avg, char *grade)

{

    for (int i = 0; i < num_studs-1; i++)

    {

        for (int j = i + 1; j < num_studs; j++)

        {

            if (names[i] > names[j])

            {

                string n = names[i];

                names[i] = names[j];

                names[j] = n;

                float a = avg[i];

                avg[i] = avg[j];

                avg[j] = a;

                char g = grade[i];

                grade[i] = grade[j];

                grade[j] = g;

            }

        }

    }

}

void output(string *names, int num_studs, float *avg, char *grade)

{

    cout << "Name\tAverage\tGrade\n";

    for (int i = 0; i < num_studs; i++)

    {

        cout << names[i] << "\t" << avg[i] << "\t" << grade[i] << endl;

    }

}

void countGrade(char *grade, int num_studs)

{

    int a = 0, b = 0, c = 0, d = 0, e = 0, f = 0;

    cout << "\n\nGrade\tCount\n";

    for (int i = 0; i < 10; i++)

    {

        if (grade[i] == 'A')

            a++;

        if (grade[i] == 'B')

            b++;

        if (grade[i] == 'C')

            c++;

        if (grade[i] == 'D')

            d++;

        if (grade[i] == 'E')

            e++;

        if (grade[i] == 'F')

            f++;

    }

    cout << "A\t" << a << endl;

    cout << "B\t" << b << endl;

    cout << "C\t" << c << endl;

    cout << "D\t" << d << endl;

    cout << "E\t" << e << endl;

    cout << "F\t" << f << endl;

}

int main()

{

    int num_studs, num_tests;

    cout<<"Enter number of students: ";

    cin>>num_studs;

    cout<<"Enter number of tests: ";

    cin>>num_tests;

    string *names = new string[num_studs];

    int **scores = new int*[num_studs];

    for(int i=0; i<num_studs; i++)

        scores[i] = new int[num_tests];

    float *avg = new float[num_studs];

    char *grade = new char[num_studs];

    readFile(names, scores, num_studs,num_tests);

    average(scores, num_studs, num_tests, avg, grade);

    sortByName(names, num_studs, avg, grade);

    output(names, num_studs, avg, grade);

    countGrade(grade, num_studs);

    // system(" pause ");

    return 0;

}


Related Solutions

C++ Programming: Programming Design and Data Structures Chapter 13 Ex 2 Redo Programming Exercise 1 by...
C++ Programming: Programming Design and Data Structures Chapter 13 Ex 2 Redo Programming Exercise 1 by overloading the operators as nonmembers of the class rectangleType. The header and implementation file from Exercise 1 have been provided. Write a test program that tests various operations on the class rectangleType. I need a main.cpp file Given: **************rectangleType.cpp******************** #include <iostream> #include <cassert> #include "rectangleType.h" using namespace std; void rectangleType::setDimension(double l, double w) { if (l >= 0) length = l; else length =...
afe Rational Fractions In week 4 we completed Chapter 13 Programming Exercise #10 Page 974. Make...
afe Rational Fractions In week 4 we completed Chapter 13 Programming Exercise #10 Page 974. Make sure you have a working fractionType class before starting this assignment. The template requirement from week 4 is not required for this assignment. Your assignment this week is to make your fractionType class safe by using exception handling. Use exceptions so that your program handles the exceptions division by zero and invalid input. An example of invalid input would be entering a fraction such...
Chapter 8 Programming exercise 6 "Days of each month" Original Exercise: Design a program that displays...
Chapter 8 Programming exercise 6 "Days of each month" Original Exercise: Design a program that displays the number of days in each month. The program’s output should be similar to this: January has 31 days. February has 28 days. March has 31 days. April has 30 days. May has 31 days. June has 30 days. July has 31 days. August has 31 days. September has 30 days. October has 31 days. November has 30 days. December has 31 days. The...
Question Objective: The objective of this lab exercise is to give you practice in programming with...
Question Objective: The objective of this lab exercise is to give you practice in programming with one of Python’s most widely used “container” data types -- the List (commonly called an “Array” in most other programming languages). More specifically you will demonstrate how to: Declare list objects Access a list for storing (i.e., writing) into a cell (a.k.a., element or component) and retrieving (i.e., reading) a value from a list cell/element/component Iterate through a list looking for specific values using...
Modified from Chapter 07 Programming Exercise 5 Original Exercise: Rock, Paper, Scissors Modification Programming Exercise 11...
Modified from Chapter 07 Programming Exercise 5 Original Exercise: Rock, Paper, Scissors Modification Programming Exercise 11 in Chapter 6 asked you to design a program that plays the Rock, Paper, Scissors game. In the program, the user enters one of the three strings—"rock", "paper", or "scissors"—at the keyboard. Add input validation (with a case-insensitive comparison) to make sure the user enters one of those strings only. Modifications: Allow the user to input "r", "p", "s" or the full strings "Rock",...
This lab is an exercise of using Java’s and C++’s dynamic binding features. The uncompleted programs...
This lab is an exercise of using Java’s and C++’s dynamic binding features. The uncompleted programs to run in Java and in C++ are given below. Note that you need to create a driver class with the main method to run the Java program. Also, you need to write the main function to run the C++ program. Perform the following activities: predict the output of the Java program. run the Java program and compare your prediction to the actual output...
1. Chapter 5, Programming Challenge #8, Conversion Program (page 314). Program Name: FinalExamConversion. Write a program...
1. Chapter 5, Programming Challenge #8, Conversion Program (page 314). Program Name: FinalExamConversion. Write a program that asks the user to enter a distance in meters. The program will then present the following menu of selection: 1. Convert to Kilometers 2. Convert to Inches 3. Convert to Feet 4. Quit the Program The program will convert the distance to kilometers, inches or feet, depending on the user’s selection. Write the following methods: • getInput: This method prompts user to enter...
C++ PROGRAM Programming Exercise 11 in Chapter 8explains how to add large integers using arrays. However,...
C++ PROGRAM Programming Exercise 11 in Chapter 8explains how to add large integers using arrays. However, in that exercise, the program could add only integers of, at most, 20 digits. This chapter explains how to work with dynamic integers. Design a class named largeIntegers such that an object of this class can store an integer of any number of digits. Add operations to add, subtract, multiply, and compare integers stored in two objects. Also add constructors to properly initialize objects...
DIRECTIONS: Complete the following Programming Exercise in Python. Name the file Lastname_Firstname_E1. You just started your...
DIRECTIONS: Complete the following Programming Exercise in Python. Name the file Lastname_Firstname_E1. You just started your summer internship with ImmunityPlus based in La Crosse, Wisconsin. You are working with the forecasting team to estimate how many doses of an immunization drug will be needed. For each drug estimation, you will be provided the following information: corona.txt 39 20 31 10 42 49 54 21 70 40 47 60 - The size of the target population. - The life expectancy, in...
In this exercise, you will complete the Restaurant Tip application from Chapter 2’s Focus on the...
In this exercise, you will complete the Restaurant Tip application from Chapter 2’s Focus on the Concepts lesson. The application’s Planning Chart is shown in Figure 3-34. Use either a flowchart or pseudocode to plan the btnCalc_Click procedure, which should calculate and display a server’s tip. Open the Tip Solution.sln file contained in the VB2017\Chap03\Tip Solution folder. Enter the three Option statements in the Code Editor window. Use the comments as a guide when coding the btnCalc_Click procedure. Be sure...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT