学生通讯录管理系统

学生通讯录管理系统

题目描述

-1)问题描述

纸质的通讯录已经不能满足大家的要求,容易丢失、查找困难等问题是纸质通讯录所不能克服的缺点。学生通讯录管理系统是为了帮助老师、同学或者其他一些需要使用通讯录的人员进行管理和分析的一种应用程序。
-2)需求分析

  • a)输入数据建立通讯录
  • b)查询通讯录中满足要求的信息
  • c)插入新的通讯录信息
  • d)删除不需要的通讯录信息
  • e)查看所有的通讯录信息

1.参考程序

代码如下(示例):

#include <cstdio>
#include <cstring>
#include <algorithm>
#include <iostream>
#include <string>
#include <vector>
#include <stack>
#include <bitset>
#include <cstdlib>
#include <cmath>
#include <set>
#include <list>
#include <deque>
#include <map>
#include <queue>
#include <fstream>
using namespace std;
typedef long long ll;
const double PI = acos(-1.0);
const double eps = 1e-6;
const int INF = 1000000000;
const int maxn = 5001;
int T, n, m;
typedef struct Communication_information
{
    int School_number;
    char name[20];
    char Phone_Number_one[3][20];
    char Phone_Number_two[3][20];
    struct Communication_information *next;
} LinkNode;
//建立系统
void Build_system(LinkNode *&L)
{
    ifstream srcFile("student.in", ios::in); //以文本模式打开in.txt备读
    if (!srcFile) { //打开失败
        cout << "error opening source file." << endl;
        return;
    }
    LinkNode *s;
    L = (LinkNode *)malloc(sizeof(LinkNode));
    L->next = NULL;
    ll num;
    srcFile>>num;
    while (num)
    {
        s = (LinkNode *)malloc(sizeof(LinkNode));
        s->School_number = num;
        srcFile >> s->name;
        srcFile >> s->Phone_Number_one[1]; 
        srcFile >> s->Phone_Number_one[2];
        srcFile >> s->Phone_Number_two[1];
        srcFile >> s->Phone_Number_two[2];
        srcFile >> num;
        s->next = L->next;
        L->next = s;  
    }
    cout<<"初始化完成!"<<endl;
}

//主界面
void Main_Interface()
{
    printf("\n******************欢迎使用本系统******************");
    printf("\n*************************************************");
    printf("\n*             1.查找学生信息                     *");
    printf("\n*             2.插入学生信息                     *");
    printf("\n*             3.删除学生信息                     *");
    printf("\n*             4.查看所有信息                     *");
    printf("\n*             5.修改学生信息                     *");
    printf("\n*             6.重置本系统                       *");
    printf("\n*             0.退出本系统                       *");
    printf("\n**************************************************");
}
void Main_Interface2()
{
    printf("\n*************************************************");
    printf("\n*             1.查找学生信息                     *");
    printf("\n*             2.插入学生信息                     *");
    printf("\n*             3.删除学生信息                     *");
    printf("\n*             4.查看所有信息                     *");
    printf("\n*             5.修改学生信息                     *");
    printf("\n*             6.重置本系统                       *");
    printf("\n*             0.退出本系统                       *");
    printf("\n**************************************************");
}
void Main_Interface3()
{
    printf("重新输入1\n");
    printf("退出系统2\n");
}

//显示页面
void Display_page(LinkNode *&L)
{
    LinkNode *p = L;
    if (L == NULL || L->next == NULL)
    {
        cout << "系统没有数据!" << endl;
        return;
    }
    cout << "编号\t\t学号\t\t姓名\t\t\t联系人一\t\t\t联系人二" << endl;
    int n = 1;
    /*输出*/
    while (p->next != NULL)
    {
        cout << n << "\t\t";
        cout << p->next->School_number << "\t\t";
        cout << p->next->name << "\t\t\t";
        cout << p->next->Phone_Number_one[1] << " " << p->next->Phone_Number_one[2] << "\t\t\t";
        cout << p->next->Phone_Number_two[1] << " " << p->next->Phone_Number_two[2] << endl;
        p = p->next;
        n++;
    }
}

//删除学生信息
void Delete_student_information(LinkNode *&L)
{
    LinkNode *p = L, *q;
    cout << "请输入要删除学生的学号和姓名(如“001 张三”):";
    int num;
    char namea[20];
    cin >> num >> namea;
    int f = 0; //判断标志
    while (p->next != NULL)
    {
        if (p->next->School_number == num && strcmp(namea, p->next->name) == 0)
        {
            q = p->next;
            p->next = q->next;
            free(q);
            f = 1;
            break;
        }
        p = p->next;
    }
    if (f == 0)
        {
            cout << "系统中无该学生信息!" << endl;
            Main_Interface3();
        int t;
        cin >> t;
        if (t == 1)
        {
            Delete_student_information(L);
        }
        else
            return;
        }
    else
        cout << "删除成功!" << endl;
}

//添加学生信息
void Add_student_information(LinkNode *&L)
{
    LinkNode *s;
    int num;
    printf("请输入学号:");
    cin >> num;
    while (num)
    {
        s = (LinkNode *)malloc(sizeof(LinkNode));
        s->School_number = num;
        printf("请输入学生姓名:");
        cin >> s->name;
        printf("请输入联系人+联系号码(如“张三 123456789”):");
        cin >> s->Phone_Number_one[1];
        cin >> s->Phone_Number_one[2];
        printf("请输入备用联系人+联系号码(如“张三 123456789”):");
        cin >> s->Phone_Number_two[1];
        if (strcmp(s->Phone_Number_one[1], "0"))
            cin >> s->Phone_Number_two[2];
        printf("请输入学号(0结束):");
        cin >> num;
        s->next = L->next;
        L->next = s;
    }
    cout << "添加成功!" << endl;
}

//查找学生信息
void Find_student_information(LinkNode *&L)
{
    LinkNode *p = L, *q;
    cout << "请输入要查人找学生的学号和姓名:";
    int num;
    char namea[20];
    cin >> num >> namea;
    int f = 0;//判断标志
    while (p->next != NULL)
    {
        if (p->next->School_number == num && strcmp(namea, p->next->name) == 0)
        {
            cout << "编号\t\t学号\t\t姓名\t\t\t联系人一\t\t\t联系人二" << endl;
            cout << 1 << "\t\t";
            cout << p->next->School_number << "\t\t";
            cout << p->next->name << "\t\t\t";
            cout << p->next->Phone_Number_one[1] << " " << p->next->Phone_Number_one[2] << "\t\t\t";
            cout << p->next->Phone_Number_two[1] << " " << p->next->Phone_Number_two[2] << endl;
            f = 1;
            break;
        }
        p = p->next;
    }
    if (f == 0)
    {
        cout << "系统中无该学生信息!" << endl;
        Main_Interface3();
        int t;
        cin >> t;
        if (t == 1)
        {
            Find_student_information(L);
        }
        else
            return;
    }
}

//修改学生信息
void Modify_student_information(LinkNode *&L)
{
    LinkNode *p = L, *q;
    cout << "请输入要查人找学生的学号和姓名:";
    int num;
    char namea[20];
    cin >> num >> namea;
    int f = 0;//判断标志
    while (p->next != NULL)
    {
        if (p->next->School_number == num && strcmp(namea, p->next->name) == 0)
        {
            cout << "查找成功!" << endl;
            cout << "请输入要修改的内容:" << endl;
            cout << "                 1.修改主联系人" << endl;
            cout << "                 2.修改备用联系人" << endl;
            cout << "                 3.修改主联系人和备用联系人" << endl;
            int t;
            cin >> t;
            if (t == 1)
            {
                printf("请输入联系人+联系号码(如“张三 123456789”):");
                cin >> p->next->Phone_Number_one[1] >> p->next->Phone_Number_one[2];
            }
            else if (t == 2)
            {
                printf("请输入备用联系人+联系号码(如“张三 123456789”):");
                cin >> p->next->Phone_Number_one[1] >> p->next->Phone_Number_one[2];
            }
            else
            {
                printf("请输入联系人+联系号码(如“张三 123456789”):");
                cin >> p->next->Phone_Number_one[1] >> p->next->Phone_Number_one[2];
                printf("请输入备用联系人+联系号码(如“张三 123456789”):");
                cin >> p->next->Phone_Number_two[1] >> p->next->Phone_Number_two[2];
            }
            cout << "修改成功!" << endl;
            f = 1;
            break;
        }
        p = p->next;
    }
    if (f == 0)
    {
        cout << "查找不到输入内容,修改失败!" << endl;
        Main_Interface3();
        int t;
        cin >> t;
        if (t == 1)
        {
            Modify_student_information(L);
        }
        else
            return;
    }
}
int main()
{
    /****建立线性表并初始化****/
    LinkNode *L;
    /**********END**********/
    printf("请初始化本系统:\n");
    Build_system(L);
    Main_Interface();
    int t;
    cout << "\n请选择功能:";
    cin >> t;
    while (t < 0 || t > 6) //判断是否输入错误
    {
        cout << "输入错误请重新输入:";
        cin >> t;
    }
    
    while (t)
    {
        /****************************选择功能******************************/
        switch (t)
        {
        case 1:
            Find_student_information(L);//查找学生信息
            break;
        case 2:
            Add_student_information(L);//添加学生信息
            break;
        case 3:
            Delete_student_information(L);//3.删除学生信息
            break;
        case 4:
            Display_page(L);//4.查看所有信息
            break;
        case 5:
            Modify_student_information(L);//5.修改学生信息
            break;
        case 6:
            Build_system(L);//6.重置本系统
            break;
        case 0:
            return 0;
            break;
        }
        /****************************END******************************/
        cout << endl;
        Main_Interface2();   //输出界面
        cout << "\n请选择功能:";
        cin >> t;
        while (t < 0 || t > 6)  //判断是否输入错误
        {
            cout << "输入错误请重新输入:";
            cin >> t;
        }
    }
  return 0;
}

  • 4
    点赞
  • 36
    收藏
    觉得还不错? 一键收藏
  • 2
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值