📄 pms.cpp
字号:
// PMS.cpp : Defines the entry point for the console application.
//
#include "People.h"
#include "stdafx.h"
#include "student.h"
#include "birthday.h"
#include "teacher.h"
#include <iostream>
#include <string>
using std::string;
using std::cin;
using std::cout;
using std::endl;
void Sort(People peoples[]);
int Search(int number,People peoples[]);
int main(int argc, char* argv[])
{
// 人员录入和显示
string setname;
int setnumber,setsex,setid,setyear,setmonth,setday;
Birthday birth;
People p;
cout<<"请输入人员姓名、编号,性别,身份证号,出生日期:\n";
cin>>setname>>setnumber>>setsex>>setid>>setyear>>setmonth>>setday;
cout<<endl;
birth.setBirth(setyear,setmonth,setday);
birth.displayBirth(setyear,setmonth,setday);
p.setPeople(setname,setid,setnumber,setsex,birth);
// p.setPeople(setname,setid,setnumber,setsex,setyear,setmonth,setday);
p.displayPeople(setname,setid,setnumber,setsex,setyear,setmonth,setday);
Birthday birthday(2013,10,3);
Teacher* te1= new Teacher("zhangsan1",1,1,31,birthday);
Teacher* te2= new Teacher("zhangsan2",2,0,31,birthday);
Teacher te3("zhangsan3",003,0,33,birthday);
cout<<te1->name <<endl;
cout<<te2->name <<endl;
cout<<te3.name <<endl;
Teacher te4(te3);//拷贝构造函数
cout<<te4.name <<endl;
te1 = te2;//操作符重载
cout<<te1->name <<endl;
cout<<te2->name <<endl;
Teacher* te5= new Teacher("zhangsan5",5,0,45,birthday);
People peoples[5] = {*te1,*te2,te3,te4,*te5};
int i = Search(5,peoples);//查询
cout<<i <<endl;
cout<<peoples[i].name <<endl;
cout<<peoples[4].number <<endl;
return 0;
}
//通过number 查找people
int Search(int number,People peoples[5])
{
for(int i = 0;i<5;i++){
if(peoples[i].number == number){
return i;
}
}
return -1;
}
//对People类对象数组按编号排序的函数
void Sort(People peoples[5])
{
People p;
// 简单排序
for(int i = 0;i<5;i++){
if(peoples[i].number >peoples[i+1].number )
{
// 排序算法、注意:因为People重载了“=”运算符,所以可以直接用
p=peoples[i];
peoples[i]=peoples[i+1];
peoples[i+1]=p;
}
}
// 打印结果
for(i=0;i<5;i++)
{
cout<<peoples[i].number<<endl;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -