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

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

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

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

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

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

代碼:

/*
?* 電話訂餐處理系統(tǒng)?
?* 第八組C語言課程設計
?* 佛祖保佑,永無 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(); // 聲明預覽全部訂餐信息的函數(shù),記得加參數(shù)?
void ColorChange(int); // 聲明修改背景&字體顏色的函數(shù)?
void Cutline(); // 聲明分界線函數(shù)?
int Unix2Time();// 聲明時間戳轉換為普通時間的函數(shù)
void Time2Unix(time_t,char,char []);// 聲明普通時間轉換為時間戳的函數(shù) ?
void GetAllInfo();//獲取所有顧客的全部信息?
void SetConsolSize(int x,int y);//定義修改緩沖區(qū)大小的函數(shù)?
static int n=0;// 定義一個全局變量n用來獲取總共有多少顧客信息?


// 聲明一個顧客的結構體變量?
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");// 調用cmd命令修改窗口大小?
?? ?SetConsolSize(150,999);//修改緩沖區(qū)的大小?
?? ?printf("歡迎使用電話訂餐系統(tǒng)!\n");
?? ?printf("請輸入菜單前標號以執(zhí)行操作\n");
?? ?PrintMenu:
?? ?PrintMenu();
?? ?//ColorChange(5);
?? ?GetChoice:
?? ?fflush(stdin);?
?? ?choice=-1;//重置choice的值?
?? ?printf("\n請輸入你的選項 >");
?? ?scanf("%d",&choice);?
?? ?fflush(stdin); // 清空緩沖區(qū),防止scanf接受多余的回車導致死循環(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("輸入錯誤!請重新輸入!\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. 預覽訂餐信息┃\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("請輸入顧客姓名 >");
?? ?scanf("%[^\n]s",custmp.name);
?? ?fflush(stdin); //清空緩沖區(qū)?
?? ?printf("請輸入顧客電話 >");
?? ?scanf("%s",custmp.phoneNumber);
?? ?fflush(stdin);?
?? ?printf("請輸入顧客的預定時間 >");
?? ?scanf("%[^\n]s",custmp.booktime);
?? ?fflush(stdin);?
?? ?printf("請輸入用餐的人數(shù) >");
?? ?scanf("%d",&custmp.num);
?? ?fflush(stdin);?
?? ?printf("請輸入顧客的備注 >");
?? ?scanf("%[^\n]s",custmp.other);
?? ?fflush(stdin);?
?? ??
?? ?// 生成以時間為編號的顧客編號?
?? ?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編號\t\t姓名\t\t電話\t\t用餐人數(shù) ? 預定日期\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.結束修改 ? ?┃\n");?
?? ?printf("┃1.姓名 ? ? ? ?┃\n");
?? ?printf("┃2.電話 ? ? ? ?┃\n");
?? ?printf("┃3.用餐人數(shù) ? ?┃\n");
?? ?printf("┃4.預定日期 ? ?┃\n");
?? ?printf("┃5.備注 ? ? ? ?┃\n");
?? ?printf("┃6.重新選擇顧客┃\n");
?? ?printf("┗━━━━━━━━━━━━━━┛\n");
?? ?GetModifiedInfo:
?? ?Cutline();
?? ?printf("\n請選擇你要修改的項目 >");
?? ?scanf("%d",&choice);
?? ?//菜單分支?
?? ?switch(choice)
?? ?{
?? ??? ?
?? ??? ?case 1:{
?? ??? ??? ?printf("請輸入更正后的內容 >");
?? ??? ??? ?scanf("%s",customer[no].name);
?? ??? ??? ?goto WriteCustData;?
?? ??? ?}break;
?? ??? ?
?? ??? ?case 2:{
?? ??? ??? ?printf("請輸入更正后的內容 >");
?? ??? ??? ?scanf("%s",customer[no].phoneNumber);?
?? ??? ??? ?goto WriteCustData;
?? ??? ?}break;
?? ??? ?
?? ??? ?case 3:{
?? ??? ??? ?printf("請輸入更正后的內容 >");
?? ??? ??? ?scanf("%d",&customer[no].num);?
?? ??? ??? ?goto WriteCustData;
?? ??? ?}break;
?? ??? ?
?? ??? ?case 4:{
?? ??? ??? ?printf("請輸入更正后的內容 >");
?? ??? ??? ?scanf("%s",customer[no].booktime);?
?? ??? ??? ?goto WriteCustData;
?? ??? ?}break;
?? ??? ?
?? ??? ?case 5:{
?? ??? ??? ?printf("請輸入更正后的內容 >");
?? ??? ??? ?scanf("%s",customer[no].other);?
?? ??? ??? ?goto WriteCustData;
?? ??? ?}break;
?? ??? ?
?? ??? ?case 6:{?
?? ??? ??? ?no=searchdata();
?? ??? ??? ?goto printmenu;
?? ??? ?}
?? ??? ?
?? ??? ?case 0:return;
?? ??? ?
?? ??? ?default:{
?? ??? ??? ?ColorChange(4);
?? ??? ??? ?printf("輸入錯誤!");
?? ??? ??? ?ColorChange(-1);
?? ??? ??? ?goto GetModifiedInfo;
?? ??? ?}break;
?? ?}?
?? ?
?? ?//將要修改的顧客信息定點在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編號\t\t姓名\t\t電話\t\t用餐人數(shù) ? 預定日期\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是否刪除這個用戶的數(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ù)所給的條件尋找對應的顧客i?
{
?? ?GetAllInfo();
?? ?char target[100];
?? ?printf("\n請輸入用戶任意單項信息 >");
?? ?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編號\t\t姓名\t\t電話\t\t用餐人數(shù) ? 預定日期\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編號\t\t姓名\t\t電話\t\t用餐人數(shù) ? 預定日期\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ù) */?
void Time2Unix(time_t Timestamp,char transfer_type,char Transfer_Time[])
{
?? ?char Time1[40];//聲明原時間
?? ?struct tm* timeinfo;
?? ?
?? ?if(transfer_type=='t')//如果 transfer_type 為 x,則返回的時間格式為易閱讀的?
?? ?{
?? ??? ?timeinfo=localtime(&Timestamp);
?? ??? ?strftime(Time1,sizeof(Time1),"%Y年%m月%d日%H時%M分%S秒",timeinfo);
?? ?}
?? ?
?? ?if(transfer_type=='n')// //如果 transfer_type 為 n,則返回的時間格式為純數(shù)字?
?? ?{
?? ??? ?timeinfo=localtime(&Timestamp);
?? ??? ?strftime(Time1,sizeof(Time1),"%Y%m%d%H%M%S",timeinfo);
?? ?}
?? ?strcpy(Transfer_Time,Time1);//將轉換后的時間格式復制到傳遞過來的數(shù)組當中去?
}

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

每個功能的測試:

1、錄入選項

2、刪除選項

3、查詢選項

4、修改選項

5、 預覽全部信息

以上就是本文的全部內容,希望對大家的學習有所幫助,也希望大家多多支持腳本之家。

相關文章

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

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

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

    VC取得任務欄高度的方法

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

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

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

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

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

    C語言內存的動態(tài)分配比較malloc和realloc的區(qū)別

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

    詳解Qt中QStackedWidget控件的使用

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

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

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

    C語言中變量與其內存地址對應的入門知識簡單講解

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

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

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

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

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

最新評論