//example4_06_student.h:定义学生类
#ifndef _STUDENT
#define _STUDENT
#include<iostream>
#include<string>
using namespace std;
#define SIZE 80
class Student
{char *name;char ID[19];char number[10];char speciality[20];int age;static int count;     //实际有意义的学生个数,小于等于对象的个数
public:Student();Student( char *na , char *id , char *num , char * spec ,int ag);Student(const Student &per);~Student();char* GetName()const;  //可以定义为常成员函数char* GetID();   //不可以定义为常成员函数char* GetNumber();  //不可以定义为常成员函数char* GetSpec();  //不可以定义为常成员函数int GetAge()const;     void Display()const;   void Input();void Insert();void Delete();static int GetCount( );  //新增加的静态成员函数
};
#endif
//example4_06_student.cpp:实现学生类
#include "example4_06_student.h"
int Student::count=0;      //静态数据成员的初始化
Student::Student()
{name=NULL;age=0;
}Student::Student( char *na , char *id , char *num , char * spec ,int ag)
{   if(na){ name=new char[strlen(na)+1];strcpy(name,na);}strcpy(ID, id);strcpy(number,num);strcpy(speciality, spec);age=ag;count++;
}Student::Student(const Student &per)
{if(per.name){name=new char[strlen(per.name)+1];strcpy(name,per.name);}strcpy(ID, per.ID);strcpy(number,per.number);strcpy(speciality, per.speciality);age=per.age;count++;
}Student::~Student()
{cout<<"disCon"<<endl;if (name)delete []name;count--;
}char* Student:: GetName()const
{return name;
}
char* Student::GetID()
{  return ID;
}
int Student::GetAge()const
{  return age;
}
char* Student::GetSpec()
{return speciality;
}
char* Student::GetNumber()
{return number;
}
void Student::Display()const
{cout<<"姓  名:"<<name<<endl;cout<<"身份证:"<<ID<<endl;cout<<"学  号:"<<number<<endl;cout<<"专  业:"<<speciality<<endl;  cout<<"年  龄:"<<age<<endl<<endl;
}
void Student::Input()
{char na[10];cout<<"输入姓  名:";cin>>na ;if(name)delete []name;name=new char[ strlen(na)+1];strcpy( name, na );cout<<"输入身份证:";cin>>ID ;cout<<"输入年  龄:";cin>>age; cout<<"输入专  业:";cin>>speciality ;cout<<"输入学  号:";cin>>number;    count++;         //此句增加,每输入一个,学生总数加1
}void Student::Insert()   //新增
{if (!age)           //当对象的age成员值为0时,就可以在此对象处重新输入以覆盖Input();
}void Student::Delete()   //新增
{age=0;               //只简单地将age置0而不移动数组元素count--;
}int  Student::GetCount( ) //新增静态成员函数,专门用来访问静态数据成员
{return count;
}
//example4_06.cpp: 第三个文件,定义学生类的对象以及一些函数,完成程序功能
#include<iostream>
#include "example4_06_student.h"
using namespace std;
const int N=10;void menu();
void OutputStu(const Student *array );      //指针形式参数前加const保护
void InputStu(Student *array);
int SearchStu(const Student *array, char *na); //指针形式参数前加const保护
bool InsertStu(Student *array);
bool DeleteStu(Student *array, char *na);int main()
{Student array[N];int choice;char na[20];do{menu();cout<<"Please input your choice:";cin>>choice;if( choice>=0 && choice <= 5 )switch(choice){case 1:InputStu(array);break;case 2:cout<<"Input the name searched:"<<endl;                 cin>>na;int i;i=SearchStu(array, na);if (i==N)cout<<"查无此人!\n";elsearray[i].Display();break;case 3:OutputStu(array); break;case 4: if (InsertStu(array))cout<<"成功插入一条记录\n"; elsecout<<"插入失败!\n";break;case 5:cout<<"Input the name deleted:"<<endl;cin>>na;if ( DeleteStu(array,na) )cout<<"成功删除一条记录\n";elsecout<<"删除失败!\n";break;default:break;}}while(choice);return 0;
}void menu()
{cout<<"**********1.录入信息**********"<<endl;cout<<"**********2.查询信息**********"<<endl;cout<<"**********3.浏览信息**********"<<endl;cout<<"**********4.插入信息**********"<<endl;   //新增菜单cout<<"**********5.删除信息**********"<<endl;   //新增菜单cout<<"**********0.退    出**********"<<endl;
}void OutputStu(const Student *array )
{cout<<"学生总人数="<<Student::GetCount()<<endl;  //此句有修改for(int i=0 ; i<N ; i++)                //此句有修改,循环控制条件及输出条件if (array[i].GetAge()) array[i].Display();
}int SearchStu(const Student *array, char *na)
{int i,j=N;for(i=0 ; i<N ; i++)          //此句有修改,循环控制条件if (array[i].GetAge())     //保证是有效记录if( strcmp( array[i].GetName() , na) == 0 ){j=i;break;}return j;
}void InputStu(Student *array )   //此函数与第三章中有较大修改,请注意
{char ch;int i=0; do{   if (Student::GetCount()==N)             cout<<"人数已满,无法继续录入!"<<endl;if (!array[i].GetAge())array[i++].Input();cout<<"继续输入吗?(Y or N )"<<endl;cin>>ch;}while(ch=='Y');
}bool InsertStu(Student *array)
{if (Student::GetCount()==N)    //判断是否有位置插入记录{cout<<"人数已满,无法插入记录!"<<endl;return false;}for (int i=0; array[i].GetAge() ; i++);   //找第一个年龄为0的空位置array[i].Insert();return true;
}bool DeleteStu(Student *array, char *na)
{if (Student::GetCount()==0) {cout<<"没有记录,无法删除!"<<endl;return false;}int  i=SearchStu(array, na);  //调用查找函数,判断此人是否存在if (i==N){cout<<"查无此人,无法删除!\n";return false;}array[i].Delete();            //如果存在,直接删除return true;
}

C++学生信息管理系统2.0相关推荐

  1. 赶紧进来看看--用C语言实现学生信息管理系统(1.0静态版)

    本文介绍了用C语言实现学生信息管理系统设计,主要包括对学生信息增删查改.分类统计.排序等功能,文章最后有全部源码展示- C语言实现学生信息管理系统--1.0静态版 一.学生信息管理系统介绍 二.实现学 ...

  2. Python实现学生信息管理系统V3.0(GUI界面)

    关于"学生信息管理系统"的基本思路和详细过程,请看V1.0版本: Python实现学生信息管理系统V1.0_︶ㄣ释然的博客-CSDN博客本文是关于学生信息管理系统的简易版以及具体内 ...

  3. python学生信息管理系统1.0

    目录 具体需求:实现一个学生信息管理系统 一.数据结构的设计: 二.菜单界面及按钮的设置: 三.各个模块的具体实现 1.定义一个字典,用于存放学生信息 2.查询学生信息模块: 3.添加学生信息模块: ...

  4. 赶紧进来看看---C语言实现学生信息管理系统(3.0文件存储版)

    本文主要介绍了将学生信息管理系统改造为文件存储版本- 主要涉及文件操作函数–将学生信息导入文件和从文件读取学生信息到程序中,从而达到数据持久化的效果 文章最后有源码展示 学生信息管理系统1.0静态版- ...

  5. C# 学生信息管理系统 2.0

    资源下载请点击 经历几天的探索,对原有的系统做了重大的修改. 修改如下: 1.登录界面进行了修改,增加了管理员选项. 2.学生界面增加了课表查询,成绩查询和选课系统,学生信息功能,界面做了优化,可以显 ...

  6. 学生信息管理系统V1.0

    需求: 将学生信息存储起来并能进行相关的增删改查 思路: 将学生信息存放在字典中,然后在将所有学生信息存放到列表中,通过对列表进行操作来达到对学生信息的增删改查等操作 说明: 此版本只是一个简单的列表 ...

  7. 学生信息管理系统V2.0

    需求 将学生信息存储起来(数据能多次使用)并能进行相关的增删改查 思路 将学生信息存放在字典中,然后在将所有学生信息存放到文件中,通过对文件进行操作来达到对学生信息的增删改查等操作 说明 这个版本只是 ...

  8. 【数据结构实习】学生信息管理系统2.0

    Student.h 1 #include<iostream> 2 #include<string> 3 #include<fstream> 4 using name ...

  9. python学生管理系统-Python 学生信息管理系统 2.0

    本次改进的方面有: 1.通过函数把不同的功能封装成为了一个个模块,使主程序看起来清晰简明. 2.把信息都通过文件操作写入了json文件中,在退出系统后重新登录时数据都还存在. 整个工程分为了四个.py ...

  10. Python实现简易版学生信息管理系统,包含源码及相关实现说明~

    前言 最近学了一点python语法,所以写一个小程序练习一下.当然程序中有许多不完美的地方,仅供各位小伙伴参考呀,并且欢迎大家留言指出不合理的地方奥~ 学生信息管理系统 1.系统介绍 该系统主要考察 ...

最新文章

  1. flash流媒体资料
  2. 华东信标组预赛前三名
  3. Linux-鸟菜-7-Linux文件系统-EXT
  4. gbdt 算法比随机森林容易_用Python实现随机森林算法
  5. no acceptable C compiler found in $PATH
  6. lync 2013 企业版部署 (四)安装office web app server
  7. 近期资料分享汇总,还不快来看看你漏了哪份没拿?
  8. java 双因素认证(2FA)TOTP demo
  9. 非web项目并且项目文件多java项目 使用tomcat发布的方式
  10. 关于token你需要知道的
  11. 菜鸟学Linux 第093篇笔记 keepalived
  12. electron-vue使用electron-updater实现自动更新
  13. rocketmq整合mysql事务_分布式事务(4)---RocketMQ实现分布式事务项目
  14. 朱恒志20135314实验2 实验报告
  15. (实用工具分享)网页尺寸测量工具Page Ruler
  16. iOS 10 消息推送
  17. Pr入门系列之六:使用标记
  18. 多媒体计算机用什么音箱好,小巧又不失音质 桌面2.0电脑音箱推荐榜
  19. 青岛小学 初中有计算机编程比赛,2017年青岛中小学信息技术竞赛活动.doc
  20. 思维导图组件@hellowuxin/mindmap的基本使用

热门文章

  1. 语音网关典型配置实例
  2. 09月28日 pytorch与resnet(四)三种主要的转移学习方案,微调ConvNet,ConvNet 作为固定特征提取器
  3. 4月26 simulink数据input,与全局变量建立堆栈
  4. for update引发了血案
  5. 第二季-专题20-移植bootm命令启动内核
  6. 三张图较为好理解JavaScript的原型对象与原型链
  7. Xcode的gdb调试
  8. 第一个python小工具
  9. UVA 679 小球掉落 思维 + 数据结构
  10. 把Chrome浏览器变成文本编辑器