Write a program Gradebook using three classes: Course, Student, and Person that
ID: 660406 • Letter: W
Question
Write a program Gradebook using three classes: Course, Student, and Person that reads the attached input.txt file and writes an output.txt file following the sample below for each student:
Student Name: [blank] [blank]
Student ID: [blank]
Number of courses enrolled: [blank]
Course No Course Name Credits Grade
[blank] [blank] [blank]
Total number of credit hours: [blank]
Mid-Semester GPA: [blank]
-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-
Class Student should inherit from Person and Course. If a student has not paid their tuition (hint: look for N instead of Y after the id number in the input file), withhold their grades from the output and print an appropriate message.
Attached are header and cpp files to help get you started, as well as a sample output file your program should imitate. Declare and define any missing functions as appropriate.
Can anyone help me with this problem? i still need to get the input.txt and output.txt
#include
#include
using namespace std;
class person
{
public:
char *firstName;
char *lastName;
int id,noCourse;
void getValues()
{
cout<<" Enter first name:";
cin>>firstName;
cout<<" Enter last name:";
cin>>lastName;
cout<<" Enter ID:";
cin>>id;
cout<<" Enter number of courses enrolled:";
cin>>noCourse;
}
void putValues()
{
cout<<" Student Name:";
cout< cout<<" StudentID:";
cout< cout<<" Number of student enrolled:";
cout< }
};
class course:public person
{
public:
int courseno,coursename,creditsgrade;
void getValue_course()
{
getValues();
cout<<" Enter course number:";
cin>>courseno;
cout<<" Enter course name:";
cin>>coursename;
cout<<" Enter credits grade:";
cin>>creditsgrade;
}
void putValue_course()
{
putValues();
cout<<" course number:";
cout< cout<<" course name:";
cout< cout<<" credits grade:";
cout< }
};
class student:public course
{
public:
float credithours,gpa;
void getvalue_student()
{
getValue_course();
cout<<" Enter creditHours:";
cin>>credithours;
cout<<" Enter mid-semester GPA:";
cin>>gpa;
}
void putvalue_student()
{
getValue_course();
cout<<" Total credit Hours:";
cin>>credithours;
cout<<" Enter mid-semester GPA:";
cin>>gpa;
}
};
void main()
{
}
Explanation / Answer
Here is the code that you can attached with your program to read and write information.
Read / Write a Text File
An example of how to read a text file using C++
you can create a text file "myfile.txt", and type the following lines
It is a test file
It is the second line of the test file
After that let's write a C++ program to read this file:
#include <iostream>
#include <fstream>
#include <string>
using namespace std;
int main () {
string line;
//By using ifstream to input file stream from a text file
ifstream myfile ("input.txt");
if (myfile.is_open())
{
while (! myfile.eof() )
{
getline (myfile.line);
cout << line << endl;
}
myfile.close();
}
else cout << "Can't open file";
return 0;
}
To write a strings to a text file you can write a program like this
#include <iostream>
#include <fstream>
using namespace std;
int main () {
// The ofstream to output strings to a text file
ofstream myfile ("output.txt");
if (myfile.is_open())
{
myfile << "This is a test. ";
myfile << "I am learning C++. ";
myfile.close();
}
else cout << "Can't open file";
return 0;
}
In the above two example, you have to include Stream class "fstream" as a header file to both read and write fromthe files. After that, for reading (input) from a text file, we use "ifstream" , for writing (output) to a text file, you can use "ofstream".
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.