Question

C++ //StudentDataStructure.txt //Student records are stored in a parallel-array Data Structure. Here is the code to...

C++

//StudentDataStructure.txt

//Student records are stored in a parallel-array Data Structure. Here is the code to generate and populate Parallel-Array Data Structure:

const int NG = 4; //Number of Grades

string names[] = {"Amy Adams", "Bob Barr", "Carla Carr",
"Dan Dobbs", "Elena Evans"
};

int exams[][NG]= { {98,87,93,88},
{78,86,82,91},
{66,71,85,94},
{72,63,77,69},
{91,83,76,60}
};   

---------------------------------------------------------------------------------

1 A) Create and Populate a Parallel-Array Data Structure using the code described in "StudentDataStructure.txt". B) Define a Record Data Structure for student records. It should have the same fields that you defined in the Parallel-Array Data Structure(part 1A) with additional fields for average test scores and grade.

2) Declare an array of records.

3) Populate the Record Data Structure with the data which resides in the Parallel-Array Data Structure(part 1A).

4) Define a function to display formatted student records.
   
5) Define a function to compute average and the populate average field for each record.

6) Define a function to compute the grade and
the populate grade field for each record.

7) Define a function to compute class average.

8) Define a function to compute class standard deviation.

9) Display class average and standard deviation.

Homework Answers

Answer #1

//C++ Code

#include<iostream>
#include<iomanip>
using namespace std;

struct Record {
        string name;
        int exams[4];
        double average=0;
        char grade = ' ';
};
/* a function to compute class standard deviation.*/
double calculateSDV(Record records[], int size);
/*a function to compute class average.*/
double calculateClassAvg(Record records[], int size);
/* a function to display formatted student records*/
void displayRecords(Record records[], int size);
/**
function to compute average and the populate average field for each record.
*/
void calculateAverage(Record records[], int size);
/*a function to compute the grade and
the populate grade field for each record.*/
void calculateGrade(Record records[], int size);

double calculateSDV(Record records[], int size)
{
        double sdv = 0.0;
        double mean = calculateClassAvg(records, size);
        for (int i = 0; i < size; i++)
                sdv += pow(records[i].average - mean, 2);

        return sqrt(sdv / size);
}
double calculateClassAvg(Record records[], int size)
{
        double total = 0;
        for (size_t i = 0; i < size; i++)
        {
                total += records[i].average;
        }
        return total / size;
}
void calculateGrade(Record records[], int size)
{
        for (size_t i = 0; i < size; i++)
        {
                if (records[i].average >= 80)
                        records[i].grade = 'A';
                else if (records[i].average < 80 && records[i].average >= 60)
                        records[i].grade = 'B';
                else if (records[i].average >= 40 && records[i].average < 60)
                        records[i].grade = 'C';
                else
                        records[i].grade = 'D';
        }
}
void calculateAverage(Record records[], int size)
{
        double total = 0;
        for (size_t i = 0; i < size; i++)
        {
                total = records[i].exams[0] + records[i].exams[1] + records[i].exams[2] + records[i].exams[3];
                records[i].average = total / 4;
        
        }
}
void displayRecords(Record records[], int size)
{
        cout << fixed << setprecision(2);
        for (int i = 0; i < size; i++)
        {
                cout << "(" << (i + 1) <<") Student's Name: "<<left<<setw(15)<<records[i].name<< "Marks are: " << records[i].exams[0]
                        
                        << " " << records[i].exams[1] << " " << records[i].exams[2]
                        << " " << records[i].exams[3] << "  Average: " << right << " " << records[i].average << " Grade: " << records[i].grade << endl;
        }
}
int main()
{
        /* Declare an array of records.*/
        Record records[] = { {"Amy Adams",{98,87,93,88}} ,
                {"Bob Barr", {78,86,82,91}},
                {"Carla Carr",{66,71,85,94}},
                {"Dan Dobbs",{72,63,77,69}},
                {"Elena Evans",{91,83,76,60}} };

        displayRecords(records, 5);
        calculateAverage(records, 5);
        calculateGrade(records, 5);
        cout << endl;
        displayRecords(records, 5);
        double classAvg = calculateClassAvg(records, 5);
        double sdv = calculateSDV(records, 5);

        cout << "Class Average: " << classAvg << "\nStandard Deviation: " << sdv << endl;
        return 0;
}

//Output

//If you need any help regarding this solution....... please leave a comment. thanks

Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
write a program that automates the process of generating the final student report for DC faculty...
write a program that automates the process of generating the final student report for DC faculty considering the following restrictions. Consider declaring three arrays for processing the student data: studID studName studGrade The student ID is a random number generated by the 5-digit system in the range of (10000 - 99999). Create a function to assign the student ID generated in an array of numbers. Consider the following to generate the random number: Add the libraries: #include <stdlib.h> #include <ctime>...
Assignment #4 – Student Ranking : In this assignment you are going to write a program...
Assignment #4 – Student Ranking : In this assignment you are going to write a program that ask user number of students in a class and their names. Number of students are limited to 100 maximum. Then, it will ask for 3 test scores of each student. The program will calculate the average of test scores for each student and display with their names. Then, it will sort the averages in descending order and display the sorted list with students’...
we will be taking data in as a file. you cannot use the data values in...
we will be taking data in as a file. you cannot use the data values in your source file but you must read in everything into variables and use it from there. First we need to include <fstream> at the top of our file. We will need to create an input file stream to work and ifstream. ifstream is a datatype. Create a variable with the datatype being ifstream. Variable is drfine by using the member accessor operator to call...
Can someone please edit my code so that it satisfies the assignments' requirements? I pasted the...
Can someone please edit my code so that it satisfies the assignments' requirements? I pasted the codes below. Requirement: Goals for This Project:  Using class to model Abstract Data Type  OOP-Data Encapsulation You are asked to write an app to keep track of a relatively small music library. The app should load song information from a data file once the app is started. It should allow user to view, add, remove, and search for songs. The app should...
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT
Active Questions
  • Emerald Co. uses a perpetual inventory system and records purchases of merchandise at net cost. The...
    asked 20 minutes ago
  • Movie stars and U.S. presidents have fished Pyramid Lake. It is one of the best places...
    asked 54 minutes ago
  • what advantages do percent distributions have over frequency distributions when comparing populations at different years?
    asked 1 hour ago
  • Richard has just been given a 6-question multiple-choice quiz in his history class. Each question has...
    asked 1 hour ago
  • Write about westernized elements in life; westernization in our life, and this includes Americanization.
    asked 2 hours ago
  • The college Physical Education Department offered an Advanced First Aid course last summer. The scores on...
    asked 2 hours ago
  • Researchers hypothesized that increasing a woman's level of arousal would increase her perceptions of attractiveness of...
    asked 2 hours ago
  • Equation 37-14b in the textbook gives the energy emitted by Hydrogen when electrons transition between states...
    asked 2 hours ago
  • Theory of Computation Please provide explanation too on how it works a. Give an NFA recognizing...
    asked 2 hours ago
  • Question 1 A sequential pattern detection circuit (state machine) has input A and output Y, which...
    asked 2 hours ago
  • Natural Foods Inc. is planning to invest in new manufacturing equipment to make a new garden...
    asked 3 hours ago
  • Explain why a callable bond's price would be expected to decline less than an otherwise comparable...
    asked 3 hours ago