NEED IT ASAP ONLY C++ CODE 1 – Create a class called person including first name
ID: 3823334 • Letter: N
Question
NEED IT ASAP
ONLY C++ CODE
1 – Create a class called person including first name and last name as string and idnum as an integer. The class should contain a default constructor setting all strings to “ ” and integers to 0 and a constructor that accepts parameters. Create a print method to print the person.
2-Create a new class derived from person called intern which extends person with one variable called grade (char). The class should contain a default constructor and a constructor with parameters. Override the print function to print intern.
Explanation / Answer
#include <iostream>
#include<string>
using namespace std;
class person
{
string first_name;
string last_name;
int idnum;
public:
person()
{
first_name="";
last_name="";
idnum=0;
}
person(string fname,string lname,int id)
{
first_name=fname;
last_name=lname;
idnum=id;
}
void print()
{
cout<<" First Name of the person is:"<<first_name;
cout<<" Last Name of the person is:"<<last_name;
cout<<" ID Number of the person is:"<<idnum;
}
};
class intern:public person
{
char grade;
public:
intern()
{
grade=' ';
}
intern(char g,string fname,string lname,int id):person(fname,lname,id)
{
grade=g;
}
void print()
{
person::print();
cout<<" Grade of the intern is:"<<grade;
}
};
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.