I just need help to finish this program: //PURPOSE: Demonstrate usage of records
ID: 3618309 • Letter: I
Question
I just need help to finish this program: //PURPOSE: Demonstrate usage of records using C++ struct to store information// about a student. Structs are used in function arguments.
#include <iostream>
#include <string>
using namespace std;
// Complete the
following StudentRec declaration that contains
// student name, tuition, gpa, and major as fields.
struct StudentRec
//function prototypes
void readStudentInfo(StudentRec& aStudent, istream& cin); // provide
function prototype for printStudentInfo
int main ()
{
//variables
StudentRec studentInfo; //used to read in student information
//input and print all student records // add priming
read function call here
while (cin)
{
// provide the function call for printing the student recordread
// provide the function call for reading the next studentrecord
}
return 0;
}
//This function reads information about a student from the standard input
// Do NOT add any prompt to the user! // provide the
function definition of readStudentInfo that matchs
// with the aboveprototype: Do NOT add any prompt to theuser!
// need the function heading and { }
//Read in all information for the student
// CHECK data files for the order of fields to read in
// the last cin using >> leaves the end of line character incin
// use the following lines for reading the end of the line
string endOfLine;
getline(cin,endOfLine);
//purpose: Print out the information about a student.
void printStudentInfo(const StudentRec& aStudent)
{
//Print out all student information
cout << endl << "-------------------------------------------"<<endl;
cout <<"Student's Name: " << aStudent.name << endl;
cout <<"Student's Tuition : "<< aStudent.tuition << endl;
cout <<"The Student't GPA : "<< aStudent.gpa << endl;
cout <<"The Student's Major : " << aStudent.major <<endl;
}
I just need help to finish this program: //PURPOSE: Demonstrate usage of records using C++ struct to store information
// about a student. Structs are used in function arguments.
#include <iostream>
#include <string>
using namespace std;
// Complete the
following StudentRec declaration that contains
// student name, tuition, gpa, and major as fields.
struct StudentRec
//function prototypes
void readStudentInfo(StudentRec& aStudent, istream& cin); // provide
function prototype for printStudentInfo
int main ()
{
//variables
StudentRec studentInfo; //used to read in student information
//input and print all student records // add priming
read function call here
while (cin)
{
// provide the function call for printing the student recordread
// provide the function call for reading the next studentrecord
}
return 0;
}
//This function reads information about a student from the standard input
// Do NOT add any prompt to the user! // provide the
function definition of readStudentInfo that matchs
// with the aboveprototype: Do NOT add any prompt to theuser!
// need the function heading and { }
//Read in all information for the student
// CHECK data files for the order of fields to read in
// the last cin using >> leaves the end of line character incin
// use the following lines for reading the end of the line
string endOfLine;
getline(cin,endOfLine);
//purpose: Print out the information about a student.
void printStudentInfo(const StudentRec& aStudent)
{
//Print out all student information
cout << endl << "-------------------------------------------"<<endl;
cout <<"Student's Name: " << aStudent.name << endl;
cout <<"Student's Tuition : "<< aStudent.tuition << endl;
cout <<"The Student't GPA : "<< aStudent.gpa << endl;
cout <<"The Student's Major : " << aStudent.major <<endl;
}
Explanation / Answer
//PURPOSE: Demonstrate usage of records using C++ struct to storeinformation
// about astudent. Structs are used in function arguments.
#include <iostream>
#include <string>
using namespacestd;
// Complete the following StudentRec declaration that contains
// student name, tuition, gpa, and major as fields.
struct StudentRec
{
string name;
double tuition;
double gpa;
string major;
};
//function prototypes
void readStudentInfo(StudentRec& , istream& );
// provide functionprototype for printStudentInfo
void printStudentInfo(const StudentRec& );
int main ()
{
//variables
StudentRecstudentInfo; //used toread in student information
//inputand print all student records
readStudentInfo(studentInfo,cin);
// add priming read function call here
while (cin)
{printStudentInfo(studentInfo);
// provide the function call for printing the student recordread
readStudentInfo(studentInfo,cin);
// provide the function call for reading the next studentrecord
}
return 0;
}
//This function readsinformation about a student from the standard input
// Do NOT add any prompt to the user!
void readStudentInfo(StudentRec& studentInfo, istream&cin)
{
// provide the function definition of readStudentInfo thatmatchs
// with the aboveprototype: Do NOT add any prompt to theuser!
// need the function heading and { }
//Read in all information for the student
getline (cin, studentInfo.name);
getline (cin, studentInfo.major);
cin>>studentInfo.tuition;
cin >>studentInfo.gpa;
// CHECK data files for the order of fields to read in
// the last cin using >> leaves the end of line character incin
// use the following lines for reading the end of the line
string endOfLine;
getline(cin,endOfLine);
}
//purpose: Print out the information about a student.
void printStudentInfo(const StudentRec& aStudent)
{
//Print out all student information
cout << endl <<"-------------------------------------------"<<endl;
cout <<"Student's Name: " <<aStudent.name << endl;
cout <<"Student's Tuition : "<< aStudent.tuition << endl;
cout <<"The Student't GPA : "<< aStudent.gpa << endl;
cout <<"The Student's Major : "<< aStudent.major <<endl;
}