1. #include "stdafx.h"
#include
#include
#include
#include
#include
using namespace std;
struct StudentData
{
int studentID;
string first_name;
string last_name;
int exam1;
int exam2;
int exam3;
int total;
char ch;
};
const int SIZE = 9;
const int INFO = 4;
// Function prototypes
void openInputFile(ifstream &, string);
void getTotal(StudentData[]);
void getGrade(StudentData[]);
void calcLowest(StudentData[], int &, int &, int &, int &, int[]);
void calcHighest(StudentData[], int &, int &, int &, int &, int[]);
void getAverage(StudentData[], int, double &, double &, double &, double &, double[]);
void getStd(StudentData[], double &, double &, double &, double &, double &, double &,
double &, double &, double[]);
void print(StudentData[], int[], int[], double[], double[]);
void sort(StudentData[]);
int main()
{
// Variables
StudentData arr[SIZE];
2. int lowest1, lowest2, lowest3, lowest4; // Stores lowest exam scores
int highest1, highest2, highest3, highest4; // Holds highest exam scores
double average1 = 0, average2 = 0, average3 = 0, average4 = 0; // Represents average of each
exam
double std1 = 0, std2 = 0, std3 = 0, std4 = 0; // Holds standard deviation for Exams 1-3 and
Total
int lowest[INFO] = {};
int highest[INFO] = {};
double average[INFO] = {};
double standardDeviation[INFO] = {};
ifstream inFile;
string inFileName = "C:UsersLisaDesktopscores.txt";
// Call function to read data in file
openInputFile(inFile, inFileName);
// Read data into an array of structs
for(int count = 0; count < SIZE; count++)
{
inFile >> arr[count].studentID >> arr[count].first_name >> arr[count].last_name >>
arr[count].exam1 >> arr[count].exam2 >> arr[count].exam3;
}
// Close input file
inFile.close();
// Get score total for each student
getTotal(arr);
// Determine grade for each student
getGrade(arr);
// Calculate lowest scores in each exam and total scores
calcLowest(arr, lowest1, lowest2, lowest3, lowest4, lowest);
// Calculate highest scores in each exam and total scores
calcHighest(arr, highest1, highest2, highest3, highest4, highest);
// Calculate average of each exam and the average of the total scores
getAverage(arr, SIZE, average1, average2, average3, average4, average);
// Calculate standard deviation of each category
getStd(arr, std1, std2, std3, std4, average1, average2, average3, average4, standardDeviation);
cout << " ";
// Print unsorted data
10. Solution
#include "stdafx.h"
#include
#include
#include
#include
#include
using namespace std;
struct StudentData
{
int studentID;
string first_name;
string last_name;
int exam1;
int exam2;
int exam3;
int total;
char ch;
};
const int SIZE = 9;
const int INFO = 4;
// Function prototypes
void openInputFile(ifstream &, string);
void getTotal(StudentData[]);
void getGrade(StudentData[]);
void calcLowest(StudentData[], int &, int &, int &, int &, int[]);
void calcHighest(StudentData[], int &, int &, int &, int &, int[]);
void getAverage(StudentData[], int, double &, double &, double &, double &, double[]);
void getStd(StudentData[], double &, double &, double &, double &, double &, double &,
double &, double &, double[]);
void print(StudentData[], int[], int[], double[], double[]);
void sort(StudentData[]);
int main()
{
// Variables
11. StudentData arr[SIZE];
int lowest1, lowest2, lowest3, lowest4; // Stores lowest exam scores
int highest1, highest2, highest3, highest4; // Holds highest exam scores
double average1 = 0, average2 = 0, average3 = 0, average4 = 0; // Represents average of each
exam
double std1 = 0, std2 = 0, std3 = 0, std4 = 0; // Holds standard deviation for Exams 1-3 and
Total
int lowest[INFO] = {};
int highest[INFO] = {};
double average[INFO] = {};
double standardDeviation[INFO] = {};
ifstream inFile;
string inFileName = "C:UsersLisaDesktopscores.txt";
// Call function to read data in file
openInputFile(inFile, inFileName);
// Read data into an array of structs
for(int count = 0; count < SIZE; count++)
{
inFile >> arr[count].studentID >> arr[count].first_name >> arr[count].last_name >>
arr[count].exam1 >> arr[count].exam2 >> arr[count].exam3;
}
// Close input file
inFile.close();
// Get score total for each student
getTotal(arr);
// Determine grade for each student
getGrade(arr);
// Calculate lowest scores in each exam and total scores
calcLowest(arr, lowest1, lowest2, lowest3, lowest4, lowest);
// Calculate highest scores in each exam and total scores
calcHighest(arr, highest1, highest2, highest3, highest4, highest);
// Calculate average of each exam and the average of the total scores
getAverage(arr, SIZE, average1, average2, average3, average4, average);
// Calculate standard deviation of each category
getStd(arr, std1, std2, std3, std4, average1, average2, average3, average4, standardDeviation);
cout << " ";