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

C語(yǔ)言實(shí)現(xiàn)電話訂餐管理系統(tǒng)

 更新時(shí)間:2022年01月04日 14:36:00   作者:樂觀的阿斯頓  
這篇文章主要為大家詳細(xì)介紹了C語(yǔ)言實(shí)現(xiàn)電話訂餐管理系統(tǒng),文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下

本文實(shí)例為大家分享了C語(yǔ)言實(shí)現(xiàn)電話訂餐管理系統(tǒng)的具體代碼,供大家參考,具體內(nèi)容如下

這是我C語(yǔ)言課程設(shè)計(jì)的題目。非常奇怪啊,下面的代碼能在C-Free中跑起來,卻沒辦法在vc++6.0中跑起來??赡苁蔷幾g器支持的標(biāo)準(zhǔn)不一樣。不管他,反正老師不會(huì)把我的代碼打一遍,然后放到vc中去運(yùn)行。

實(shí)現(xiàn)了4個(gè)功能:添加、查找、修改、刪除,同時(shí)會(huì)把信息寫入到同一目錄下的customer.dat文件中。(這個(gè)文件需要手動(dòng)建立,沒有建立的話程序會(huì)不運(yùn)行。)。
能力有限,錯(cuò)誤在所難免,歡迎指出。

代碼:

/*
?* 電話訂餐處理系統(tǒng)?
?* 第八組C語(yǔ)言課程設(shè)計(jì)
?* 佛祖保佑,永無(wú) BUG
?*/?

#include<stdio.h>
#include<stdlib.h>
#include<windows.h>
#include<time.h>

void PrintMenu(); // 聲明主界面函數(shù)?
void AddCustomerInfo(); // 聲明添加顧客訂餐信息的函數(shù)?
void ModifyCustmoerInfo(); // 聲明修改顧客訂餐信息的函數(shù),記得加參數(shù)?
void DeleteCustomerInfo(); // 聲明刪除顧客訂餐信息的函數(shù),記得加參數(shù)
int searchdata();// 查找顧客訂餐信息并返回值?
void SearchCustomerInfo();// 聲明查詢顧客訂餐信息的函數(shù),記得加參數(shù)
void ViewAllInfo(); // 聲明預(yù)覽全部訂餐信息的函數(shù),記得加參數(shù)?
void ColorChange(int); // 聲明修改背景&字體顏色的函數(shù)?
void Cutline(); // 聲明分界線函數(shù)?
int Unix2Time();// 聲明時(shí)間戳轉(zhuǎn)換為普通時(shí)間的函數(shù)
void Time2Unix(time_t,char,char []);// 聲明普通時(shí)間轉(zhuǎn)換為時(shí)間戳的函數(shù) ?
void GetAllInfo();//獲取所有顧客的全部信息?
void SetConsolSize(int x,int y);//定義修改緩沖區(qū)大小的函數(shù)?
static int n=0;// 定義一個(gè)全局變量n用來獲取總共有多少顧客信息?


// 聲明一個(gè)顧客的結(jié)構(gòu)體變量?
struct Customer
{
?? ?char no[15];?
?? ?char name[20];
?? ?char phoneNumber[20];
?? ?char booktime[40];
?? ?int num;
?? ?char other[200];
?? ?char ordertime[40];
}customer[100],custmp;

int main()
{
?? ?int choice;
?? ?SetConsoleTitle("電話訂餐系統(tǒng)");
?? ?GetAllInfo();
?? ?system("mode con cols=150 lines=40");// 調(diào)用cmd命令修改窗口大小?
?? ?SetConsolSize(150,999);//修改緩沖區(qū)的大小?
?? ?printf("歡迎使用電話訂餐系統(tǒng)!\n");
?? ?printf("請(qǐng)輸入菜單前標(biāo)號(hào)以執(zhí)行操作\n");
?? ?PrintMenu:
?? ?PrintMenu();
?? ?//ColorChange(5);
?? ?GetChoice:
?? ?fflush(stdin);?
?? ?choice=-1;//重置choice的值?
?? ?printf("\n請(qǐng)輸入你的選項(xiàng) >");
?? ?scanf("%d",&choice);?
?? ?fflush(stdin); // 清空緩沖區(qū),防止scanf接受多余的回車導(dǎo)致死循環(huán)?
?? ?switch(choice)
?? ?{
?? ??? ?case 1:AddCustomerInfo();break;
?? ??? ?case 2:ModifyCustmoerInfo();break;
?? ??? ?case 3:DeleteCustomerInfo();break;
?? ??? ?case 4:SearchCustomerInfo();break;
?? ??? ?case 5:ViewAllInfo();break;
?? ??? ?case 6:goto PrintMenu;break;
?? ??? ?case 0:exit(0);
?? ??? ?default:{
?? ??? ??? ?Cutline();
?? ??? ??? ?ColorChange(4);
?? ??? ??? ?printf("輸入錯(cuò)誤!請(qǐng)重新輸入!\n");?
?? ??? ??? ?ColorChange(-1);
?? ??? ??? ?Cutline();
?? ??? ?}
?? ??? ??? ?
?? ?}
?? ?goto GetChoice;
}

void PrintMenu()//打印菜單函數(shù)?
{
?? ?printf("┏━━━━━━━━━━━━━━━━┓\n");?
?? ?printf("┃ 0. 退出本系統(tǒng) ?┃\n");
?? ?printf("┃ 1. 錄入訂餐信息┃\n");
?? ?printf("┃ 2. 修改訂餐信息┃\n");
?? ?printf("┃ 3. 刪除訂餐信息┃\n");
?? ?printf("┃ 4. 查詢訂餐信息┃\n");
?? ?printf("┃ 5. 預(yù)覽訂餐信息┃\n");
?? ?printf("┃ 6. 顯示菜單 ? ?┃\n");
?? ?printf("┗━━━━━━━━━━━━━━━━┛\n");?
}

void ColorChange(int color)//改變字體顏色函數(shù)?
{
?? ?HANDLE SELF = GetStdHandle(STD_OUTPUT_HANDLE);
?? ?
?? ?if(color==-1)
?? ??? ?SetConsoleTextAttribute(SELF,7);
?? ?SetConsoleTextAttribute(SELF,color);
}

void Cutline()//顯示一條分割線?
{
?? ?printf("————————————\n");
}

void AddCustomerInfo()//追加一條顧客的信息?
{
?? ?FILE *fp;
?? ?Cutline();
?? ?
?? ?//嘗試打開顧客數(shù)據(jù)文件 customer.dat?
?? ?if((fp=fopen(".\\customer.dat","rb"))==NULL)
?? ?{?
?? ??? ?ColorChange(4);
?? ??? ?printf("打開顧客數(shù)據(jù)文件失??!\n");
?? ??? ?//printf("寫入顧客信息失??!");
?? ??? ?ColorChange(7);
?? ??? ?Cutline();
?? ??? ?return;
?? ?}
?? ?
?? ?//輸入顧客的訂餐信息?
?? ?printf("請(qǐng)輸入顧客姓名 >");
?? ?scanf("%[^\n]s",custmp.name);
?? ?fflush(stdin); //清空緩沖區(qū)?
?? ?printf("請(qǐng)輸入顧客電話 >");
?? ?scanf("%s",custmp.phoneNumber);
?? ?fflush(stdin);?
?? ?printf("請(qǐng)輸入顧客的預(yù)定時(shí)間 >");
?? ?scanf("%[^\n]s",custmp.booktime);
?? ?fflush(stdin);?
?? ?printf("請(qǐng)輸入用餐的人數(shù) >");
?? ?scanf("%d",&custmp.num);
?? ?fflush(stdin);?
?? ?printf("請(qǐng)輸入顧客的備注 >");
?? ?scanf("%[^\n]s",custmp.other);
?? ?fflush(stdin);?
?? ??
?? ?// 生成以時(shí)間為編號(hào)的顧客編號(hào)?
?? ?time_t rawtime;
?? ?time(&rawtime);?
?? ?Time2Unix(rawtime,'t',custmp.ordertime);
?? ?Time2Unix(rawtime,'n',custmp.no);
?? ??? ?
?? ?fclose(fp);
?? ?
?? ?//將顧客的數(shù)據(jù)文件寫入到 customer.dat中去?
?? ?fp=fopen(".\\customer.dat","ab");
?? ?fwrite(&custmp,sizeof(struct Customer),1,fp);
?? ?fclose(fp);
?? ?Cutline();
}

void ModifyCustmoerInfo()//修改顧客訂餐信息?
{
?? ?char target[40];
?? ?int no,choice;
?? ?long int movesize;
?? ?no=searchdata();
?? ?printmenu:
?? ?printf("\n查詢到下列顧客信息:\n");
?? ?printf("\n編號(hào)\t\t姓名\t\t電話\t\t用餐人數(shù) ? 預(yù)定日期\t\t\t下單日期\t\t\t備注\n");
?? ?ColorChange(240);
?? ?printf("%-16s",customer[no].no);
?? ?printf("%-16s",customer[no].name);
?? ?printf("%-16s",customer[no].phoneNumber);
?? ?printf("%-11d",customer[no].num);
?? ?printf("%-30s",customer[no].booktime);
?? ?printf("%-31s",customer[no].ordertime);
?? ?printf("%-39s\n",customer[no].other);
?? ?ColorChange(-1);
?? ?printf("┏━━━━━━━━━━━━━━┓\n");
?? ?printf("┃0.結(jié)束修改 ? ?┃\n");?
?? ?printf("┃1.姓名 ? ? ? ?┃\n");
?? ?printf("┃2.電話 ? ? ? ?┃\n");
?? ?printf("┃3.用餐人數(shù) ? ?┃\n");
?? ?printf("┃4.預(yù)定日期 ? ?┃\n");
?? ?printf("┃5.備注 ? ? ? ?┃\n");
?? ?printf("┃6.重新選擇顧客┃\n");
?? ?printf("┗━━━━━━━━━━━━━━┛\n");
?? ?GetModifiedInfo:
?? ?Cutline();
?? ?printf("\n請(qǐng)選擇你要修改的項(xiàng)目 >");
?? ?scanf("%d",&choice);
?? ?//菜單分支?
?? ?switch(choice)
?? ?{
?? ??? ?
?? ??? ?case 1:{
?? ??? ??? ?printf("請(qǐng)輸入更正后的內(nèi)容 >");
?? ??? ??? ?scanf("%s",customer[no].name);
?? ??? ??? ?goto WriteCustData;?
?? ??? ?}break;
?? ??? ?
?? ??? ?case 2:{
?? ??? ??? ?printf("請(qǐng)輸入更正后的內(nèi)容 >");
?? ??? ??? ?scanf("%s",customer[no].phoneNumber);?
?? ??? ??? ?goto WriteCustData;
?? ??? ?}break;
?? ??? ?
?? ??? ?case 3:{
?? ??? ??? ?printf("請(qǐng)輸入更正后的內(nèi)容 >");
?? ??? ??? ?scanf("%d",&customer[no].num);?
?? ??? ??? ?goto WriteCustData;
?? ??? ?}break;
?? ??? ?
?? ??? ?case 4:{
?? ??? ??? ?printf("請(qǐng)輸入更正后的內(nèi)容 >");
?? ??? ??? ?scanf("%s",customer[no].booktime);?
?? ??? ??? ?goto WriteCustData;
?? ??? ?}break;
?? ??? ?
?? ??? ?case 5:{
?? ??? ??? ?printf("請(qǐng)輸入更正后的內(nèi)容 >");
?? ??? ??? ?scanf("%s",customer[no].other);?
?? ??? ??? ?goto WriteCustData;
?? ??? ?}break;
?? ??? ?
?? ??? ?case 6:{?
?? ??? ??? ?no=searchdata();
?? ??? ??? ?goto printmenu;
?? ??? ?}
?? ??? ?
?? ??? ?case 0:return;
?? ??? ?
?? ??? ?default:{
?? ??? ??? ?ColorChange(4);
?? ??? ??? ?printf("輸入錯(cuò)誤!");
?? ??? ??? ?ColorChange(-1);
?? ??? ??? ?goto GetModifiedInfo;
?? ??? ?}break;
?? ?}?
?? ?
?? ?//將要修改的顧客信息定點(diǎn)在customer.dat文件中覆蓋修改?
?? ?WriteCustData:
?? ?movesize=no*sizeof(struct Customer);
?? ?printf("movesize is %d\n",movesize);
?? ?FILE *fp;
?? ?fp=fopen(".\\customer.dat","r+");
?? ?rewind(fp);
?? ?fseek(fp,1L*(movesize),0);
?? ?fwrite(&customer[no],sizeof(struct Customer),1,fp);
?? ?fclose(fp);
?? ?goto GetModifiedInfo;
}

void DeleteCustomerInfo()
{
?? ?int i,no;
?? ?no=searchdata();
?? ?char choice;
?? ?FILE *fp;
?? ?
?? ?printf("\n查詢到下列顧客信息:\n");
?? ?printf("\n編號(hào)\t\t姓名\t\t電話\t\t用餐人數(shù) ? 預(yù)定日期\t\t\t下單日期\t\t\t備注\n");
?? ?ColorChange(240);
?? ?printf("%-16s",customer[no].no);
?? ?printf("%-16s",customer[no].name);
?? ?printf("%-16s",customer[no].phoneNumber);
?? ?printf("%-11d",customer[no].num);
?? ?printf("%-30s",customer[no].booktime);
?? ?printf("%-31s",customer[no].ordertime);
?? ?printf("%-39s\n",customer[no].other);
?? ?ColorChange(-1);
?? ?ColorChange(4);
?? ?
?? ?printf("\n是否刪除這個(gè)用戶的數(shù)據(jù)?(y/n) >");
?? ?fflush(stdin);
?? ?scanf("%c",&choice);?
?? ?ColorChange(7);
?? ?if(choice=='n'||choice=='N')
?? ?{
?? ??? ?printf("\n返回主菜單...\n");
?? ??? ?return;
?? ?}
?? ?
?? ?if(choice=='y'||choice=='Y')
?? ?{
?? ??? ?GetAllInfo();
?? ??? ?fp=fopen(".\\customer.dat","wb");
?? ??? ?fclose(fp);
?? ??? ?fp=fopen(".\\customer.dat","ab");
?? ??? ?printf("%d,%d",n,no);
?? ??? ?for(i=0;i<=(n-1);i++)
?? ??? ?{
?? ??? ??? ?if(i==no)
?? ??? ??? ??? ?continue;
?? ??? ??? ??? ?
?? ??? ??? ?fwrite(&customer[i],sizeof(struct Customer),1,fp);
?? ??? ??? ?
?? ??? ?}
?? ??? ?fclose(fp);
?? ?}
?? ?
}

int searchdata()//根據(jù)所給的條件尋找對(duì)應(yīng)的顧客i?
{
?? ?GetAllInfo();
?? ?char target[100];
?? ?printf("\n請(qǐng)輸入用戶任意單項(xiàng)信息 >");
?? ?scanf("%s",target);
?? ?int i,res1,res2,res3;
?? ?for(i=0;i<=(n-1);i++)
?? ?{
?? ??? ?res1=memcmp(target,customer[i].no,strlen(customer[i].no));
?? ??? ?res2=memcmp(target,customer[i].name,strlen(customer[i].name));
?? ??? ?res3=memcmp(target,customer[i].phoneNumber,strlen(customer[i].phoneNumber));
?? ??? ?if(!(res1&&res2&&res3))
?? ??? ??? ?return i;?
?? ?}
?? ?return -1;
}

void SearchCustomerInfo()
{
?? ?int no=searchdata();
?? ?printf("\n查詢到下列顧客信息:\n");
?? ?printf("\n編號(hào)\t\t姓名\t\t電話\t\t用餐人數(shù) ? 預(yù)定日期\t\t\t下單日期\t\t\t備注\n");
?? ?ColorChange(240);
?? ?printf("%-16s",customer[no].no);
?? ?printf("%-16s",customer[no].name);
?? ?printf("%-16s",customer[no].phoneNumber);
?? ?printf("%-11d",customer[no].num);
?? ?printf("%-30s",customer[no].booktime);
?? ?printf("%-31s",customer[no].ordertime);
?? ?printf("%-100s\n",customer[no].other);
?? ?ColorChange(-1);
}

void GetAllInfo()//獲取所有顧客的全部信息函數(shù)?
{
?? ?n=0;
?? ?FILE *fp;
?? ?fp=fopen(".\\customer.dat","rb");
?? ?do
?? ?{
?? ??? ?fread(&customer[n],sizeof(struct Customer),1,fp);
?? ??? ?//if(customer[n].no[0]=='\0')
?? ??? ?//?? ?break;
?? ??? ?n++;
?? ?}while(feof(fp)==0);
?? ?n=n-1;
?? ?fclose(fp);
}

void ViewAllInfo()
{
?? ?GetAllInfo();?
?? ?printf("n is %d",n);
?? ?int i=0,flag=1;
?? ?printf("\n編號(hào)\t\t姓名\t\t電話\t\t用餐人數(shù) ? 預(yù)定日期\t\t\t下單日期\t\t\t備注\n");?
?? ?while(i<=(n-1))
?? ?{
?? ??? ?if(flag)
?? ??? ?{
?? ??? ??? ?ColorChange(240);
?? ??? ??? ?flag=0;
?? ??? ?}else{
?? ??? ??? ?ColorChange(7);
?? ??? ??? ?flag=1;
?? ??? ?}
?? ??? ?printf("%-16s",customer[i].no);
?? ??? ?printf("%-16s",customer[i].name);
?? ??? ?printf("%-16s",customer[i].phoneNumber);
?? ??? ?printf("%-11d",customer[i].num);
?? ??? ?printf("%-30s",customer[i].booktime);
?? ??? ?printf("%-31s",customer[i].ordertime);
?? ??? ?printf("%-100s\n",customer[i].other);
?? ??? ?++i;
?? ?}
?? ?ColorChange(-1);
?? ?putchar('\n');
}

/* 將時(shí)間戳轉(zhuǎn)換為原時(shí)間的函數(shù) */?
void Time2Unix(time_t Timestamp,char transfer_type,char Transfer_Time[])
{
?? ?char Time1[40];//聲明原時(shí)間
?? ?struct tm* timeinfo;
?? ?
?? ?if(transfer_type=='t')//如果 transfer_type 為 x,則返回的時(shí)間格式為易閱讀的?
?? ?{
?? ??? ?timeinfo=localtime(&Timestamp);
?? ??? ?strftime(Time1,sizeof(Time1),"%Y年%m月%d日%H時(shí)%M分%S秒",timeinfo);
?? ?}
?? ?
?? ?if(transfer_type=='n')// //如果 transfer_type 為 n,則返回的時(shí)間格式為純數(shù)字?
?? ?{
?? ??? ?timeinfo=localtime(&Timestamp);
?? ??? ?strftime(Time1,sizeof(Time1),"%Y%m%d%H%M%S",timeinfo);
?? ?}
?? ?strcpy(Transfer_Time,Time1);//將轉(zhuǎn)換后的時(shí)間格式復(fù)制到傳遞過來的數(shù)組當(dāng)中去?
}

void SetConsolSize(int x,int y)// 設(shè)置緩沖區(qū)的大小?
{
?? ?SMALL_RECT winPon={0,0,25,10};
?? ?HANDLE con=GetStdHandle(STD_OUTPUT_HANDLE);
?? ?COORD buf={x,y};// 緩沖區(qū)長(zhǎng)10000,高25?
?? ?SetConsoleScreenBufferSize(con,buf);
}

每個(gè)功能的測(cè)試:

1、錄入選項(xiàng)

2、刪除選項(xiàng)

3、查詢選項(xiàng)

4、修改選項(xiàng)

5、 預(yù)覽全部信息

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

相關(guān)文章

  • C++用boost.signal實(shí)現(xiàn)多播委托

    C++用boost.signal實(shí)現(xiàn)多播委托

    這篇文章介紹了C++用boost.signal實(shí)現(xiàn)多播委托的方法,文中通過示例代碼介紹的非常詳細(xì)。對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下
    2022-06-06
  • VC取得任務(wù)欄高度的方法

    VC取得任務(wù)欄高度的方法

    這篇文章主要介紹了VC取得任務(wù)欄高度的方法,需要的朋友可以參考下
    2014-07-07
  • c++核心編程之函數(shù)的重載

    c++核心編程之函數(shù)的重載

    這篇文章主要介紹了c++核心編程之函數(shù)的重載,函數(shù)可以重復(fù)使用,提高了復(fù)用性,但前提是必須在一個(gè)作用域并且函數(shù)名稱相同,下面附代碼詳細(xì)介紹,需要的小伙伴可以參考一下
    2022-03-03
  • C++11 模板參數(shù)的“右值引用”是轉(zhuǎn)發(fā)引用嗎

    C++11 模板參數(shù)的“右值引用”是轉(zhuǎn)發(fā)引用嗎

    這篇文章主要介紹了C++11 模板參數(shù)的“右值引用”是轉(zhuǎn)發(fā)引用嗎,文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧
    2020-05-05
  • C語(yǔ)言內(nèi)存的動(dòng)態(tài)分配比較malloc和realloc的區(qū)別

    C語(yǔ)言內(nèi)存的動(dòng)態(tài)分配比較malloc和realloc的區(qū)別

    這篇文章主要介紹了C語(yǔ)言內(nèi)存的動(dòng)態(tài)分配比較malloc和realloc的區(qū)別,本篇文章通過簡(jiǎn)要的案例,講解了該項(xiàng)技術(shù)的了解與使用,以下就是本文的詳細(xì)內(nèi)容,需要的朋友可以參考下
    2021-07-07
  • 詳解Qt中QStackedWidget控件的使用

    詳解Qt中QStackedWidget控件的使用

    這篇文章主要為大家詳細(xì)介紹了Qt中QStackedWidget控件的具體使用,文中的示例代碼講解詳細(xì),具有一定的借鑒價(jià)值,需要的可以參考一下
    2023-02-02
  • C++使用UDP通訊的實(shí)現(xiàn)示例

    C++使用UDP通訊的實(shí)現(xiàn)示例

    本文實(shí)現(xiàn)對(duì)C++使用UDP做了簡(jiǎn)單封裝,實(shí)現(xiàn)通訊,包括服務(wù)端和客戶端,文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧
    2023-12-12
  • C語(yǔ)言中變量與其內(nèi)存地址對(duì)應(yīng)的入門知識(shí)簡(jiǎn)單講解

    C語(yǔ)言中變量與其內(nèi)存地址對(duì)應(yīng)的入門知識(shí)簡(jiǎn)單講解

    這篇文章主要介紹了C語(yǔ)言中變量與其內(nèi)存地址對(duì)應(yīng)的入門知識(shí)簡(jiǎn)單講解,同時(shí)這也是掌握指針部分知識(shí)的基礎(chǔ),需要的朋友可以參考下
    2015-12-12
  • C++二叉樹實(shí)現(xiàn)詞頻分析功能

    C++二叉樹實(shí)現(xiàn)詞頻分析功能

    這篇文章主要為大家詳細(xì)介紹了C++二叉樹實(shí)現(xiàn)詞頻分析功能,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2017-12-12
  • C++動(dòng)態(tài)規(guī)劃計(jì)算最大子數(shù)組

    C++動(dòng)態(tài)規(guī)劃計(jì)算最大子數(shù)組

    所謂最大子數(shù)組就是連續(xù)的若干數(shù)組元素,如果其和是最大的,那么這個(gè)子數(shù)組就稱為該數(shù)組的最大子數(shù)組
    2022-06-06

最新評(píng)論