Home / Object-Oriented C++ / Import and export information

Build a Person class that includes information: Full name, Date of birth, Hometown. Then, build the derived class "Engineer" in addition to the information of the Person class, the engineer class also has information about: Major, Year of Graduation (int) and methods:

Input method: enter engineer information.

Export method: output information to the screen.

Build the main program importing a list of engineers. Print the list of engineers on the screen and the information of the most recently graduated engineers (largest graduation year).


Person class:

class Person
{
	char name[30]; 
	char Birthday[30]; 
	char Places[30];
public:	
	void Input()
	{
		cin.ignore(); 
		cout<<"Enter name: ";
		gets(name);fflush(stdin); 
		cout<<"Date of birth: ";
		gets(Birthday);fflush(stdin); 
		cout<<"Que quan: ";
		gets(Places);fflush(stdin);
		
	}
	
	void Output()
	{
		cout<<"Name: "<

Engineer class:

class Engineer:public Person
{

	char majors[30]; 
	int graduationyear;
public:	
	void Input()
	{
		Person::Input();
		cout<<"Study field: ";
		gets(majors);fflush(stdin);
		cout<<"Professional male: ";
		cin>>graduationyear;
	}
	void Output()
	{
		Person::Output();
		cout<<"Class: "<

Main function:

int main()
{
	int i,n;
	Engineer a[100];
	cout<<"n= ";
	cin>>n; 
	for(i=0;iMax)	
		Max=a[i].getGraduationYear();
	cout<<"The most successful male profession today is: \n"; 
	for(i=0;i
#include
#include
#include
#include
using namespace std;
class Person
{
	char name[30]; 
	char Birthday[30]; 
	char Places[30];
public:	
	void Input()
	{
		cin.ignore(); 
		cout<<"Enter name: ";
		gets(name);fflush(stdin); 
		cout<<"Date of birth: ";
		gets(Birthday);fflush(stdin); 
		cout<<"Que quan: ";
		gets(Places);fflush(stdin);
		
	}
	
	void Output()
	{
		cout<<"Name: "<>graduationyear;
	}
	void Output()
	{
		Person::Output();
		cout<<"Class: "<Max)	
		Max=a[i].getGraduationYear();
	cout<<"The most successful male profession today is: \n"; 
	for(i=0;i

Result:

 2
Ky su 1:
Enter name: Nguyen Huu C
Date of birth: September 2, 2001
Que mandarin: Can Tho
Field of study: IT
Male good career: 2015
Ky su 2:
Enter name: Like Learning Again
Date of birth: December 12, 1981
Quan Quan: Long An
Field of study: IT
Southern good career: 2003
Information about the incoming king:
Name: Nguyen Huu C
Date of birth: September 2, 2001
Que Quan: Can Tho
Field of study: IT
Male good career: 2015
Name: Thich H?c L?i
Date of birth: December 12, 1981
Quan Quan: Long An
Field of study: IT
Southern good career: 2003
The most successful male profession today is:
Name: Nguyen Huu C
Date of birth: September 2, 2001
Que Quan: Can Tho
Field of study: IT
Male good career: 2015

Did you find this article helpful?

Support the author so they can write more quality articles!

Tư vấn lộ trình CNTT 🤖