Write a class named
Student that has the following member variables:
• name. A string that holds the student ’s name.
• ID Number. An int variable that holds the student ’s ID number.
• major. A string that holds the name of the major of the student.
• Grade. A string that holds the student ’s grade.
The class should have the following member functions:
• get (): A member function that defined outside of the class, accepts the following values as arguments and assigns them to the appropriate member variables: student’s name, student’s ID number, major, and grade.
• put (): A member function that defined in side the class and display all the values as an output.
Write a C++ program that creates one object of Student class to hold the following data.
Name: Susan Meyers
ID Number: 47899
Major: MIS
Grade: A
#include <iostream>
#include <string>
using namespace std;
class Student {
string name;
unsigned long ID;
string major;
char grade;
public:
Student() : name("Unknown"), ID(0), major("NA"), grade('F')
{}
void get(string name, unsigned long id, string major, char grade);
void put();
};
void Student::get(string name_, unsigned long id, string major_, char grade_)
{
name = name_;
ID = id;
major = major_;
grade = grade_;
}
void Student::put()
{
cout << "Name: " << name << endl;
cout << "ID Number: " << ID << endl;
cout << "Major: " << major << endl;
cout << "Grade: " << grade << endl;
}
int main() {
Student student;
student.get("Susan Mayers", 47899, "MIS", 'A');
student.put();
return 0;
}
Comments
Leave a comment