Question

In: Computer Science

(c++)You will be given a data file containing data for 10 students. The format is as...

(c++)You will be given a data file containing data for 10 students. The format is as follows - grades are double precision numbers:

Line 1: Header Information

Line 2: Student Full name

Line 3: Student ID

Line 4: testgrade_1 testgrade_2 testgrade_3 testgrade_4 testgrade_5

Line 5: Student Full name

Line 6: Student ID

Line 7: testgrade_1 testgrade_2 testgrade_3 testgrade_4 testgrade_5

Line 8: Student Full name

Line 9: Student ID

Line 10: testgrade_1 testgrade_2 testgrade_3 testgrade_4 testgrade_5

Etc.

  1. Read the data into appropriate arrays. You do not need to create a dynamic array.

  2. Determine the average of all the grades for each test, and print the test number then the name, student id, and grade for all students who fall below that average.

  3. Determine the average of all the grades for each student.

  4. Determine which student has the highest average grades - print their name and their average

  5. Determine which student has the lowest average grades - print their name and their average

Student Learning Outcomes:

  • Creating and using functions

  • Creating and using non-dynamically allocated arrays - 1-Dimensional and/or 2-Dimensional

  • File input

  • Style

    • Variable Naming

      • Proper variable and function naming (not uppercase to start, descriptive of purpose)

      • Proper constant naming (all capital letters)

    • Comments

      • Programmer name, date, purpose

      • Useful, descriptive comments about program procedures

      • Useful, descriptive comments about function purpose, inputs, and outputs

Solutions

Expert Solution

#include <iostream>
#include <cstdio>
#include <fstream>
#include <string>
#include <cstdlib>
#define MAX 100
using namespace std;

// Defines a class Student
class Student
{
// Data member to store student data
string branch;
string name;
int id;
double marks[3];
public:
// Default constructor to assign default values to data member
Student()
{
branch = name = "";
id = 0;
marks[0] = marks[1] = marks[2] = 0.0;
}// End of default constructor

// Function to read file contents and stores it in array of object of Student class
// Returns number of records by reference
void readRecord(Student stu[], int &len)
{
string ch;
// ifstream class object declared to read data from file
ifstream fileRead;

// Opens both the file for reading
fileRead.open("studentInfo.txt");

// Checks if the file unable to open for reading display's error message and stop
if(!fileRead)
{
cout<<"\n ERROR: Unable to open the file for reading.";
exit(0);
}// End of if condition

// Loops till end of the file
while(!fileRead.eof())
{
// Reads a record
getline(fileRead, stu[len].branch, '\n');
getline(fileRead, stu[len].name, '\n');
fileRead>>stu[len].id;

// Reads the marks
for(int c = 0; c < 3; c++)
fileRead>>stu[len].marks[c];
// Reads new line character
getline(fileRead, ch, '\n');
// Increase the record counter
len++;
}// End of while loop
}// End of function

// Function to determine the average of all the grades for each student and returns average
double average(Student stu)
{
// To store total
double total = 0;
// Loops 3 times for marks
for(int d = 0; d < 3; d++)
// Calculates total
total += stu.marks[d];
// Returns average
return total / 3.0;
}// End of function

// Function to display all students information
void showAll(Student stu[], int len)
{
cout<<"\n\n *********** All Student Information *********** ";

// Loops till number of students
for(int c = 0; c < len; c++)
{
// Displays student information
cout<<"\n Branch: "<<stu[c].branch<<"\n Name: "<<stu[c].name<<"\n ID: "<<stu[c].id;
cout<<"\n Marks \n";

// Loop 3 times to display marks
for(int d = 0; d < 3; d++)
cout<<"\t Mark1: "<<stu[c].marks[d];
// Displays average
cout<<"\n Average: "<<average(stu[c]);
}// End of for loop
}// End of function

// Function to determine which student has the highest average grades - print their name and their average
void highestAvg(Student stu[], int len)
{
cout<<"\n\n *********** Student Highest Average *********** ";

// Calls the function to get the average of first student
// and stores it in maxAvg as maximum average
double maxAvg = average(stu[0]);
// Stores the first position as highest average student position
int pos = 0;

// Loops till number of students starting from 1
// Because 0th position student already considered above
for(int c = 1; c < len; c++)
{
// Calls the function to get average of each student
double currentAvg = average(stu[c]);

// Checks if current student average is greater then earlier student average
if(currentAvg > maxAvg)
{
// Assigns the current average as maximum average
maxAvg = currentAvg;
// Stores the index position as highest student position
pos = c;
}// End of if condition
}// End of for loop

// Displays student name and average
cout<<"\n Name: "<<stu[pos].name<<"\n Average: "<<maxAvg;
}// End of function

// Function to determine which student has the lowest average grades - print their name and their average
void lowestAvg(Student stu[], int len)
{
cout<<"\n\n *********** Student Lowest Average *********** ";

// Calls the function to get the average of first student
// and stores it in minAvg as minimum average
double minAvg = average(stu[0]);
// Stores the first position as lowest average student position
int pos = 0;

// Loops till number of students starting from 1
// Because 0th position student already considered above
for(int c = 1; c < len; c++)
{
// Calls the function to get average of each student
double currentAvg = average(stu[c]);

// Checks if current student average is less then earlier student average
if(currentAvg < minAvg)
{
// Assigns the current average as minimum average
minAvg = currentAvg;
// Stores the index position as lowest student position
pos = c;
}// End of if condition
}// End of for loop

// Displays student name and average
cout<<"\n Name: "<<stu[pos].name<<"\n Average: "<<minAvg;
}// End of function
};// End of class

// main function definition
int main()
{
// Creates an array of Student array of objects of size MAX
Student stu[MAX];
// Initializes the record counter to 0
int len = 0;

// Calls the function to read file contents
stu[0].readRecord(stu, len);

// Calls the function to display all student information
stu[0].showAll(stu, len);
// Calls the function to display highest average student information
stu[0].highestAvg(stu, len);
// Calls the function to display lowest student information
stu[0].lowestAvg(stu, len);
return 0;
}// End of main function

Sample Output:

*********** All Student Information ***********
Branch: CSE
Name: Pyari Mohan Sahu
ID: 111
Marks
Mark1: 99.23 Mark1: 98.77 Mark1: 89.88
Average: 95.96
Branch: ECE
Name: Ram Mohan Panda
ID: 132
Marks
Mark1: 78.21 Mark1: 67.31 Mark1: 81.45
Average: 75.6567
Branch: ME
Name: Tanvi Mohan Sahu
ID: 222
Marks
Mark1: 97.53 Mark1: 89.67 Mark1: 80.84
Average: 89.3467
Branch: CE
Name: Manvi Sahu
ID: 333
Marks
Mark1: 98.83 Mark1: 91.79 Mark1: 90.81
Average: 93.81

*********** Student Highest Average ***********
Name: Pyari Mohan Sahu
Average: 95.96

*********** Student Lowest Average ***********
Name: Ram Mohan Panda
Average: 75.6567

StudentInfo.txt file contents

CSE
Pyari Mohan Sahu
111
99.23 98.77 89.88
ECE
Ram Mohan Panda
132
78.21 67.31 81.45
ME
Tanvi Mohan Sahu
222
97.53 89.67 80.84
CE
Manvi Sahu
333
98.83 91.79 90.81


Related Solutions

Language C: Suppose you are given a file containing a list of names and phone numbers...
Language C: Suppose you are given a file containing a list of names and phone numbers in the form "First_Last_Phone." Write a program to extract the phone numbers and store them in the output file. Example input/output: Enter the file name: input_names.txt Output file name: phone_input_names.txt 1) Name your program phone_numbers.c 2) The output file name should be the same name but an added phone_ at the beginning. Assume the input file name is no more than 100 characters. Assume...
(C++) You are given a file consisting of students’ names in the following form: lastName, firstName...
(C++) You are given a file consisting of students’ names in the following form: lastName, firstName middleName. (Note that a student may not have a middle name.) Write a program that converts each name to the following form: firstName middleName lastName. Your program must read each student’s entire name in a variable and must consist of a function that takes as input a string, consists of a student’s name, and returns the string consisting of the altered name. Use the...
Write a C++ program to read a data file containing the velocity of cars crossing an...
Write a C++ program to read a data file containing the velocity of cars crossing an intersection. Then determine the average velocity and the standard deviation of this data set. Use the concept of vector array to store the data and perform the calculations. Include a function called “Standard” to perform the standard deviation calculations and then return the value to the main function for printing. Data to use. 10,15,20,25,30,35,40,45,50,55. Please use something basic.
Suppose you are given a file containing a list of names and phone numbers in the...
Suppose you are given a file containing a list of names and phone numbers in the form "First_Last_Phone." In C, Write a program to extract the phone numbers and store them in the output file. Example input/output: Enter the file name: input_names.txt Output file name: phone_input_names.txt 1) Name your program phone_numbers.c 2) The output file name should be the same name but an added phone_ at the beginning. Assume the input file name is no more than 100 characters. Assume...
In this assignment you will be given an input file containing a series of universities along...
In this assignment you will be given an input file containing a series of universities along with that universities' location and rating. You must write a program that uses user defined functions to output a list of all school's above a certain rating to the terminal. Your program should do the following: - Prompt the user for the name of the input file to open - Prompt the user for the rating threshold ( Note: we print if the rating...
Suppose you are given a file containing a list of names and phone numbers in the...
Suppose you are given a file containing a list of names and phone numbers in the form "First_Last_Phone." Write a program in C to extract the phone numbers and store them in the output file. Example input/output: Enter the file name: input_names.txt Output file name: phone_input_names.txt 1) Name your program phone_numbers.c 2) The output file name should be the same name but an added phone_ at the beginning. Assume the input file name is no more than 100 characters. Assume...
Suppose you are given a file containing a list of names and phone numbers in the...
Suppose you are given a file containing a list of names and phone numbers in the form "First_Last_Phone." Write a program to extract the phone numbers and store them in the output file. Example input/output: Enter the file name: input_names.txt Output file name: phone_input_names.txt 1) Name your program phone_numbers.c 2) The output file name should be the same name but an added phone_ at the beginning. Assume the input file name is no more than 100 characters. Assume the length...
Suppose you are given a file containing a list of names and phone numbers in the...
Suppose you are given a file containing a list of names and phone numbers in the form "First_Last_Phone." Write a program in C language to extract the phone numbers and store them in the output file. Example input/output: Enter the file name: input_names.txt Output file name: phone_input_names.txt 1) Name your program phone_numbers.c 2) The output file name should be the same name but an added phone_ at the beginning. Assume the input file name is no more than 100 characters....
(C++) Create a data file and name it "input.txt". manually save 10 integers into the file....
(C++) Create a data file and name it "input.txt". manually save 10 integers into the file. Write a program to read the data and calculate the average of events and odds, separately. Print out the average values.
Given a data file murders.dat containing the number of murders in Hampton roads cities write program...
Given a data file murders.dat containing the number of murders in Hampton roads cities write program code to accomplish the following: 1. Read the data from the murders.dat file and store into parallel arrays or an array of struct 2. Print the total number of murders in the Hampton roads cities 3. Print all of the data read 4. Print the name of the city with the most murders 5. Print the name of the city with the least murders...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT