C课程设计

这个课程设计不够完美,仅仅实现了增删查改的功能,使用了指针操作。时间不够了,只有先这样了,过几天考完试再补写吧~
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<stdlib.h>
#include<algorithm>
using namespace std;
#define LEN sizeof(struct infor)
struct infor
{
    long num;
    char adr[50];
    char name[20];
    char rela[20];
    struct infor *next;
};
struct infor *Head;
struct infor *del(struct infor *head,long number)
{
    void menu();
    struct infor *pf,*pb;
    if(head->next==NULL)
    {
        printf("你还没有好友\n");
        goto end;
    }
    pb=head->next;
    while(pb->num!=number&&pb->next!=NULL)
    {
        pf=pb;
        pb=pb->next;
    }
    if(pb->num==number)
    {
        if(pb==head->next)
            head->next=pb->next;
        else
            pf->next=pb->next;
        printf("该好友已被删除\n");
    }
    else
    {
        printf("没有该好友\n");
    }
    printf("请按任意键继续!");
    getchar();
    getchar();
end:
    menu();
    return head;
}
void home()
{
    system("color 2d");
    printf("\n");
    printf("\t o(∩_∩)o o(∩_∩)o o(∩_∩)o o(∩_∩)o o(∩_∩)o o(∩_∩)o \n");
    printf("\n");
    printf("\t  ☆☆☆☆☆☆☆☆☆☆☆☆☆★☆☆☆☆☆☆☆☆☆☆☆☆☆☆\n");
    printf("\t  ☆                                                    ☆\n");
    printf("\t  ☆                                                    ☆\n");
    printf("\t  ☆                                                    ☆\n");
    printf("\t  ☆              欢迎使用通讯录管理系统                ☆\n");
    printf("\t  ☆                                                    ☆\n");
    printf("\t  ★                                                    ★\n");
    printf("\t  ☆                                                    ☆\n");
    printf("\t  ☆                                                    ☆\n");
    printf("\t  ☆                                                    ☆\n");
    printf("\t  ☆                                   制作人;         ☆\n");
    printf("\t  ☆                                       2014.6.23    ☆\n");
    printf("\t  ☆                                                    ☆\n");
    printf("\t  ☆☆☆☆☆☆☆☆☆☆☆☆☆★☆☆☆☆☆☆☆☆☆☆☆☆☆☆\n");
    getchar();
}
void display(struct infor *head)
{
    void menu();
    struct infor *p;
    p = head->next;
    printf("学生信息如下:\n");
    printf("\t\t好友号码\t好友住址\t好友姓名\t你们的关系\n");
    while(p!= NULL)
    {
        printf("\t\t%-8ld\t%-8s\t%-8s\t%-8s\n",p->num,p->adr,p->name,p->rela);
        p = p->next;
    }
    printf("请按任意键继续!");
    getchar();
    getchar();
    menu();
}
bool Find(struct infor *head,long ai)
{
    struct infor *pi;
    pi=head->next;
    while(pi!=NULL&&pi->num!=ai)
    pi=pi->next;
    if(pi&&pi->num==ai)
        return 0;
    else
        return 1;
}
struct infor *add(struct infor *head)
{
    void menu();
    int n,t,m;
    struct infor *p,*pi,*flag;
    printf("希望增添几个好友?\n");
    scanf("%d",&n);
    while(n--)
    {
        pi = head;
        while(pi->next != NULL)
        {
            pi=pi->next;
        }
        printf("1.在通讯录顶部增添\t2.在通讯录底部增添\t\n");
        scanf("%d",&t);
        getchar();
        char numstr[20];
        if(t==1)
        {
            struct infor *pt =head->next;
            p=(struct infor *)malloc(LEN);
            p->next=NULL;
            printf("请输入所要添加好友的号码: ");
            gets(numstr);
            long aa=atol(numstr);
            if(!Find(head,aa))
            {
                printf("该好友号码已经存在!\n请按任意键继续!");
                getchar();
                getchar();
                menu();
            }
            p->num=atol(numstr);
            printf("请输入好友住址: ");
            gets(p->adr);
            printf("请输入好友姓名: ");
            gets(p->name);
            printf("请输入关系:");
            gets(p->rela);
            head->next=p;
            p->next=pt;
        }
        if(t==2)
        {
            p=(struct infor *)malloc(LEN);
            p->next=NULL;
            printf("请输入所要添加好友的号码: ");
            gets(numstr);
            long aa=atol(numstr);
            if(!Find(head,aa))
            {
                printf("该好友号码已经存在!\n请按任意键继续!");
                getchar();
                getchar();
                menu();
            }
            p->num=atol(numstr);
            printf("请输入好友住址: ");
            gets(p->adr);
            printf("请输入好友姓名: ");
            gets(p->name);
            printf("请输入关系:");
            gets(p->rela);
            pi->next=p;
            pi=p;
        }
    }
    menu();
}
struct infor *print(struct infor *Head)
{
    void menu();
    char cho;
    struct infor *p,*pi;
    pi=Head;
    int num;
loop:
    printf("请输入你所要查询的好友学号:");
    scanf("%ld",&num);
    getchar();
    while(num!=pi->num&&pi->next!=NULL)
        pi=pi->next;
    if(pi->num==num)
    {
        printf("该好友的基本信息如下:\n\t\t好友号码:%d\n\t\t好友住址:%s\n\t\t好友姓名:%s\n\t\t你们的关系:%s\n",pi->num,pi->adr,pi->name,pi->rela);
        printf("是否需要继续查找?\n是:Y\t否:N\n");
        scanf("%c",&cho);
        getchar();
        if(cho=='Y'||cho=='y')
            goto loop;
        else if(cho=='N'||cho=='n')
            goto end;
    }
    else
    {
        printf("没有该好友!是否继续查找?\n是:Y\t否:N\n");
        scanf("%c",&cho);
        getchar();
        if(cho=='Y'||cho=='y')
            goto loop;
        else if(cho=='N'||cho=='n')
            goto end;
    }
end:
    printf("请按任意键继续!");
    getchar();
    menu();
    return Head;
}
struct infor *modify(struct infor *head)
{
    void menu();
    long numb;
    struct infor *p,*pi;
    printf("请输入所要修改好友的号码:");
    scanf("%ld",&numb);
    pi=head->next;
    while(pi!=NULL&&numb!=pi->num)
    {
        pi=pi->next;
    }
    if(pi&&pi->num==numb)
    {
        printf("请输入修改后的好友\n号码:");
        scanf("%ld",&pi->num);
        printf("住址:");
        scanf("%s",&pi->adr);
        printf("姓名:");
        scanf("%s",&pi->name);
        printf("关系:");
        scanf("%s",&pi->rela);
        printf("修改完毕!");
    }
    else
    {
        printf("您没有改好友!");
    }
    printf("请按任意键继续!");
    getchar();
    getchar();
    menu();
}
void menu()
{
    int n;
    system("cls");
    printf("\n\t\t          欢迎使用好友管理系统 \n ");
    printf("\t   ☆☆☆☆☆☆☆☆☆☆☆☆☆★☆☆☆☆☆☆☆☆☆☆☆☆☆☆\n");
    printf("\t   ☆                                                    ☆\n");
    printf("\t   ☆                      功能菜单                      ☆\n");
    printf("\t   ☆                     1.添加好友                     ☆\n");
    printf("\t   ☆                     2.删除好友                     ☆\n");
    printf("\t   ★                     3.修改信息                     ★\n");
    printf("\t   ☆                     4.查看资料                     ☆\n");
    printf("\t   ☆                     5.显示资料                     ☆\n");
    printf("\t   ☆                     6.退出系统                     ☆\n");
    printf("\t   ☆                                                    ☆\n");
    printf("\t   ☆                                                    ☆\n");
    printf("\t   ☆                                                    ☆\n");
    printf("\t   ☆☆☆☆☆☆☆☆☆☆☆☆☆★☆☆☆☆☆☆☆☆☆☆☆☆☆☆\n");
    printf("请选择功能:[ ]\b\b");
    scanf("%d",&n);
    switch(n)
    {
    case 1:
        add(Head);
        break;
    case 2:
        long aim;
        printf("请输入所要删除好友的号码:");
        scanf("%d",&aim);
        del(Head,aim);
        break;
    case 3:
        modify(Head);
        break;
    case 4:
        print(Head);
        break;
    case 5:
        display(Head);
        break;
    case 6:
        exit(0);
        break;
    }
}
int main()
{
    Head = (struct infor*)malloc(LEN);
    Head->next=NULL;
    home();
    menu();
    return 0;
}

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
提供的源码资源涵盖了安卓应用、小程序、Python应用和Java应用等多个领域,每个领域都包含了丰富的实例和项目。这些源码都是基于各自平台的最新技术和标准编写,确保了在对应环境下能够无缝运行。同时,源码中配备了详细的注释和文档,帮助用户快速理解代码结构和实现逻辑。 适用人群: 这些源码资源特别适合大学生群体。无论你是计算机相关专业的学生,还是对其他领域编程感兴趣的学生,这些资源都能为你提供宝贵的学习和实践机会。通过学习和运行这些源码,你可以掌握各平台开发的基础知识,提升编程能力和项目实战经验。 使用场景及目标: 在学习阶段,你可以利用这些源码资源进行课程实践、课外项目或毕业设计。通过分析和运行源码,你将深入了解各平台开发的技术细节和最佳实践,逐步培养起自己的项目开发和问题解决能力。此外,在求职或创业过程中,具备跨平台开发能力的大学生将更具竞争力。 其他说明: 为了确保源码资源的可运行性和易用性,特别注意了以下几点:首先,每份源码都提供了详细的运行环境和依赖说明,确保用户能够轻松搭建起开发环境;其次,源码中的注释和文档都非常完善,方便用户快速上手和理解代码;最后,我会定期更新这些源码资源,以适应各平台技术的最新发展和市场需求。

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值