Create a class of records for a gradebook called Rec. The data should be private, and should include a firstname, lastname, array of three grades, and a field for average grade. Build two constructors: a default constructor and a constructor that takes the first and last name. Build a function to read the data, either from a file or from cin. The read function reads the two names and three grades, but does not read the average grade. Build a write function that writes the data either to a file or to cout. The write function prints all of the data on one line with spaces between fields. Build a function to calculate the average grade field. I will provide you with a driver called hw1.cpp in ~cthorpe/public/142 and with a test file HW1.txt in the same directory HW1.txt contains: Pete Jones 1 2 4 This is what I have done so far:   #include #include #include using namespace std; class Rec { private: string fname; string lname; int grades[3]; int avg_grade; public: Rec() { fname = "student"; lname = "one"; avg_grade = 0; grades = {0}; } Rec(string first, string last) { fname = first; lname = last; } void read(ifstream &in, string fname, string lname, int grades[], int avg_grade) { int i = 0; while (!in.eof()) { in >> fname >> lname >> grades[i]; i++; } } void write(string fname, string lname, int grades[],int avg_grade) { int i = 0; for (int i = 0; i < 3; i++) { cout << fname << " " << lname << " "; cout << grades[i] << " " << avg_grade << endl; } } }; int main() { Rec r1; Rec r2("Smith", "Jean"); ifstream instr; instr.open("HW1.txt"); cout << "Blank record" << endl; r1.write(cout); cout << "Initialized record" << endl; r2.write(cout); r1.read(instr); if (r1 == r2) cout << "same"; else cout << "different"; cout << endl; r1.calc_avg(); r1.write(cout); cout << endl; return 0; } I need help with the rest and want to know if I did anything wrong so far.

Computer Networking: A Top-Down Approach (7th Edition)
7th Edition
ISBN:9780133594140
Author:James Kurose, Keith Ross
Publisher:James Kurose, Keith Ross
Chapter1: Computer Networks And The Internet
Section: Chapter Questions
Problem R1RQ: What is the difference between a host and an end system? List several different types of end...
icon
Related questions
Question

Create a class of records for a gradebook called Rec.

The data should be private, and should include a firstname, lastname, array of three grades, and a field for average grade.

Build two constructors: a default constructor and a constructor that takes the first and last name.

Build a function to read the data, either from a file or from cin. The read function reads the two names and three grades, but does not read the average grade.

Build a write function that writes the data either to a file or to cout. The write function prints all of the data on one line with spaces between fields.

Build a function to calculate the average grade field.

I will provide you with a driver called hw1.cpp in ~cthorpe/public/142 and with a test file HW1.txt in the same directory

HW1.txt contains:

Pete Jones 1 2 4

This is what I have done so far:

 

#include <iostream>
#include <fstream>
#include <string>

using namespace std;


class Rec {
private:
string fname;
string lname;
int grades[3];
int avg_grade;
public:
Rec()
{
fname = "student";
lname = "one";
avg_grade = 0;
grades = {0};
}
Rec(string first, string last)
{
fname = first;
lname = last;
}
void read(ifstream &in, string fname, string lname, int grades[], int avg_grade)
{
int i = 0;
while (!in.eof())
{
in >> fname >> lname >> grades[i];
i++;
}

}
void write(string fname, string lname, int grades[],int avg_grade)
{
int i = 0;
for (int i = 0; i < 3; i++)
{
cout << fname << " " << lname << " ";
cout << grades[i] << " " << avg_grade << endl;
}
}
};

int main()
{
Rec r1;
Rec r2("Smith", "Jean");
ifstream instr;

instr.open("HW1.txt");

cout << "Blank record" << endl;
r1.write(cout);
cout << "Initialized record" << endl;
r2.write(cout);

r1.read(instr);
if (r1 == r2) cout << "same"; else cout << "different";
cout << endl;

r1.calc_avg();
r1.write(cout);
cout << endl;

return 0;
}

I need help with the rest and want to know if I did anything wrong so far.

C. OpenSSH SSH client
File Edit Options Buffers Tools C++ Help
#include <iostream>
#include <fstream>
using namespace std;
// Class declaration goes here
// function bodies go here
int main ()
{
Rec r1;
Rec r2("Smith", "Jean");
ifstream instr;
instr.open ("HW1.txt");
cout <« "Blank record" << endl;
r1.write(cout);
cout << "Initialized record" << endl:
r2.write(cout);
r1.read(instr);
if (r1 == r2) cout << "same"; else cout << "different":
cout << endl;
r1.calc_avg();
r1.write(cout);
cout <« endl;
return 0;
All L1
-UU-:%%-- F1 hw1.cpp
Loading cc-langs...done
(C++/1 Abbrev) -----
Transcribed Image Text:C. OpenSSH SSH client File Edit Options Buffers Tools C++ Help #include <iostream> #include <fstream> using namespace std; // Class declaration goes here // function bodies go here int main () { Rec r1; Rec r2("Smith", "Jean"); ifstream instr; instr.open ("HW1.txt"); cout <« "Blank record" << endl; r1.write(cout); cout << "Initialized record" << endl: r2.write(cout); r1.read(instr); if (r1 == r2) cout << "same"; else cout << "different": cout << endl; r1.calc_avg(); r1.write(cout); cout <« endl; return 0; All L1 -UU-:%%-- F1 hw1.cpp Loading cc-langs...done (C++/1 Abbrev) -----
Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 3 steps with 2 images

Blurred answer
Recommended textbooks for you
Computer Networking: A Top-Down Approach (7th Edi…
Computer Networking: A Top-Down Approach (7th Edi…
Computer Engineering
ISBN:
9780133594140
Author:
James Kurose, Keith Ross
Publisher:
PEARSON
Computer Organization and Design MIPS Edition, Fi…
Computer Organization and Design MIPS Edition, Fi…
Computer Engineering
ISBN:
9780124077263
Author:
David A. Patterson, John L. Hennessy
Publisher:
Elsevier Science
Network+ Guide to Networks (MindTap Course List)
Network+ Guide to Networks (MindTap Course List)
Computer Engineering
ISBN:
9781337569330
Author:
Jill West, Tamara Dean, Jean Andrews
Publisher:
Cengage Learning
Concepts of Database Management
Concepts of Database Management
Computer Engineering
ISBN:
9781337093422
Author:
Joy L. Starks, Philip J. Pratt, Mary Z. Last
Publisher:
Cengage Learning
Prelude to Programming
Prelude to Programming
Computer Engineering
ISBN:
9780133750423
Author:
VENIT, Stewart
Publisher:
Pearson Education
Sc Business Data Communications and Networking, T…
Sc Business Data Communications and Networking, T…
Computer Engineering
ISBN:
9781119368830
Author:
FITZGERALD
Publisher:
WILEY