欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

C語言實(shí)現(xiàn)通訊錄系統(tǒng)課程設(shè)計(jì)

 更新時(shí)間:2022年07月22日 11:58:41   作者:成就一億技術(shù)人  
這篇文章主要為大家詳細(xì)介紹了C語言實(shí)現(xiàn)通訊錄系統(tǒng)課程設(shè)計(jì),文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下

本文實(shí)例為大家分享了C語言實(shí)現(xiàn)通訊錄系統(tǒng)的具體代碼,供大家參考,具體內(nèi)容如下

設(shè)計(jì)要求

1.單位、個(gè)人信息查詢
2.打開、寫入保存這些信息的文件

完整代碼

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

typedef struct Userinfo // 定義結(jié)構(gòu)體類型;封裝個(gè)人的信息
{
? ? char name[20]; // 用戶姓名
? ? char sex[2]; // 性別
? ? char cname[20]; // 單位
? ? char mobileNumber[11]; // 手機(jī)
} Userinfo;

typedef struct Companyinfo // 定義結(jié)構(gòu)體類型;封裝個(gè)人的信息
{
? ? char companyname[20]; // 姓名
? ? char companyaddress[200]; // 單位地址
? ? char telphone[8]; // 電話
} Companyinfo;

? ? int count = 0; //系統(tǒng)中的現(xiàn)有人數(shù)
? ? int countu = 0; //系統(tǒng)中的現(xiàn)有人數(shù)

void insertuserinfo(Userinfo *userinfo, int *countu)
/*添加聯(lián)系人信息*/
{
?? ?printf("請輸入要添加人的姓名:> ");
?? ?scanf("%s", (userinfo + (*countu))->name);
//flag:
?? ?printf("請輸入要添加人的性別(男/女):> ");
?? ?scanf("%s", (userinfo + (*countu))->sex);
?? ?printf("請輸入要添加人的工作單位:> ");
?? ?scanf("%s", &(userinfo + (*countu))->cname);
?? ?printf("請輸入要添加的電話:> ");
?? ?scanf("%s", (userinfo + (*countu))->mobileNumber);
?? ?printf("添加成功!\n");
?? ?(*countu)++;/*已有人數(shù)加1*/
}

void insertcompanyinfo(Companyinfo *companyinfo, int *count)
/*添加單位信息*/
{
?? ?printf("請輸入要添加單位的名稱:> ");
?? ?scanf("%s", (companyinfo + (*count))->companyname);
?? ?printf("請輸入要添加單位的地址:> ");
?? ?scanf("%s", &(companyinfo + (*count))->companyaddress);
?? ?printf("請輸入要添加單位的電話:> ");
?? ?scanf("%s", (companyinfo + (*count))->telphone);
?? ?printf("添加成功!\n");
?? ?(*count)++;/*已有人數(shù)加1*/
}

void DeleteUserinfo(Userinfo *userinfo, int *countu)
/*刪除指定聯(lián)系人信息*/
{
?? ?char _name[20];
?? ?if ((*countu) <= 0)
?? ?{
?? ??? ?printf("此系統(tǒng)中還沒有人員信息!\n");
?? ??? ?return;
?? ?}
?? ?printf("請輸入您要?jiǎng)h除人員的姓名:> ");
?? ?scanf("%s", _name);
?? ?for (int i = 0; i < (*countu); i++)
?? ?{
?? ??? ?if (strcmp((userinfo + i)->name, _name) == 0)
?? ??? ?{
?? ??? ??? ?for (int j = i; j < (*countu) - 1; j++)
?? ??? ??? ?{
?? ??? ??? ??? ?strcpy((userinfo + j)->name, (userinfo + j + 1)->name);
?? ??? ??? ??? ?strcpy((userinfo + j)->sex, (userinfo + j + 1)->sex);
?? ??? ??? ??? ?strcpy((userinfo + j)->cname ,(userinfo + j + 1)->cname);
?? ??? ??? ??? ?strcpy((userinfo + j)->mobileNumber, (userinfo + j + 1)->mobileNumber);
?? ??? ??? ?}
?? ??? ??? ?(*countu)--;
?? ??? ??? ?printf("刪除成功!\n");
?? ??? ??? ?return;
?? ??? ?}/*if*/
?? ?}/*for*/
?? ?printf("當(dāng)前系統(tǒng)中沒有此人!\n");
}

void DeleteCompanyinfo(Companyinfo *companyinfo, int *count)
/*刪除指定單位信息*/
{
?? ?char _name[20];
?? ?if ((*count) <= 0)
?? ?{
?? ??? ?printf("此系統(tǒng)中還沒有單位信息!\n");
?? ??? ?return;
?? ?}
?? ?printf("請輸入您要?jiǎng)h除單位名稱:> ");
?? ?scanf("%s", _name);
?? ?for (int i = 0; i < (*count); i++)
?? ?{
?? ??? ?if (strcmp((companyinfo + i)->companyname, _name) == 0)
?? ??? ?{
?? ??? ??? ?for (int j = i; j < (*count) - 1; j++)
?? ??? ??? ?{
?? ??? ??? ??? ?strcpy((companyinfo + j)->companyname, (companyinfo + j + 1)->companyname);
?? ??? ??? ??? ?strcpy((companyinfo + j)->companyaddress, (companyinfo + j + 1)->companyaddress);
?? ??? ??? ??? ?strcpy((companyinfo + j)->telphone, (companyinfo + j + 1)->telphone);
?? ??? ??? ?}
?? ??? ??? ?(*count)--;
?? ??? ??? ?printf("刪除成功!\n");
?? ??? ??? ?return;
?? ??? ?}/*if*/
?? ?}/*for*/
?? ?printf("當(dāng)前系統(tǒng)中沒有此單位!\n");
}

void Search(const Companyinfo *companyinfo, const int count)
/*查找指定單位信息*/
{
?? ?char _name[20];
?? ?printf("請輸入您要查找的單位名稱:> ");
?? ?scanf("%s", _name);
?? ?for (int i = 0; i < count; i++)
?? ?{
?? ??? ?if (strcmp((companyinfo + i)->companyname, _name) == 0)
?? ??? ?{
?? ??? ??? ?printf("*********=======您查單位信息為=======*********\n");
?? ??? ??? ?printf(" ? ?********* ? 單位名稱:> %s\n", (companyinfo + i)->companyname);
?? ??? ??? ?printf(" ? ?********* ? 單位地址:> %s\n", (companyinfo + i)->companyaddress);
?? ??? ??? ?printf(" ? ?********* ? 單位電話:> %s\n", (companyinfo + i)->telphone);
?? ??? ??? ?return;
?? ??? ?}
?? ?}/*for*/
?? ?printf("沒有找到您要查找的單位!\n");
}

void SearchUser(const Userinfo *userinfo, const int countu)
/*查找指定聯(lián)系人信息*/
{
?? ?char _name[20];
?? ?printf("請輸入您要查找人的信息:> ");
?? ?scanf("%s", _name);
?? ?for (int i = 0; i < countu; i++)
?? ?{
?? ??? ?if (strcmp((userinfo + i)->name, _name) == 0)
?? ??? ?{
?? ??? ??? ?printf("*********=======您查個(gè)人信息為=======*********\n");
?? ??? ??? ?printf(" ? ?********* ? 姓名:> %s\n", (userinfo + i)->name);
?? ??? ??? ?printf(" ? ?********* ? 性別:> %s\n", (userinfo + i)->sex);
?? ??? ??? ?printf(" ? ?********* ? 單位:> %d\n", (userinfo + i)->cname);
?? ??? ??? ?printf(" ? ?********* ? 電話:> %d\n", (userinfo + i)->mobileNumber);
?? ??? ??? ?return;
?? ??? ?}
?? ?}/*for*/
?? ?printf("沒有找到您要查找的人員!\n");
}

void Alter(Companyinfo *companyinfo, const int count)
/*修改指定單位信息*/
{
?? ?char _name[20];
?? ?printf("請輸入您要修改的單位的名稱:> ");
?? ?scanf("%s", _name);
?? ?for (int i = 0; i < count; i++)
?? ?{
?? ??? ?if (strcmp((companyinfo + i)->companyname, _name) == 0)
?? ??? ?{
?? ??? ??? ?printf("請輸入修改后的單位名稱:> ");
?? ??? ??? ?scanf("%s", (companyinfo + i)->companyname);
?? ??? ??? ?printf("請輸入修改后的單位地址:> ");
?? ??? ??? ?scanf("%s", (companyinfo + i)->companyaddress);
?? ??? ??? ?printf("請輸入修改后的單位電話:> ");
?? ??? ??? ?scanf("%s", (companyinfo + i)->telphone);
?? ??? ??? ?printf("修改成功!\n");
?? ??? ??? ?return;
?? ??? ?}
?? ?}/*for*/
?? ?printf("沒有找到您要查找的單位!\n");
}

void Show(const Companyinfo *companyinfo, const int count)
/*顯示所有單位信息*/
{
?? ?if (count == 0)
?? ?{
?? ??? ?printf("沒有找到您要查找的單位!\n");
?? ?}
?? ?else
?? ?{
?? ??? ?for (int i = 0; i < count; i++)
?? ??? ?{
?? ??? ??? ?printf("%5s ? ?|%13s ?|%s\n", (companyinfo + i)->companyname, (companyinfo + i)->telphone, (companyinfo + i)->companyaddress);
?? ??? ?}
?? ?}
}

void OpenFile()
{
? ?FILE *fp = NULL;
? ?char buff[255];
? ?fp = fopen("/Teldict.txt", "r");
? ?printf("打開文件名:Teldict.text \n");
? ?printf("內(nèi)容如下:\n");
? ?fgets(buff, 255, (FILE*)fp);
? ?printf("1: %s\n", buff );
? ?fclose(fp);
}

void WriteFile()
{
? char s[100];
? ?FILE *fp = NULL;
? ?fp = fopen("/Teldict.txt", "w+");
? ? ? ? ? ? printf("請輸入寫入文件的內(nèi)容: ");
? ? ? ? ? ? scanf("%s",&s);
? ?fprintf(fp,s);
? ?fputs(s, fp);
?// ?fputs("This is testing for fputs...\n", fp);
? ?fclose(fp);

}

int StcCmp(const void*num1, const void *num2)
/*快排的比較函數(shù)*/
{
?? ?return (strcmp(((Companyinfo *)num1)->companyname, ((Companyinfo *)num2)->companyname) > 0) ? 1 : -1;
}

int switchuserinfo(Userinfo *userinfo)
{

? ? int b;
? ? ? ? ? ? printf("\n");
? ? ? ? ? ? printf("1)新建個(gè)人信息\n");
? ? ? ? ? ? printf("2)修改個(gè)人信息\n");
? ? ? ? ? ? printf("3)刪除個(gè)人信息\n");
? ? ? ? ? ? printf("4)返回上一菜單\n");
? ? ? ? ? ? printf("請選擇上面序號進(jìn)行相應(yīng)的操作: ");
? ? ? ? ? ? scanf("%d",&b);
? ? ? ? ? ? switch(b)
? ? ? ? ? ? {
? ? ? ? ? ? ? ? case 1:
? ? ? ? ? ? ? ? ? ? {
? ? ? ? ? ? ? ? ? ? ? insertuserinfo(userinfo,&countu);
? ? ? ? ? ? ? ? ? ? ? break;
? ? ? ? ? ? ? ? ? ? }
? ? ? ? ? ? ? ? case 2:
? ? ? ? ? ? ? ? ? ? {
? ? ? ? ? ? ? ? ? ? ? void Alter(Companyinfo *companyinfo, const int count);
? ? ? ? ? ? ? ? ? ? ? break;
? ? ? ? ? ? ? ? ? ? }
? ? ? ? ? ? ? ? case 3:
? ? ? ? ? ? ? ? ? ? {
? ? ? ? ? ? ? ? ? ? ? void Alter(Companyinfo *companyinfo, const int count);
? ? ? ? ? ? ? ? ? ? ? break;
? ? ? ? ? ? ? ? ? ? }

? ? ? ? ? ? ? ? case 4:break;
? ? ? ? ? ? }
? ?return 0;

}

int switchcompanyinfo(Companyinfo *companyinfo)
{

? ? ? int b;
? ? ? ? ? ? printf("\n");
? ? ? ? ? ? printf("1)新建單位信息\n");
? ? ? ? ? ? printf("2)修改單位信息\n");
? ? ? ? ? ? printf("3)刪除單位信息\n");
? ? ? ? ? ? printf("4)查詢單位信息\n");
? ? ? ? ? ? printf("5)顯示單位信息\n");
? ? ? ? ? ? printf("6)返回上一菜單\n");
? ? ? ? ? ? printf("請選擇上面序號進(jìn)行相應(yīng)的操作: ");
? ? ? ? ? ? scanf("%d",&b);
? ? ? ? ? ? switch(b)
? ? ? ? ? ? {
? ? ? ? ? ? ? ? case 1:
? ? ? ? ? ? ? ? ? ? {
? ? ? ? ? ? ? ? ? ? ? insertcompanyinfo(companyinfo,&count);
? ? ? ? ? ? ? ? ? ? ? break;
? ? ? ? ? ? ? ? ? ? }
? ? ? ? ? ? ? ? case 2:
? ? ? ? ? ? ? ? ? ? {
? ? ? ? ? ? ? ? ? ? ? Alter(companyinfo,count);
? ? ? ? ? ? ? ? ? ? ? break;
? ? ? ? ? ? ? ? ? ? }
? ? ? ? ? ? ? ? case 3:
? ? ? ? ? ? ? ? ? ? {
? ? ? ? ? ? ? ? ? ? ? DeleteCompanyinfo(companyinfo,&count);
? ? ? ? ? ? ? ? ? ? ? break;
? ? ? ? ? ? ? ? ? ? }
? ? ? ? ? ? ? ? case 4:
? ? ? ? ? ? ? ? ? ? {
? ? ? ? ? ? ? ? ? ? ? Search(companyinfo,count);
? ? ? ? ? ? ? ? ? ? ? break;
? ? ? ? ? ? ? ? ? ? }
? ? ? ? ? ? ? ? case 5:
? ? ? ? ? ? ? ? ? ? {
? ? ? ? ? ? ? ? ? ? ? Show(companyinfo,count);
? ? ? ? ? ? ? ? ? ? ? break;
? ? ? ? ? ? ? ? ? ? }
? ? ? ? ? ? ? ? case 6:break;
? ? ? ? ? ? }
?return 0;
};

int main()
{
Userinfo userinfo[10];
Companyinfo companyinfo[10];
int inputkey;
printf("歡迎使用電話薄查詢系統(tǒng)!\n\n");

qq:
? ?printf("請輸入登錄賬號:");
? ?scanf("%d",&inputkey);
? int input = 1;
if (inputkey==1001)
?{
?? ?while (input)
?? ?{
?? ? ?printf("\n");
? ? ?printf("請選擇對應(yīng)序號:(1) 單位信息管理; (2)個(gè)人信息管理 ?(3)重新登錄 ?(4)退出 :");
? ? ?scanf("%d",&input);
?? ??? ?switch (input)
?? ??? ?{
?? ? ? ? ?case 1: ? ? ?//單位信息管理
?? ??? ??? ? switchcompanyinfo(companyinfo);
?? ??? ??? ? break;
?? ? ? ? ?case 2: ? ? ?//個(gè)人信息管理
?? ??? ??? ? switchuserinfo(userinfo);
?? ??? ??? ? break;
?? ? ? ? ?case 3: ? ? ?//
?? ??? ??? ? goto qq;
?? ??? ??? ? break;
?? ??? ? ?case 4:
?? ??? ??? ?printf("感謝您試用本服務(wù)系統(tǒng),歡迎您的下次使用!\n");
?? ??? ??? ?system("pause");
?? ??? ? ? ?return 0;
? ? ?? ?};//while

? ? ?}
?}
? else
? ? {
? ?? ?while (input)
?? ?{
?? ? ? ?printf("請選擇操作序號 :\n\n");
?? ? ? ?printf("1)單位查詢\n");
?? ? ? ?printf("2)個(gè)人信息查詢\n");
?? ? ? ?printf("3)打開文件\n");
?? ? ? ?printf("4)寫入文件\n");
?? ? ? ?printf("5)重新登錄\n");
?? ? ? ?printf("6)退出\n");
? ? ?scanf("%d",&input);
?? ??? ?switch (input)
?? ??? ?{
?? ? ? ? ?case 1: ? ? ?//單位查詢
?? ??? ??? ? Search(companyinfo, count);
?? ??? ??? ? break;
?? ? ? ? ?case 2: ? ? ?//個(gè)人信息查詢
?? ??? ??? ? SearchUser(userinfo, countu);
?? ??? ??? ? break;
?? ? ? ? ?case 3: ? ? ?//打開文件
?? ??? ??? ? OpenFile();
?? ??? ??? ? break;
?? ? ? ? ?case 4: ? ? ?//寫入文件
?? ??? ??? ? WriteFile();
?? ??? ??? ? break;
? ? ? ? ? case 5 :
? ? ? ? ? ? goto qq; break;

?? ??? ? ?case 6:
?? ??? ??? ?printf("感謝您試用本服務(wù)系統(tǒng),歡迎您的下次使用!\n");
?? ??? ??? ?system("pause");
?? ??? ? ? ?return 0;
? ? ?? ?};//while

?? ?}

? ? }

? printf("\n");
?? ?system("pause");
? return 0;
}

運(yùn)行結(jié)果

本代碼設(shè)置的登錄賬號是1,當(dāng)然你也可以進(jìn)行修改。

以上就是本文的全部內(nèi)容,希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。

相關(guān)文章

最新評論