Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

in c++, I have completed 1-9 i need help with 10. i have included all the instructions incase you want them. My code is at

in c++, I have completed 1-9 i need help with 10. i have included all the instructions incase you want them. My code is at the bottom and a sample of what is supposed to be done is below the code.(The text file grades is in order of charms,defense herbology,potions,transfiguration)(the year is at the end of each students name in students.txt file)

1. Create a structure called Student with the following data elements: (5 points)

name - string house - string year - integer grades - array of doubles of size 5 average - double

2. Create a structure called Course with the following data elements: (5 points) subject - string

year avg - array of doubles of size 7 3. Open the file students.txt. The first line of this file is an integer that will tell you the number

of students in the gradebook. Read in size from the file. (2 points)

4. Create a dynamic array of Student structures with size number of elements. (5 points)

5. Create an array of Course structures of size 5. This one should be local to main, and not

dynamic. (4 points)

6.Continue reading from students.txt into the array of Student structures. Each following line of the file will be of the format name * house * year Please make sure you watch out for the newlines while reading. (10 points)

7. Open the file grades.txt. This file will have one less line than the student file. Each line of this file will have 5 doubles. The grades on line k will be the grades for the student on line k+1 of the student file. The grades will always be in the order - Charms Defense Herbology Potions Transfiguration (space separated) (3 points)

8. Read data from the grade file into each students record. Calculate each students individual average and store it in the structure. (15 points)

9. Calculate the count of students in each year. (6 points)

10. Iterate through the array of students and use this data to calculate the average for each

subject for each of the 7 years at Hogwarts. (12 points)

11. Open a file called report.txt. Use the student array to print the name of the student and their grade average into this file. (10 points)

12.Once all the student information has been printed, print the average of each subject by year into the file. (15 points)

13. Delete the dynamic array of students. (3 points)

here are the files i used.

students.txt

12 Bronwen Bennett * Hufflepuff * 3 Edward Kerley * Slytherin * 1 Linda Fawcett * Hufflepuff * 6 Reginald Shipway * Gryffindor * 4 Ann Trevithick * Ravenclaw * 7 Michael Hennessey * Gryffindor * 2 Stephen Perkins * Slytherin * 3 Dogan Sagar * Gryffindor * 5 Rebecca Cunningham * Ravenclaw * 4 Laetitia Trigg * Hufflepuff * 2 Bruce Embleton * Slytherin * 5 Alan Myerscough * Ravenclaw * 7 

grades.txt

62 38 80 65 87 52 51 91 31 51 36 73 67 96 84 56 87 38 45 78 75 66 37 89.5 67 96 86 68 90 62 32 73 31.5 85 35 86 84 90 90 41 60 60 48 65 55 30.5 53 93 45 39 35 55 88 48 70 94 94 30 66 62 

report.txt

Bronwen Bennett 66.4 Edward Kerley 55.2 Linda Fawcett 71.2 Reginald Shipway 60.8 Ann Trevithick 66.9 Michael Hennessey 80.4 Stephen Perkins 51.3 Dogan Sagar 78.2 Rebecca Cunningham 57.6 Laetitia Trigg 52.1 Bruce Embleton 59.2 Alan Myerscough 69.2 

MY code

#include #include #include #include #include using namespace std;

struct Student { string name, house; int year; double grades[5]; double average; }; struct Course { string subject; double year_avg[7]; }; int main() { int size; Student *students; Course *course; ifstream in, IN; in.open("students.txt"); if (!in) cout << "error opening students.txt file"; else { in >> size; students = new Student[size]; Course courselist[5]; for (int i = 0; i < size; i++) { char star; in.ignore(); getline(in, students[i].name, '*'); getline(in, students[i].house, '*'); in >> students[i].year; } IN.open("grades.txt"); if (!IN) cout << "error opening grades.txt file"; else { double avg = 0.0,vals; for (int i = 0; i < size; i++) { for (int j = 0; j < 5; j++) { IN >> vals; students[i].grades[j] = vals; avg += vals; } avg = avg / 5; students[i].average = avg; } } int count1=0, count2=0, count3=0, count4=0, count5=0, count6=0, count7=0; for (int i = 0; i < size; i++) { if (students[i].year = 1) count1++; if (students[i].year = 2) count2++; if (students[i].year = 3) count3++; if (students[i].year = 4) count4++; if (students[i].year = 5) count5++; if (students[i].year = 6) count6++; if (students[i].year = 7) count7++; }

} }

Sample of what needs to be done.

Charms: Year 1: 52 Year 2: 63.25 Year 3: 47 Year 4: 58 Year 5: 60.5 Year 6: 36 Year 7: 84.5 
Defense: Year 1: 51 Year 2: 69.5 Year 3: 55.5 Year 4: 73.5 Year 5: 69.5 Year 6: 73 Year 7: 80 
Herbology: Year 1: 91 Year 2: 80.5 Year 3: 55.75 Year 4: 43 Year 5: 89 Year 6: 67 Year 7: 33.5 
Potions: Year 1: 31 
Year 2: 67.5 Year 3: 75 Year 4: 55 Year 5: 69 Year 6: 96 Year 7: 77.75 
Transfiguration: Year 1: 51 Year 2: 50.5 Year 3: 61 
Year 4: 66.5 Year 5: 55.5 Year 6: 84 Year 7: 64.5 

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Expert Oracle Database Architecture

Authors: Thomas Kyte, Darl Kuhn

3rd Edition

1430262990, 9781430262992

More Books

Students also viewed these Databases questions