简单学生管理系统

学生管理系统

内容:

针对若干学生信息(至少包括学生学号、年龄、性别等信息),设计一个学生信息管理系统。

要求该组数据在程序运行时已经被赋过初值(在程序里写好初始值,而不是键盘输入初始值)。

功能:

用户界面设计与实现:提供相关操作步骤的指导性提示,可以参考图2的形式。


在指定位置插入1名学生信息:从键盘输入要插入学生信息以及插入位置(按存储顺序),然后实现在指定位置插入该名学生信息。

计算学生平均年龄:计算学生年龄的平均值并输出到屏幕

统计男女学生人数:统计学生男女人数并输出到屏幕

根据学生学号查找学生信息:从键盘输入学生学号,然后在这组学生信息中进行查找,如果存在,则在屏幕上输出该学生所在位置(存储顺序),如果不存在,输出“没有查找到!”。

显示所有学生信息:在屏幕显示所有学生的信息。

退出功能:结束程序的运行。

。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。

。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。

实现代码

//node.h

#ifndef NODE_H_

#define NODE_H_

#include<iostream>

#include<string>

#include<cstdlib>

using namespace std;

struct node{

   int no;

   int year;

   char sex[100];

   node*next;

   };

class student{

   private:

      node *head;

      node *tail;

      int count;

    public:

     student():head(NULL),tail(NULL),count(0){}

     void input(node a);

     float year_average();

     void  get_count(){cout<<"总共有多少人:"<< count<<endl;}

     void find_student(const int n);

     void show_student();

     };

void student::input(node a)

{

    if(head==NULL)

    {

        head=&a;

        tail=&a;

        ++count;

    }

    else

    {

        tail->next=&a;

        tail=&a;

        ++count;

    }

}

float student::year_average()

{

    node *p;

    p=head;

    float total=0;

    while(p)

    {

        total+=p->year;

        p=p->next;

    }

    return total/count;

}

void student::find_student( int n)

{

    node *p,*q;

    p=q=head;

    while(q->next)

  {

    if(q->no==n)

    {

        cout<<"we find it"<<endl;

        if(p!=head)

        cout<<"the privous of it is No."<<q->no;

        break;

    }

    else

    {

        q=p;

        p=p->next;

    }

  }

  if(p->next==NULL)

  {

      cout<<"we can not find it."<<endl;

  }

}

void student::show_student()

{

    node*p=head;

    if(p==NULL)cout<<"是空的"<<endl;

    while(p)

    {

        cout<<"the No. of the student is "<<p->no<<"  and he(she) is "<<p->sex<<" and the age is "<<p->year<<endl;

        p=p->next;

        if(p==tail)

        cout<<"the No. of the student is "<<p->no<<"  and he(she) is "<<p->sex<<" and the age is "<<p->year<<endl;

        break;

    }

}

#endif



//main.h

#include <iostream>

#include<string>

#include<cstring>

#include<cstdlib>

#include"node.h"

using namespace std;

void show_tab()

{

    cout<<"......................................"<<endl;

    cout<<"\n\n\n";

    cout<<"       欢迎进入学生管理系统        "<<endl;

    cout<<"\n\n\n";

    cout<<"....................................."<<endl;

    cout<<"请选择您的操作:"<<endl;

    cout<<"1.在指定位置插入一名学生信息:"<<endl;

    cout<<"2.计算学生的平均年龄:"<<endl;

    cout<<"3.统计学生人数总数:"<<endl;

    cout<<"4.根据学生编号查找学生:"<<endl;

    cout<<"5.显示所有学生信息:"<<endl;

    cout<<"6.退出"<<endl;

    cout<<"请选择按键(1~6)"<<endl;

}

node input_shudent()

{

    node *p=(node*)malloc(sizeof(node));

    cout<<"请输入学生学号:";

    cin>>p->no;

    cout<<"输入出生日期:";

    cin>>p->year;

    cout<<"输入性别:";

    cin>>p->sex;

    p->next=NULL;

    return *p;

}

int input_num_find()

{

    int n;

    cout<<"please input the num wo want to find "<<endl;

    cin>>n;

    return n;

}

int main()

{

    student   a;

    while(1)

    {

        show_tab();

        int choice;

        cin>>choice;

        switch(choice)

        {

            case(1):

              a.input(input_shudent());

            break;

            case(2):

            a.year_average();

            break;

            case(3):

            a.get_count();

            break;

            case(4):

            a.find_student(input_num_find());

            break;

            case(5):

            a.show_student();

            break;

            case(6):

        goto flag1;

             }

    }

 flag1:   cout << "Hello world!" << endl;

    return 0;

}


0 | 评论

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值