C++学生信息管理系统3.0

//example5_14_people.h
#ifndef _PERSON
#define _PERSON

#include<iostream>
#include<string>
using namespace std;

class Date
{
protected:
	int year;
	int month;
	int day;
public:
	void Set( int y, int m, int d );
	int GetYear( );
	int GetMonth( );
	int GetDay( );
};

class Person
{
protected:
	char name[20];
	char number[10];
	char sex;
	Date birthday;
public:
	Person( );
	void Input( );
	void Output( );
	char* GetName( );
};

class Student: virtual public Person
{
protected:
	char speciality[20];
public:
	void Input( );
	void Output( );
};

class Graduate: virtual public Student
{
protected:
	char  researchTopic[50];	//研究课题
public:
	void Input( );
	void Output( );
};

class Teacher: virtual public Person
{
protected:
	char academicTitle [20];	//教师职称
public:
	void Input( );
	void Output( );
};

class PostgraduateOnJob: public Graduate, public Teacher
{
public:
	void Input( );
	void Output( );
};

#endif


//example5_14_people.cpp
#include "example5_14_people.h"

//Date类的函数实现
void Date::Set( int y, int m, int d )
{
	year = y;
	month = m;
	day = d;
}

int Date::GetYear( )
{
	return year;
}

int Date::GetMonth( )
{
	return month;
}

int Date::GetDay( )
{
	return day;
}


//Person类的函数实现
Person::Person( )
{
	strcpy( name, "00" );
}

char * Person::GetName( )
{
	return name;
}

void Person::Input( )
{
	cout << "请输入信息\n";
	cout << "姓  名:";
	cin >> name ;
	cout << "编  号:";
	cin >> number;
	int y, m ,d;
	cout << "出生日期(年份 月份 日期):";
	cin >> y >> m >> d;
	birthday.Set( y, m, d);
	cout << "性别(m/f):";
	cin >> sex;
}

void Person::Output( )
{
	cout << "姓  名:" << name << endl;
	cout << "编  号:" << number << endl;
	cout << "性  别:";
	if ( sex == 'm' )
		cout << "女" << endl;
	else
		cout << "男" << endl;
	cout << "出生日期:" << birthday.GetYear( ) << '-' << birthday.GetMonth( ) << '-' <<birthday.GetDay( ) << endl;
}


//Student类的函数实现
void Student::Input( )
{
	Person::Input( );
	cout << "专  业:";
	cin >> speciality;
}

void Student::Output( )
{
	Person::Output( );
	cout << "专  业:" << speciality << endl;
}

//Graduate类的函数实现
void Graduate::Input( )
{
	Student::Input( );
	cout << "研究课题:";
	cin >> researchTopic;
}

void Graduate::Output( )
{
	Student::Output( );
	cout << "研究课题:" << researchTopic << endl;
}


//Teacher类的函数实现
void Teacher::Input( )
{
	Person::Input( );
	cout << "职  称:";
	cin >> academicTitle;
}

void Teacher::Output( )
{
	Person::Output( );
	cout << "职  称:" << academicTitle << endl;
}

//PostgraduateOnJob类的函数实现
void PostgraduateOnJob::Input( )
{
	Graduate::Input( );
	cout << "职  称:";
	cin >> academicTitle;
}

void PostgraduateOnJob::Output( )
{
	Graduate::Output( );
	cout << "职  称:" << academicTitle << endl;
}

//example5_14_interface.h
#ifndef _INTERFACE
#define _INTERFACE
#include "example5_14_people.h"

const int N = 3;

class Interface
{
protected:
	Student st[N];
	int numOfSt;
	Graduate gr[N];
	int numOfGr;
	PostgraduateOnJob po[N];
	int numOfPo;
	Teacher te[N];
	int numOfTe;
public:
	Interface( );
	void display( );
	void run( );
	void Input( );
	void Output( );      
};

#endif


//example5_14_interface.cpp
#include "example5_14_interface.h"
#include <cstring>
#include <iostream>

using namespace std;

Interface::Interface( )
{
	numOfSt = 0;
	numOfGr = 0;
	numOfPo = 0;
	numOfTe = 0;
}

void Interface::display( )
{
	cout << "**********0.退    出**********" << endl;
	cout << "**********1.录入信息**********" << endl;
	cout << "**********2.浏览信息**********" << endl;
}

void Interface::run( )
{
	int choice;

	do
	{
		display( );
		cout << "Please input your choice:";
		cin >> choice;
		switch ( choice )
		{
		case 0 :
			break;
		case 1 :
			Input( );
			break;
		case 2 :
			Output( );
			break;
		}

	} while (choice);
}

void Interface::Input( )
{
	int type;
	int i;
	char ch;

	do
	{
		cout << "你要输入的人员类型(1-学生 2-研究生 3-在职研究生 4-教师 ):";
		cin >> type;

		if ( type == 1 )
		{
			if ( numOfSt == N )
			{
				cout << "人数已满,无法继续录入!" << endl;
			}
			else
			{
				for ( i=0 ; strcmp( st[i].GetName( ), "00" ) != 0; i++ );
				st[i].Input( );
				numOfSt++;
			}
		}
		else if ( type == 2 )
		{
			if ( numOfGr == N )
			{
				cout << "人数已满,无法继续录入!" << endl;
			}
			else
			{
				for ( i=0 ; strcmp( gr[i].GetName( ), "00" ) != 0; i++ );
				gr[i].Input( );
				numOfGr++;
			}
		}
		else if ( type == 3 )
		{
			if ( numOfPo == N )
			{
				cout << "人数已满,无法继续录入!" << endl;
			}
			else
			{
				for ( i=0 ; strcmp( po[i].GetName( ), "00" ) != 0; i++ );
				po[i].Input( );
				numOfPo++;
			}
		}
		else if ( type == 4 )
		{
			if ( numOfTe == N )
			{
				cout << "人数已满,无法继续录入!" << endl;
			}
			else
			{
				for ( i=0 ; strcmp( te[i].GetName( ), "00" ) != 0; i++ );
				te[i].Input( );
				numOfTe++;
			}
		}
		else
		{
			cout << "选择有误" << endl;
		}

		cout << "继续输入?(y/n)" << endl;
		cin >> ch;

	} while( ch == 'y' );
}

void Interface::Output( )
{
	int type;
	int i;
	cout << "你要查看的人员类型(1-学生 2-研究生 3-在职研究生 4-教师 ):";
	cin >> type;

	if ( type == 1 )
	{
		if ( numOfSt == 0 )
		{
			cout << "没有学生数据!" << endl;
		}
		else
		{
			for ( i=0 ; i<N ; i++ )
			if ( strcmp( st[i].GetName( ), "00" ) != 0 )
				st[i].Output( );
		}
	}
	else if ( type == 2 )
	{
		if ( numOfGr == 0 )
		{
			cout << "没有研究生数据!" << endl;
		}
		else
		{
			for ( i=0 ; i<N ; i++ )
			if ( strcmp( gr[i].GetName( ), "00" ) != 0 )
				gr[i].Output( );
		}
	}
	else if ( type == 3 )
	{
		if ( numOfPo == 0 )
		{
			cout << "没有在职研究生数据!" << endl;
		}
		else
		{
			for ( i=0 ; i<N ; i++ )
			if ( strcmp( po[i].GetName( ), "00" ) != 0 )
				po[i].Output( );
		}
	}
	else if ( type == 4 )
	{
		if ( numOfTe == 0 )
		{
			cout << "没有教师数据!" << endl;
		}
		else
		{
			for ( i=0 ; i<N ; i++ )
			if ( strcmp( te[i].GetName( ), "00" ) != 0 )
				te[i].Output( );
		}
	}
	else
	{
		cout << "选择有误" << endl;
	}
}

//example5_14_main.cpp
#include <iostream>
#include "example5_14_interface.h"
using namespace std;

int main( )
{
	Interface in;
	in.run( );
	return 0;
}


  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值