C++ Programming Design a Sub Class: Build a \"Student\" Class. Make this class i
ID: 3694194 • Letter: C
Question
C++ ProgrammingDesign a Sub Class:
Build a "Student" Class. Make this class inherit from the Person class. Your class should have all of the following properties: stuld, firstName, lastName, email, major and gpa. Include set and get methods for properties that were not inherited. Include 2 Constmctors(see example). Also add a display function for the Student class. Use main to test out this class.
Main Code: Student *sl = new Student(419, "Bill", "Clinton", "bc@gmail.com", "CS" 2.2); sl->display(); C++ Programming
Design a Sub Class:
Build a "Student" Class. Make this class inherit from the Person class. Your class should have all of the following properties: stuld, firstName, lastName, email, major and gpa. Include set and get methods for properties that were not inherited. Include 2 Constmctors(see example). Also add a display function for the Student class. Use main to test out this class.
Main Code: Student *sl = new Student(419, "Bill", "Clinton", "bc@gmail.com", "CS" 2.2); sl->display(); C++ Programming
Design a Sub Class:
Build a "Student" Class. Make this class inherit from the Person class. Your class should have all of the following properties: stuld, firstName, lastName, email, major and gpa. Include set and get methods for properties that were not inherited. Include 2 Constmctors(see example). Also add a display function for the Student class. Use main to test out this class.
Main Code: Student *sl = new Student(419, "Bill", "Clinton", "bc@gmail.com", "CS" 2.2); sl->display();
Explanation / Answer
#include<iostream>
#include<string>
using namespace std;
class Person
{
public:
int stdId;
string firstName, lastName, email, major;
double gpa;
};
class Student : public Person
{
public:
Student()
{
stdId=0;
strcpy(firstName,"");
strcpy(lastName,"");
strcpy(email,"");
strcpy(major,"");
gpa=0;
}
Student(int sid, string fn, string ln, string em, string m, double g)
{
stdId=sid;
strcpy(firstName,fn);
strcpy(lastName,ln);
strcpy(email,em);
strcpy(major,m);
gpa=g;
}
void setid(int s)
{
stdId=s;
}
void setfn(string fn)
{
strcpy(firstName,fn);
}
void setln(string ln)
{
strcpy(lasttName,ln);
}
void setem(string em)
{
strcpy(email,em);
}
void setmj(string m)
{
strcpy(major,m);
}
void setgpa(double g)
{
gpa=g;
}
int getid()
{
return stdId;
}
string getfn()
{
return firstName;
}
string getln()
{
return lasttName;
}
string getem()
{
return email;
}
striing getmj()
{
return major;
}
double getgpa()
{
return gpa;
}
void display()
{
cout<<"Student Id="<<stdId<<endl;
cout<<"First Name="<<firstName<<endl;
cout<<"Last Name="<<lastName<<endl;
cout<<"Email="<<email<<endl;
cout<<"Major="<<major<<endl;
cout<<"GPA="<<gpa<<endl;
}
};
void main()
{
Student *s1 = new Student(419,"Bill","Clinton","bc@gamil.com","CS",2.2);
s1->display();
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.