Question #44647

Create a test program that defines and uses both the default and non-default constructor of a class. Create a class of students in a college. Make sure you include name, phone number, student number, current course, current GPA, and current grade.
1

Expert's answer

2014-08-11T10:46:42-0400

Answer on Question #44647, Programming, C++

Problem.

Create a test program that defines and uses both the default and non-default constructor of a class. Create a class of students in a college. Make sure you include name, phone number, student number, current course, current GPA, and current grade.

Solution.

Code

#include <iostream>
#include <string>
using namespace std;
class Student {
    string name; // student name
    string phone; // phone number
    int number; // student number
    string course; // current course
    string gpa; // current gpa
    string grade; // current grade
public:
    Student(); // default constructor
    Student(string name, int number); // custom constructor
};
int main() {
    Student boy;
    Student girl("Emily", 12);
    Student classOfStudents[2] = {boy, girl}; // class of students
    return 0;
}
// Default constructor
Student::Student() {
    cout << "Enter student name: ";
    cin >> name;
    cout << "Enter student number: ";
    cin >> number;
}
// Custom constructor
Student::Student(string name, int number) {
    Student::name = name;
    Student::number = number;
}


Result

Enter student name: Jack

Enter student number: 123

http://www.AssignmentExpert.com/

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!
LATEST TUTORIALS
APPROVED BY CLIENTS