Please program in C++ and document the code as you go so I can understand what you did for example ///This code does~
Your help is super appreciated. Ill make sure to like and review to however the best answer needs.
Overview
You will revisit the program that you wrote for Assignment 2 and add functionality that you developed in Assignment 3. Some additional functionality will be added to better the reporting of the students’ scores. There will be 11 students total.
Specifications
The grading scheme is: Test #1 -- 25% Test #2 -- 25% Test #3 -- 25% Test #4 -- 25% The student data is stored in a "students.txt" file that has all of the students’ names and test scores. The file has the following configuration: (first name) (last name) (Test1) (Test2) (Test3) (Test4)
Requirements
Create a "grades.txt" file that has a detailed summary of the final grades for each student. The file should have the following configuration:
1) Header with last name, first name, test scores, and final grade
2) A list of all student in alphabetical order by last name along with their test scores and final grade
3) A concluding summary with the following data: a) average score b) min score c) max score Formatting: last name - 15 character field, left justified first name - 15 character field, left justified score/grade - 7 character field, right justified, decimal format, one decimal place, decimal always shown The final grades must be calculated using the above mentioned grading scheme. The following files are given to test your program: "students.txt" – input file "grades.txt" - output file
Submission
You will submit one file for credit: assignment4.cpp - your Assignment 4 source code
Last Name First Name Test 1 Test 2 Test 3 Test 4 Grade Chambler Tara 81.0 74.0 95.0 91.0 85.2 Dixon Daryl 89.0 95.0 90.0 99.0 93.2 Espinosa Rosita 88.0 90.0 93.0 92.0 90.8 Greene Maggie 85.0 82.0 94.0 90.0 87.8 Greene Beth 75.0 82.0 89.0 81.0 81.8 Grimes Carl 75.0 84.0 92.0 89.0 85.0 Grimes Rick 92.0 96.0 85.0 100.0 93.2 Peletier Carol 84.0 91.0 89.0 95.0 89.8 Porter Eugene 96.0 98.0 100.0 95.0 97.2 Rhee Glenn 94.0 99.0 97.0 95.0 96.2 Williams Sasha 79.0 84.0 90.0 95.0 87.0 Mean = 89.8 Min = 81.8 Max = 97.2
Daryl Dixon 89 95 90 99 Rick Grimes 92 96 85 100 Glenn Rhee 94 99 97 95 Maggie Greene 85 82 94 90 Carl Grimes 75 84 92 89 Carol Peletier 84 91 89 95 Beth Greene 75 82 89 81 Sasha Williams 79 84 90 95 Tara Chambler 81 74 95 91 Rosita Espinosa 88 90 93 92 Eugene Porter 96 98 100 95
edit: previous code sorry about that.
#include <iostream>
#include <iomanip>
#include <fstream>
#include <cmath>
using namespace std;
/// Declare global constants
const char* IN_FILE_NAME = "stats.txt";
const char* OUT_FILE_NAME = "results.txt";
const int ELEMENTS = 100;
/// Function Prototypes
bool getTrialElements(ifstream&, double[], int);
void sortElements(double[], int);
double findMean(double[], int);
double findMedian(double[], int);
double findMinimum(double[], int);
double findMaximum(double[], int);
double findStdDev(double[], int);
void printTrialResults(ofstream&, int, double[], int);
/// This program uses basic statistics with set of data
points
int main()
{
/// Declare variables
ifstream inFile;
ofstream outFile;
int trialNumber = 0;
double elementArray[ELEMENTS];
/// Open input and output files
inFile.open(IN_FILE_NAME);
outFile.open(OUT_FILE_NAME);
/// Loop through all of the data sets in the file
while(getTrialElements(inFile, elementArray, ELEMENTS))
{
/// Keep track of the number of data sets processed
trialNumber++;
/// Output the results to the output file
printTrialResults(outFile, trialNumber, elementArray,
ELEMENTS);
}
/// Close input and output files
outFile.close();
inFile.close();
return 0;
}
bool getTrialElements(ifstream& fin, double array[], int
size)
{
int i;
for(i = 0; i < 100 && !fin.eof(); i++) //Read all
element.
fin >> array[i];
if(i != 100) //If the trial doesn't have 100 elements
return false; //Return false.
return true; //Return true if not.
}
void sortElements(double array[], int size) //sorts
{
for(int i = 0; i < size-1; i++)
for(int j = 0; j < size-i-1; j++)
if(array[j] < array[j+1])
{
double temp = array[j];
array[j] = array[j+1];
array[j+1] = temp;
}
}
double findMean(double array[], int size) //the mean
{
double sum = 0;
for(int i = 0; i < size; i++)
sum += array[i];
return sum / size;
}
double findMedian(double array[], int size) //the median
{
sortElements(array, size);
if(size % 2 == 0)
return (array[size/2] + array[size/2-1]) / 2.0;
return array[size/2];
}
double findMinimum(double array[], int size) //theMinimum
{
double min = array[0];
for(int i = 1; i < size; i++)
if(array[i] < min)
min = array[i];
return min;
}
double findMaximum(double array[], int size) //themaximum
{
double max = array[0];
for(int i = 1; i < size; i++)
if(array[i] > max)
max = array[i];
return max;
}
double findStdDev(double array[], int size) //stdDev
{
double stdDev = 0;
double avg = findMean(array, size);
for(int i = 0; i < size; i++)
stdDev += pow(array[i] - avg, 2);
stdDev = sqrt(1/(double)size * stdDev);
return stdDev;
}
void printTrialResults(ofstream&, int trialNumber, double
array[], int size) //TrialResults displayed
{
cout << "trial " << setw(5) << left <<
trialNumber;
cout << "mean: " << setw(6) << left <<
fixed << setprecision(1) << findMean(array,
size);
cout << "median: " << setw(6) << left <<
fixed << setprecision(1) << findMedian(array,
size);
cout << "min: " << setw(6) << left << fixed
<< setprecision(1) << findMinimum(array, size);
cout << "max: " << setw(6) << left << fixed
<< setprecision(1) << findMaximum(array, size);
cout << "std dev: " << setw(6) << left <<
fixed << setprecision(1) << findStdDev(array,
size);
cout << endl;
}
#include <iostream>
#include <iomanip>
#include <fstream>
#include <cmath>
using namespace std;
/// Declare global constants
const char* IN_FILE_NAME = "students.txt";
const char* OUT_FILE_NAME = "grades.txt";
const int SIZE = 100;
/// Defining structure
struct Student
{
string fname, lname;
double test[4];
double grade;
};
/// Function Prototypes
int readFile(ifstream&, Student[]);
void findGrade(Student[], int);
double findMean(Student[], int);
void sortElements(Student[], int size);
double findMinimum(Student[], int);
double findMaximum(Student[], int);
void writeFile(ofstream&, Student[], int);
int main()
{
/// Declare variables
ifstream inFile;
ofstream outFile;
Student stud[SIZE];
int n = 0;
/// Open input and output files
inFile.open(IN_FILE_NAME);
outFile.open(OUT_FILE_NAME);
/// Calling function to read input file
n = readFile(inFile, stud);
///Calling function to calculate grade
findGrade(stud, n);
///Calling function to write data into output file
writeFile(outFile, stud, n);
/// Close input and output files
outFile.close();
inFile.close();
return 0;
}
///Function to read input file and
/// store data into structure
int readFile(ifstream& fin, Student array[])
{
int i=0;
while(!fin.eof())
{
//Read all element
fin >> array[i].fname >> array[i].lname;
for(int j=0; j<4; j++)
fin >> array[i].test[j];
i++;
}
return i; //Return number of students
}
//Function to calculate grade of students
void findGrade(Student array[], int size)
{
for(int i=0; i<size; i++)
{
array[i].grade=0;
for(int j=0; j<4; j++)
{
array[i].grade += array[i].test[j]*0.25;
}
}
}
///Function to sort the array of students by last name
void sortElements(Student array[], int size) //sorts
{
for(int i = 0; i < size-1; i++)
for(int j = 0; j < size-i-1; j++)
if(array[j].lname > array[j+1].lname)
{
Student temp = array[j];
array[j] = array[j+1];
array[j+1] = temp;
}
}
//Function to find the mean of grades of students
double findMean(Student array[], int size) //the mean
{
double sum = 0;
for(int i = 0; i < size; i++)
sum += array[i].grade;
return sum / size;
}
///Function to detemine minimum grade
double findMinimum(Student array[], int size) //theMinimum
{
double min = array[0].grade;
for(int i = 1; i < size; i++)
if(array[i].grade < min)
min = array[i].grade;
return min;
}
///Function to detemine maximum grade
double findMaximum(Student array[], int size) //themaximum
{
double max = array[0].grade;
for(int i = 1; i < size; i++)
if(array[i].grade > max)
max = array[i].grade;
return max;
}
///Function to write data into file
void writeFile(ofstream& fout, Student array[], int size) //TrialResults displayed
{
fout<<left<<setw(15)<<"Last Name"<<left<<setw(15)<<"First Name"<<right<<setw(7)<<"Test1"
<<right<<setw(7)<<"Test2"<<right<<setw(7)<<"Test3"
<<right<<setw(7)<<"Test4"<<right<<setw(7)<<"Grade"<<endl;
sortElements(array, size);
fout << setprecision(1) <<fixed;
for(int i = 0; i < size; i++)
{
fout<<left<<setw(15)<<array[i].lname<<left<<setw(15)<<array[i].fname;
for(int j=0; j<4; j++)
fout<<right<<setw(7)<<array[i].test[j];
fout<<right<<setw(7)<<array[i].grade<<endl;
}
fout << endl;
fout << "Mean = "<< findMean(array, size)<<endl;
fout << "Min = " << findMinimum(array, size)<<endl;
fout << "Max = " << findMaximum(array, size)<<endl;
}
Sample input file "students.txt":
Before executing above program you need to create "students.txt" file and store it into current working folder.
Content of output file "grades.txt" after executing program:-
Please program in C++ and document the code as you go so I can understand what...
I need a detailed pseudocode for this code in C ++. Thank you #include <iostream> #include <string> #include <iomanip> using namespace std; struct Drink { string name; double cost; int noOfDrinks; }; void displayMenu(Drink drinks[], int n); int main() { const int size = 5; Drink drinks[size] = { {"Cola", 0.65, 2}, {"Root Beer", 0.70, 1}, {"Grape Soda", 0.75, 5}, {"Lemon-Lime", 0.85, 20}, {"Water", 0.90, 20} }; cout <<...
Hello, I need to implement these small things in my C++ code. Thanks. 1- 10 characters student first name, 10 characters middle name, 20 characters last name, 9 characters student ID, 3 characters age, in years (3 digits) 2- Open the input file. Check for successful open. If the open failed, display an error message and return with value 1. 3- Use a pointer array to manage all the created student variables.Assume that there will not be more than 99...
I want to change this code and need help. I want the code to not use parallel arrays, but instead use one array of struct containing the data elements, String for first name, String for last name,Array of integers for five (5) test scores, Character for grade. If you have any idea help would be great. #include #include #include #include using namespace std; const int NUMBER_OF_ROWS = 10; //number of students const int NUMBER_OF_COLUMNS = 5; //number of scores void...
The following code is for Chapter 13 Programming Exercise 21. I'm not sure what all is wrong with the code written. I get errors about stockSym being private and some others after that.This was written in the Dev C++ software. Can someone help me figure out what is wrong with the code with notes of what was wrong to correct it? #include <cstdlib> #include <iostream> #include <iomanip> #include <fstream> #include <cassert> #include <string> using namespace std; template <class stockType> class...
Can anyone help me with my C++ assignment on structs, arrays and bubblesort? I can't seem to get my code to work. The output should have the AVEPPG from highest to lowest (sorted by bubbesort). The output of my code is messed up. Please help me, thanks. Here's the input.txt: Mary 15 10.5 Joseph 32 6.2 Jack 72 8.1 Vince 83 4.2 Elizabeth 41 7.5 The output should be: NAME UNIFORM# AVEPPG Mary 15 10.50 Jack 72 8.10 Elizabeth 41 7.50 Joseph 32 6.20 Vince 83 4.20 My Code: #include <iostream>...
IN C++ PLEASE -------Add code to sort the bowlers. You have to sort their parallel data also. Print the sorted bowlers and all their info . You can use a bubble sort or a shell sort. Make sure to adjust your code depending on whether or not you put data starting in row zero or row one. Sort by Average across, lowest to highest. The highest average should then be on the last row.. When you sort the average, you...
In c++ programming, can you please edit this program to meet these requirements: The program that needs editing: #include <iostream> #include <fstream> #include <iomanip> using namespace std; int cal_avg(char* filenumbers, int n){ int a = 0; int number[100]; ifstream filein(filenumbers); if (!filein) { cout << "Please enter a a correct file to read in the numbers from"; } while (!filein.eof()) { filein >> number[a]; a++; } int total = number[0]; for (a = 0; a < n; a++) {...
The following is a sample inventory in C++, i want to ask the user to input a item number for removing from inventory. //CPP #include <iostream> #include <fstream> #include <cstdlib> #include <iomanip> #define MAX 1000 using namespace std; //Function to Add a new inventory item to the data into the array in memory void addItem(string desc[],string idNum[], float prices[], int qty[],int &num) { cout<<"Enter the names:"; cin>>desc[num]; cout<<"Enter the item number:"; cin>>idNum[num]; cout<<"Enter the price of item:"; cin>>prices[num]; cout<<"Enter the...
Expand the payroll program to combine two sorting techniques (Selection and Exchange sorts) for better efficiency in sorting the employee’s net pay. //I need to use an EXSEL sort in order to combine the selection and Exchange sorts for my program. I currently have a selection sort in there. Please help me with replacing this with the EXSEL sort. //My input files: //My current code with the sel sort. Please help me replace this with an EXSEL sort. #include <fstream>...
Hello I need a small fix in my program. I need to display the youngest student and the average age of all of the students. It is not working Thanks. #include <iostream> #include <iomanip> #include <fstream> #include <vector> #include <algorithm> using namespace std; struct Student { string firstName; char middleName; string lastName; char collegeCode; int locCode; int seqCode; int age; }; struct sort_by_age { inline bool operator() (const Student& s1, const Student& s2) { return (s1.age < s2.age); // sort...