The recent assignment I was given in my programming class had me utilize a structure. Structures are not covered for another 10 chapters in our textbooks, however I did read up on them as much as I could to try to figure this thing out. I am still unsure on how to use them. Here is the question and then the code that I came up with to answer it. My code is riddled with errors and I really need help trying to figure out what I am doing wrong.
1. Write a program that includes the following four steps:
Step 1.Create a structure with the name StudentRecord containing a Name stored as an array of 20 characters, an ID stored as an integer, and a GPA stored as a floating-point number. Create (instantiate) a variable from StudentRecord called TESCStudent.
Step 2. Assign the following values to the variable by assuming Name is SuperProgrammer, with an ID of 1234, and a GPA of 4.0.
Step 3. The program should print out on the screen that SuperProgrammer with an Identification number of 1234 has a 4.0 GPA. (Of course, your program needs to use the structure you defined in step 1.)
Step 4. Generalize the program so that you can input the student's name, ID, and GPA when the program is run. Please do not forget to include prompt statements in your program. Print out the user entered Name, ID, and GPA.
Make sure your program includes all four steps, not just steps 1 and 4.
#include <iostream>
using std::cout;
using std::cin;
using std::endl;
#include <string>
using std::string;
struct StudentRecord
{
char name[ 20 ];
int iD;
float gPA;
};
class GradeBook
{
GradeBook( char word[], int number, float grade )
{
setStudentName( word );
setStudentID( number );
setStudentGPA( grade );
}
void setStudentName( char* word )
{
StudentRecord name = word;
}
char getStudentName()
{
return StudentRecord name;
}
void setStudentID( int number)
{
StudentRecord iD = number;
}
int getStudentID()
{
return StudentRecord iD;
}
void setStudentGPA( float grade )
{
StudentRecord gPA = grade;
}
float getStudentGPA()
{
return StudentRecord gPA;
}
void displayMessage()
{
cout << "Student: " << getStudentName() << " ID: " << getStudentID() << " GPA: " << getStudentGPA() << endl;
}
void newStudent()
{
cout << "Please enter a new student's name ( 20 character limit with no spaces ):/n" << endl;
cin >> name;
cout << "Please enter " << getStudentName() << "'s ID:/n" << endl;
cin >> iD;
cout << "Please enter " << getStudentName() << "'s GPA:/n" << endl;
displayMessage();
}
};
int main()
{
GradeBook TESCStudent( SuperProgrammer, 1234, 4.0 );
TESCSudent.displayMessage();
TESCStudent.newStudent();
system( "pause" );
return 0;
}