| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 1537 人关注过本帖
标题:vc++通讯录
只看楼主 加入收藏
akun51286
Rank: 1
等 级:新手上路
帖 子:2
专家分:0
注 册:2005-12-8
收藏
 问题点数:0 回复次数:2 
vc++通讯录
要求:
能实现通讯录管理的基本功能,包括记录输入、
记录显示、记录查找、记录删除、记录插入及文件读写等;
提交程序设计流程图和设计说明书
用vc编写
搜索更多相关主题的帖子: 通讯录 流程图 程序设计 记录 说明书 
2005-12-08 23:36
beary
Rank: 1
等 级:新手上路
帖 子:12
专家分:0
注 册:2005-12-9
收藏
得分:0 

楼主啥意思啊?给我们出题呢么?

2005-12-09 08:15
Morueda
Rank: 1
等 级:新手上路
帖 子:2
专家分:0
注 册:2013-10-23
收藏
得分:0 
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define OK 1      // OK代表操作成功
#define ERROR 0   // ERROR代表操作失败
///////////////////////////////////////
//    定义结构体TepletePhone用来存放数据
typedef struct TepletePhone
{
    char id[12];
    char sex[10];
    char name[20];
    char adress[20];
    char PhoneNum[12];
    char Email[20];
    struct TepletePhone *next;
}LinkNode,*HeadNode;
//////////////////////////////////
//    将建立好的链表输入到文件中
void write(HeadNode head);
//////////////////////////////////
//    5统计总人数
size_t Cound(void);
//////////////////////////////////
//    2按学号进行删除操作
int Delete(HeadNode head,int num);
//////////////////////////////////
//    4用学号进行查询
int Found(const char *id);
//////////////////////////////////
//    初始化管理界面
void InitGraph(void);
//////////////////////////////////
//    进行选择处理
void Choose(void);
//////////////////////////////////
//    初始化通讯录
void InitNum(HeadNode *head);
/////////////////////////////////
//  1插入操作
int InsertNum(HeadNode head,int num,LinkNode node);
/////////////////////////////////
// 3 查看通讯录
void ShowNum(void);
/////////////////////////////////////
//    主函数
int main(void)
{
    InitGraph();
    Choose();
    return 0;
}
//////////////////////////////////////
//    初始化链表(建立学生信息)
void InitNum(HeadNode *head)
{
    *head = (HeadNode)malloc(sizeof(LinkNode));
    if (*head == NULL)
    {
        printf("内存分配失败\n");
        exit(EXIT_FAILURE);
    }
    else
        (*head)->next = NULL;
}
/////////////////////////////////////
//    功能1.按位置插入
int InsertNum(HeadNode head,int num,LinkNode node)
{
    int i = 0;
    LinkNode *ptail,*pnew;
    ptail = head;
    if (num <= 0)
        return ERROR;
    while (i < num-1 && ptail != NULL)
    {
        ptail = ptail->next;
        i++;
    }
    if (ptail == NULL)
        return ERROR;
    else
    {
        pnew = (LinkNode *)malloc(sizeof(LinkNode));
        if (pnew == NULL)
        {
            printf("分配内存失败\n");
            exit(EXIT_FAILURE);
        }
        *pnew = node;
        pnew->next = ptail->next;
        ptail->next = pnew;
        return OK;
    }
}
///////////////////////////////////////
//    功能3.显示
void ShowNum(void)
{
    char show[100];
    FILE *fp;
    if ((fp = fopen("D:\\B1231.txt","r")) == NULL)
        printf("文件打开失败\n");
    while (fgets(show,99,fp) != NULL)
        printf("%s",show);
    printf("\n");
    fclose(fp);
}
/////////////////////////////////////
//    初始化界面
void InitGraph(void)
{
    printf("*******同学通讯管理********\n");
    printf("*1. 插入.\n");
    printf("*2. 删除.\n");
    printf("*3. 显示.\n");
    printf("*4. 查询.\n");
    printf("*5. 统计.\n");      
    printf("*6. 修改.\n");
    printf("*7. 退出.\n");
    printf("***************************\n");
}
//////////////////////////////////////
//    用于选择,提供功能
void Choose(void)
{
    int number,insert;
    char num[20],num1[100];
    LinkNode node;
    while (1)
    {
        printf("请输入你需要进行的操作,以回车结束输入:");
        scanf("%d",&number);
        switch(number)
        {
        case 1:{
                    HeadNode head;
                    InitNum(&head);
                    FILE *fp;
                    if ((fp = fopen("D:\\B1231.txt","r")) == NULL)
                        printf("文件打开失败\n");
                    fgets(num1,99,fp);
                    for (number = 0; number < Cound(); number++)
                    {
                        fscanf(fp,"%s%s%s%s%s%s",node.id,
                        node.name,node.sex,node.adress,
                        node.PhoneNum,node.Email);
                        if (InsertNum(head,number+1,node) == ERROR)
                            exit(EXIT_FAILURE);
                    }
                    printf("请输入需要新建学生的信息\n");
                    printf("*请输入学号:");
                    scanf("%s",node.id);
                    printf("*请输入姓名:");
                    scanf("%s",node.name);
                    printf("*请输入性别:");
                    scanf("%s",node.sex);
                    printf("*请输入家庭住址:");
                    scanf("%s",node.adress);
                    printf("*请输入电话号码:");
                    scanf("%s",node.PhoneNum);
                    printf("*请输入E-mail:");
                    scanf("%s",node.Email);
                    printf("*请输入需要插入的位置:");
                    scanf("%d",&insert);
                    if (InsertNum(head,insert,node) == ERROR)
                    {
                        printf("插入操作失败\n");
                        exit(EXIT_FAILURE);
                    }
                    write(head);
               }break;
        case 2:{
                    FILE *fp;
                    HeadNode head;
                    InitNum(&head);
                    if ((fp = fopen("D:\\B1231.txt","r")) == NULL)
                        printf("文件打不开\n");
                    fgets(num1,99,fp);
                    for (number = 0; number < Cound(); number++)
                    {
                        fscanf(fp,"%s%s%s%s%s%s",node.id,
                        node.name,node.sex,node.adress,
                        node.PhoneNum,node.Email);
                        if (InsertNum(head,number+1,node) == ERROR)
                            exit(EXIT_FAILURE);
                    }
                        printf("请输入需要删除第几位学生的信息:");
                        scanf("%d",&insert);
                        if (Delete(head,insert) == ERROR)
                        {
                            printf("删除操作失败\n");
                            exit(EXIT_FAILURE);
                        }
                        write(head);   
               }break;
        case 3: ShowNum(); break;
        case 4:    {
                    printf("请输入需要查询的学号:");
                    scanf("%s",num);
                    if (Found(num) == ERROR)
                        printf("查询失败\n");
                }break;
        case 5:    printf("通讯录中有%u个学生的信息\n",Cound()); break;
        case 6:{
                    HeadNode head;
                    InitNum(&head);
                    FILE *fp;
                    if ((fp = fopen("D:\\B1231.txt","r")) == NULL)
                        printf("文件打开失败\n");
                    fgets(num1,99,fp);
                    for (number = 0; number < Cound(); number++)
                    {
                        fscanf(fp,"%s%s%s%s%s%s",node.id,
                        node.name,node.sex,node.adress,
                        node.PhoneNum,node.Email);
                        if (InsertNum(head,number+1,node) == ERROR)
                            exit(EXIT_FAILURE);
                    }
                    printf("请输入需要更改的学生号:");
                    char item[20],change[20];
                    scanf("%s",item);
                    LinkNode *p = head->next;
                    for (number = 0; number < Cound(); number++)
                        if (p != NULL && strcmp(item,p->id) == 0)
                            break;
                        else
                            p = p->next;
                    printf("请输入需要更改的数据项:");
                    scanf("%s",item);
                    printf("请输入新的数据项:");
                    scanf("%s",change);
                    int num;
                    if (strcmp(item,"姓名") == 0)
                        strcpy(p->name,change);
                    if (strcmp(item,"学号") == 0)
                        strcpy(p->id,change);
                    if (strcmp(item,"性别") == 0)
                        strcpy(p->sex,change);
                    if (strcmp(item,"家庭住址") == 0)
                        strcpy(p->adress,change);
                    if (strcmp(item,"电话号码") == 0)
                        strcpy(p->PhoneNum,change);
                    if (strcmp(item,"E-mail") == 0)
                        strcpy(p->Email,change);
                    write(head);
               }break;
        case 7: return; break;
        default: printf("操作失败,"
                "请输入正确的操作\n"); break;
        }
    }
}
//////////////////////////////////////
//    功能4.按学号查询
int Found(const char *id)
{
    FILE *fp;
    if ((fp = fopen("D:\\B1231.txt","r")) == NULL)
    {
        printf("文件打开失败\n");
        return ERROR;
    }
    char test[20],found[100];
    int flag = 0;
    size_t count = 0;
    while (fscanf(fp,"%s",test) != EOF)
    {
        if(strcmp(test,id) == 0)
        {
            fgets(found,99,fp);
            flag = 1;
            printf("%s",id);
            printf("%s",found);
            if (count == Cound()*6)
                printf("\n");            //    为了最后一行有换行
            break;
        }   
        count++;
    }
    if (flag == 0)
        return ERROR;
    else
        return OK;
    fclose(fp);
}
///////////////////////////////////
//    统计总人数
size_t Cound(void)
{
    FILE *fp;
    char num[100];
    if ((fp = fopen("D:\\B1231.txt","r")) == NULL)
        printf("打开文件失败\n");
    size_t count = -1;
    while (fgets(num,99,fp) != NULL)
        count++;
    fclose(fp);   
    return count;
}
///////////////////////////////////////
//    将链表写入文件函数
void write(HeadNode head)
{
    FILE *fp;
    LinkNode *p = head->next;
    fp = fopen("D:\\B1231.txt","w");
    fprintf(fp,"%s\t%s\t%s\t%s\t%s\t%s\n",
        "学号","姓名","性别","家庭住址",
        "电话号码","E-mail");
    while (p != NULL)
    {
        fprintf(fp,"%s\t%s\t%s\t%s\t\t%s\t%s\t",
            p->id,p->name,p->sex,p->adress,
            p->PhoneNum,p->Email);
        if (p->next != NULL)            //    为了最后一行少一个换行
            fprintf(fp,"%s","\n");
        p = p->next;
    }
    fclose(fp);
}
//////////////////////////////////////
//    删除节点(删除学生信息)
int Delete(HeadNode head,int num)
{
    int i = 0;
    LinkNode *pnext,*now;
    pnext = head;
    while (pnext->next != NULL && i < num-1)
    {
        pnext = pnext->next;
        i++;
    }
    if (pnext->next == NULL)
        return ERROR;
    now = pnext->next;
    pnext->next = now->next;
    free(now);
    return OK;
}


你自己做一个文件,改一下
2013-10-23 12:46
快速回复:vc++通讯录
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.030660 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved