现在的位置: 首页 > 综合 > 正文

学生管理系统(c/cpp)

2013年10月23日 ⁄ 综合 ⁄ 共 2661字 ⁄ 字号 评论关闭

#include
using namespace std;

typedef struct lnode
{
    long sno;
    char name[20];
    struct lnode *next;
}LNode, *LinkList;

LinkList InitList()
{
    LinkList head;
    head = new LNode;
    head->next = NULL;
    cout<<"Initialization completed!"<    return head;
}

LinkList CreateList()
{
    int i, n;
    cout<<"Input data number:";
    cin>>n;

    LinkList q, p, head;
    head = new LNode;
    head->next = NULL;
    q = head;

    for (i = 0; i < n; i++)
    {
        p = new LNode;
        cout<<"Input Information:"<        cin>>p->sno;
        cout<<"name:";
        cin>>p->name;

        p->next = NULL;
        q->next = p;
        q = p;
    }
      return (head);
}
void ListInsert(LinkList &L)
{
    int i, j;
    LinkList p, s;
    p = L;
    j = 0;

    cout<<"Input Location:"<    cin>>i;

    while (p->next != NULL && j    {
        p = p->next;
        j++;
    }

    if (j != i-1)
    {
        cout<<"You made a wrong location!"<        return;
    }

    s = new LNode;

    cout<<"Input Information:"<        <<"Sno:";
    cin>>s->sno;
    cout<<"name:";
    cin>>s->name;

    s->next = p->next;
    p->next = s;
}

void GetElem(LinkList L)
{
    LinkList p;
    int i, j;
    p = L;
    j = 0;

    cout<<"Input data Location:";
    cin>>i;

    while (p->next != NULL && j < i)
    {
        p = p->next;
        j++;
    }

    if (p != NULL && j==i)
    {
        cout<<"You got information:"<            <sno<            <name<    }

    else

        cout<<"ERROR!"<}

void ListDelete(LinkList &L)
{
    int i, j;
    LinkList p, s;
    p = L;
    j = 0;
    cout<<"Input Location:";
    cin>>i;

    while (p->next != NULL && j    {
        p = p->next;
        j++;
    }

    if (j != i-1)
    {
        cout<<"You made a wrong location!"<        return;
    }

    s = p->next;
    p->next = s->next;
    delete s;
}

void main()
{
    LinkList L;
    char ch;
    cout<<"--------------------------------------------------"<        <<"-                                                -"<        <<"-         Students Management System             -"<        <<"-      ...................................       -"<        <<"-                                                -"<        <<"-             1.Init Linklist                    -"<        <<"-             2.Create a Linklist                -"<         <<"-             3.Insert information               -"<         <<"-             4.Find data                        -"<        <<"-             5.Delete data                      -"<        <<"-             6.Exit                             -"<        <<"-                                                -"<        <<"--------------------------------------------------"<

while(1)
{
    cin>>ch;
    switch (ch)
    {
         case '1' : L = InitList() ; break;
         case '2' : L = CreateList() ; break;
         case '3' : ListInsert(L) ; break;
         case '4' : GetElem(L) ; break;
         case '5' : ListDelete(L) ; break;
         case '6' : exit(1) ; break;
         default : cout<<"You get a wrong operation!"; exit(1); break;
    }
}
    system("pause");
}

【上篇】
【下篇】

抱歉!评论已关闭.