A. c語言設計案例張傳學P196編寫結構體鏈表
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
typedefstructNode
{
charname[20];
charphone[20];
charcell[20];
charmail[50];
structNode*next;
}Node;
voidshow(Node*h)
{
Node*p;
for(p=h;p!=NULL;p=p->next)
{
printf("%s,%s,%s,%s ",p->name,p->phone,p->cell,p->mail);
}
}
Node*Insert(Node*h)
{
Node*p=(Node*)malloc(sizeof(Node));
scanf("%s%s%s%s",p->name,p->phone,p->cell,p->mail);
if(h==NULL)
{
p->next=NULL;
}
else
{
p->next=h;
}
returnp;
}
Node*find(Node*h,char*name)
{
Node*r=NULL;
while(h)
{
if(strcmp(h->name,name)==0)
{
r=h;
break;
}
h=h->next;
}
returnr;
}
voiddestroy(Node*h)
{
Node*p;
while(h)
{
p=h;
h=h->next;
free(p);
}
}
intmain()
{
Node*h=NULL;
intc=-1;
do
{
printf("chooseafunction: ");
printf("1:insertanewnode ");
printf("2:printallnodes ");
printf("3:findanode ");
printf("4:exit ");
scanf("%d",&c);
switch(c)
{
case1:
h=Insert(h);
break;
case2:
show(h);
break;
case3:
{
Node*r;
charname[20];
scanf("%s",name);
r=find(h,name);
if(r)
printf("%s,%s,%s,%s ",r->name,r->phone,r->cell,r->mail);
elseprintf("notfind ");
break;
}
case4:
break;
default:
printf("unknowcommand ");
break;
}
}while(c!=4);
destroy(h);
return0;
}
B. 請問C語言課程設計報告摘要怎麼寫,是指什麼啊,舉個例子吧
摘要:又稱概要、內容提要。摘要是以提供文獻內容梗概為目的,不加評論和補充解釋,簡明、確切地記述文獻重要內容的短文。其基本要素包括研究目的、方法、結果和結論。具體地講就是研究工作的主要對象和范圍,採用的手段和方法,得出的結果和重要的結論,有時也包括具有情報價值的其它重要的信息。
C語言課程設計,應該主要根據你的設計內容,簡要地提煉出設計的背景,功能,意義等。最後給出關鍵字。下面是正文。
例如:
摘要(標題居中)
近年來隨著計算機在社會領域的不斷發展,程序設計 。。。。。C語言。。。。(這里講你做的東西的背景。)
本課程設計完成了什麼。。。。(功能)
其意義是。。。。(意義)
關鍵詞: C語言,其他
C. c語言程序綜合課程設計一般案例有哪些急求……
如果有一定的基礎的話,一樓的說的不錯先學學「數據結構」的相關知識!演算法在程序設計中有很「重要」的作用……其實學c主要是學編程的思想!你要是就一個個的死學案例,也只是會設計類似的東西!不會有創新,甚至有的地方會根本搞不明白。不知道你基礎怎麼樣?如果不是很好,就復習《數據結構吧》清華出版社那本嚴蔚敏的數據結構(C語言版)。比較容易理解,最好還是要看些英文的原版數據結構的書。
當然如果你數據結構學得很好的話,比如你就是想通過一些案例的開發,來增強自己的實戰能力,你可以深入學習你說的那本書,其實你只要仔細看一下就會發現,其實案例設計的教程中文版的根本沒什麼創新都停留在以下幾個「經典問題」上,不同的版本也沒什麼太多的區別就是重印一下而已!這本書作為對編程基本功的訓練不錯!
案例一:貪吃蛇游戲
案例二:計算器
案例三:黑白棋游戲
案例四:迷宮問題
案例五:掃地雷游戲
案例六:速算24
案例七:數據結構CAI系統
案例八:進度調度
案例九:存儲管理分區分配演算法
案例十:通訊錄
案例十一:學生成績管理
案例十二:工資管理
案例十三:圖書借閱管理
案例十四:教師工作量計算
相關下載地址:
D. C語言設計案例張傳學P82編寫如圖123聖誕樹
為了更方便的設計聖誕樹的形狀,我用的是設計遞歸函數的方法。程序如下:
#include <stdio.h>
#include <math.h>
void shu(int n)
{
int i;
for (i = 1; i <= 6 - n; i++)
{
printf(" ");
}
for (i = 1; i <= 2 * n - 1;i++)
{
printf("*");
}
printf(" ");
if (n != 6)
shu(n + 1);
}
void gen(int n)
{
int i;
for (i = 1; i <= n; i++)
{
printf(" ***** ");
}
}
void main()
{
shu(1);
shu(2);
gen(5);
}
模擬結果如圖1。
E. c語言課程設計實例
#include<iostream.h>
void main()
{
char a[12][9]={{'j','a','n','u','a','r','y'},{'F','e','b','r','u','a','r','y'},{'m','a','r','c','h'},{'a','p','r','i','l'},{'m','a','y'},{'j','u','n','e'},{'j','u','l','y'},{'a','u','g','u','s','t'}, {'s','e','p','t','e','m','b','e','r'},{'o','c','t','o','b','e','r'},{'n','o','v','e','m','b','e','r'},{'D','e','c','e','m','b','e','r'}},(*p)[9]=a;
int b;
cout<<"輸入月份:";
cin>>b;
cout<<"該月的英文單詞是:"<<*(p+b-1)<<endl;
}
程序寫到這分上,我都想自殺了.......用字元串應該會簡單些,可是我沒想好..只能這樣了..
F. 與C語言課程設計案例精編的案例十一有類似的程序沒
應你的要求改下
include<bios.h>
#include<dos.h> /*頭文件*/
#include<conio.h>
#include<ctype.h>
#include<process.h>
#include<slib.h>
#include<sio.h>
#include<sing.h>
#define NULL 0
#define ESC 0x001b /* 退出 */
#define F1 0x3b00 /* 查看幫助信息,調用HelpMassage()函數 */
#define F2 0x3c00 /*輸入學生成績*/
#define F3 0x3d00 /*按學號查找*/
#define F4 0x3e00 /*按姓名查找*/
#define F5 0x3f00 /*列出所有學生成績*/
#define F6 0x4000 /*統計*/
suct stuType /*定義結構體變數*/
{
char NO[11]; /*學號長度為10*/
char XM[10];
float CJ[4]; /*包含4門成績*/
};
/*-------------2-------------*/
int JY_NO(char *stu_num,FILE *fp) /*檢驗學號的正確性*/
{ suct stuType stud;
int NO;
char *p=stu_num;
if(scmp(stu_num,"#")==0) return 1; /*若輸入"#"返回真值,不再循環輸入*/
while(*p!='\0') /*學號必須是數字,否則返回重新輸入*/
{ NO=(int)*p;
if(NO<48||NO>57)
{ puts("\t\t\t非法學號!請重新輸入!\n");
return 0;
}
else p ; /*指針加1*/
}
if(slen(stu_num)!=10) /*若學號長度不為10,則返回重新輸入*/
{ puts("\t\t\t學號長度不對!\n");
return 0;
}
if(getchar()!='\n') /*若學號後面的字元不是回車符,則學號長度大於10*/
{ printf("\t\t\t學號長度大於10個!請重新輸入!\n");
do{}while(getchar()!='\n'); /*用getchar接收多餘的字元*/
return 0;
}
else
{
rewind(fp); /*使文件指針指向頭*/
while(!feof(fp)) /*若文件指針未到結尾,就繼續執行下面的循環,feof遇到文件結束符返回非零值,否則返回0*/
{ fread(&stud,sizeof(suct stuType),1,fp); /*讀取一定長度的數據*/
if(scmp(stu_num,stud.NO)==0) /*學號的唯一性*/
{ printf("\t\t\t學號重復,請重新輸入!\n");
printf("\t\t\t該學生成績如下:\n");
printf("\t\t\t語文:%.1f\n",stud.CJ[0]);
printf("\t\t\t數學:%.1f\n",stud.CJ[1]);
printf("\t\t\t英語:%.1f\n",stud.CJ[2]);
printf("\t\t\t總評:%.1f\n",stud.CJ[3]);
return 0;
}
}
}
return 1;
}
/*-------------3-------------*/
int JY_NO2(char *stu_num) /*檢驗學號*/
{ int NO;
char *p=stu_num;
if(scmp(stu_num,"#")==0)return 1; /*若輸入「#」,則返回真值結束*/
if(slen(stu_num)!=10) /*學號長度為10*/
{ puts("\t\t\t學號長度不對!\n");
return 0;
}
while(*p!='\0') /*學號必須用數字,若包含有字母,或其它字元則返回假值重新輸入*/
{ NO=(int)*p;
if(NO<48||NO>57)
{ puts("\t\t\t非法學號!請重新輸入!\n");
return 0;
}
else p ; /*指針加1*/
}
if(getchar()!='\n') /*檢驗學號長度是否大於10,並把多餘的字元去掉*/
{ printf("\t\t\t學號長度大於10個!請重新輸入!\n");
do{}while(getchar()!='\n');
return 0;
}
return 1;
}
/*-------------4-------------*/
int JY_XM(char *stu_XM) /*檢驗姓名*/
{ int PD;
char *p;
p=stu_XM;
while(*p!='\0') /*姓名只能用中文*/
{
PD=(int)*p;
if(PD>0)
{ puts("\t\t\t姓名只能用中文,請重新輸入!\n");
return 0;
}
else p ; /*使指針加1,指向下一漢字*/
}
if(getchar()!='\n') /*姓名長度不得大於5個*/
{ printf("\t\t\t姓名長度大於5個!請重新輸入!\n");
do{}while(getchar()!='\n');
return 0;
}
return 1; /*字元串全為漢字返回真*/
}
/*-------------5-------------*/
int JY_CJ(float stu_CJ) /*學生成績只能在0~100之間*/
{
if(stu_CJ<0||stu_CJ>100)
{ printf("\t\t\t輸入錯誤,成績只能在0~100之間!\n");
return 0;
}
return 1;
}
/*-------------6-------------*/
void CreatFile() /*輸入文件*/
{ FILE *fp;
suct stuType stu,stu0={"","",}; /*對stu0先賦值*/
fp=fopen("stu.dat","wb "); /*打開或創建一個二進制文件,打開時將原來的內容刪除*/
if(fp==NULL)
{ printf("\t\t\t文件打開失敗!\n\t\t\t按任意鍵返回...");
getch();
return;
}
else
{ while(1)
{ stu=stu0;
do{ printf("\n\t\t\t請輸入學號:"); /*輸入學號並檢驗其正確性*/
scanf("s",stu.NO);
}while(!JY_NO(stu.NO,fp));
if(scmp(stu.NO,"#")==0)break;
do{ printf("\n\t\t\t請輸入姓名:"); /*輸入姓名並檢驗其正確性*/
scanf("s",stu.XM);
}while(!JY_XM(stu.XM));
do{ printf("\n\t\t\t請輸入語文成績:"); /*輸入成績並檢驗其正確性*/
scanf("%f",&stu.CJ[0]);
}while(!JY_CJ(stu.CJ[0]));
do{ printf(
"\n\t\t\t請輸入數學成績:"); /*同上*/
scanf("%f",&stu.CJ[1]);
}while(!JY_CJ(stu.CJ[1]));
do{ printf("\n\t\t\t請輸入英語成績:");
scanf("%f",&stu.CJ[2]);
}while(!JY_CJ(stu.CJ[2]));
do{ printf("\n\t\t\t請輸入總評成績:");
scanf("%f",&stu.CJ[3]);
}while(!JY_CJ(stu.CJ[3]));
fwrite(&stu,sizeof(suct stuType),1,fp); /*寫文件*/
}
}
fclose(fp); /*關閉文件*/
}
/*-------------7-------------*/
void Search_Xuehao() /*按學號查詢*/
{ FILE *fp;
int flag;
suct stuType stu,stud;
fp=fopen("stu.dat","rb");
if(fp==NULL) /*若文件打不開則輸出下面的信息*/
{ printf("\t\t\t文件打開失敗!\n\t\t\t按任意鍵返回...");
getch();
return;
}
else
{ do{ puts("\n\t\t\t輸入「#」結束查詢");
do{ printf("\t\t\t請輸入要查詢的學號:");
scanf("s",stu.NO);
}while(!JY_NO2(stu.NO));
if(scmp(stu.NO,"#")==0)break; /*若輸入「#」則結束循環*/
flag=0;
rewind(fp);
while(fread(&stud,sizeof(suct stuType),1,fp)) /*檢查文件指針結束*/
{ if(scmp(stu.NO,stud.NO)==0) /*比較學號*/
{ puts("\t\t\t該學生成績如下:");
printf("\t\t\t學號:%s\n",stud.NO);
printf("\t\t\t姓名:%s\n",stud.XM);
printf("\t\t\t語文:%.1f\n",stud.CJ[0]);
printf("\t\t\t數學:%.1f\n",stud.CJ[1]);
printf("\t\t\t英語:%.1f\n",stud.CJ[2]);
printf("\t\t\t總評:%.1f\n",stud.CJ[3]);
flag=1; /*記錄學號是否查到*/
}
}
if(flag==0)puts("\t\t\t無此學號!");
}while(scmp(stu.NO,"#")!=0);
}
fclose(fp); /*關閉文件*/
}
/*-------------8-------------*/
void Search_Xingming() /*按姓名查找*/
{ FILE *fp;
int flag=0;
suct stuType stu,stud;
fp=fopen("stu.dat","rb");
if(fp==NULL)
{ printf("\t\t\t文件打開失敗!\n\t\t\t按任意鍵返回...");
getch();
return;
}
else
{ do{
do{ printf("\t\t\t請輸入要查詢的學生姓名:");
scanf("s",stu.XM);
}while(!JY_XM(stu.XM));
rewind(fp); /*文件指針指向頭*/
while(fread(&stud,sizeof(suct stuType),1,fp))
{ if(scmp(stu.XM,stud.XM)==0) /*比較姓名是否相同*/
{ puts("\t\t\t該學生姓名如下:");
printf("\t\t\t學號:%s\n",stud.NO);
printf("\t\t\t姓名:%s\n",stud.XM);
printf("\t\t\t語文:%.1f\n",stud.CJ[0]);
printf("\t\t\t數學:%.1f\n",stud.CJ[1]);
printf("\t\t\t英語:%.1f\n",stud.CJ[2]);
printf("\t\t\t總評:%.1f\n",stud.CJ[3]);
flag=1; /*記錄姓名是否被查到*/
}
}
if(flag==0)puts("\n\t\t\t無此學生!");
puts("\t\t\t是否繼續(y--繼續,其他返回)?");
}while(getch()=='y');
}
fclose(fp);
/* puts("\t\t\t請按任意鍵繼續...");*/
/* getch();*/
}
/*-------------9-------------*/
int ListFile(void) /*輸出文件,列出所有學生成績*/
{ FILE *fp;
int REC=0; /*記錄學生人數*/
suct stuType stu;
fp=fopen("stu.dat","rb");
if(fp==NULL)
{ printf("\t\t\t文件打開失敗!\n\t\t\t按任意鍵返回...");
getch();
return 1;
}
else{ printf("\t\t\t學生成績如下:\n");
printf("\t\t\t學號\t\t姓名\t語文\t數學\t英語\t總評\n");
rewind(fp);
while(fread(&stu,sizeof(suct stuType),1,fp))
{ /*每讀取一個長度的數據就輸出*/
printf("\t\t\t%s",stu.NO);
printf("\t%s",stu.XM);
printf("\t%.1f",stu.CJ[0]);
printf("\t%.1f",stu.CJ[1]);
printf("\t%.1f",stu.CJ[2]);
printf("\t%.1f",stu.CJ[3]);
printf("\n");
REC ;
if(REC ==0) /*每輸出20個學生成績,停一下*/
{ printf("\t\t\t請按任意鍵繼續...\n");
getch();
}
}
}
fclose(fp); /*關閉文件*/
printf("\t\t\t請按任意鍵繼續...");
getch();
}
/*-------------10-------------*/
void Statistics() /*統計及格和優秀人數*/
{ FILE *fp;
int REC=0,pass[4]={0},good[4]={0}; /*REC--記錄個數,即人數,pass--及格人數,good--優秀人數*/
float highest[4]={0},score[4]={0}; /*highest--最高分,score--總分*/
suct stuType stu;
fp=fopen("stu.dat","rb");
if(fp==NULL)
{ printf("\t\t\t文件打開失敗!\n\t\t\t按任意鍵返回...");
getch();
return;
}
else { rewind(fp);
while(fread(&stu,sizeof(suct stuType),1,fp))
{ REC ;
score[0]=score[0] stu.CJ[0]; /*語文*/
if(stu.CJ[0]>=60)pass[0] ;
if(stu.CJ[0]>=80)good[0] ;
if(highest[0]<stu.CJ[0])highest[0]=stu.CJ[0];
score[1]=score[1] stu.CJ[1]; /*數學*/
if(stu.CJ[1]>=60)pass[1] ;
if(stu.CJ[1]>=80)good[1] ;
if(highest[1]<stu.CJ[1])highest[1]=stu.CJ[1];
score[2]=score[2] stu.CJ[2]; /*英語*/
if(stu.CJ[2]>=60)pass[2] ;
if(stu.CJ[2]>=80)good[2] ;
if(highest[2]<stu.CJ[2])highest[2]=stu.CJ[2];
score[3]=score[3] stu.CJ[3]; /*總評*/
if(stu.CJ[3]>=60)pass[3] ;
if(stu.CJ[3]>=80)good[3] ;
if(highest[3]<stu.CJ[3])highest[3]=stu.CJ[3];
}
if(REC==0) /*可以防止記錄為0是REC作除數而造成的錯誤*/
{ printf("\t\t\t未輸入學生記錄!按任意鍵返回...");
getch();
return;
}
else{
printf("\t\t\t\t 語文\t 數學\t 英語\t 總評\n"); /*輸出統計信息*/
printf("\t\t\t平均分: %.1f\t %.1f\t %.1f\t %.1f\n",score[0]/REC,score[1]/REC,score[2]/REC,score[3]/REC);
printf("\t\t\t最高分: %.1f\t %.1f\t %.1f\t %.1f\n",highest[0],highest[1],highest[2],highest[3]);
printf("\t\t\t優秀人數:%d\t %d\t %d\t %d\n",good[0],good[1],good[2],good[3]);
printf("\t\t\t及格人數:%d\t %d\t %d\t %d\n",pass[0],pass[1],pass[2],pass[3]);
}
}
fclose(fp);
printf("\n\t\t\t請按任意鍵繼續...");
getch();
}
/*-------------11-------------*/
void HelpMessage()
{ clrscr();
printf("\n\n\n\n\n 此系統是應老師所布置的作業編制而成,該系統具有存貯學生數據,按學號、姓名查詢,列出學生成績和統計功能。\n \n 使用方法:系統輸入數據後,將在當前目錄中建立一個名為stu.dat文件,用於保存輸入的數據。學號輸入只能用數字輸入,並且學號只能是10位。姓名輸入符合中國人的姓名,只能用中文,且最長為5個漢字。\n 此程序在Turbo C2.0下運行通過\n\n 由於是初學者,水平有限此系統還有許多不夠完整和嚴密性,敬請指正!");
getch();
}
/*-------------12-------------*/
int GetKey(void) /*此函數返回一個按鍵的數值*/
{ int key;
key=bioskey(0); /*bioskey為調用BIOS鍵盤介面*/
if(key<<8) /*位移*/
{
key=key&0x00ff;
}
return key; /*返回按鍵*/
}
/*-------------13-------------*/
void main()
{ int key;
suct date d; /*定義時間結構體*/
geate(&d); /*讀取系統日期並把它放到結構體d中*/
clrscr(); /*清除屏幕*/
printf("\n\n\n\n\n");
printf("\t\t\t****************************\n"); /*版本信息*/
printf("\t\t\t 學生成績管理系統1.0 \n");
printf("\t\t\t****************************\n");
printf("\t\t\t 製作群: 404 1工作室 \n");
printf("\t\t\t 指導老師:--- \n");
printf("\t\t\t 製作時間:2004年5月 \n");
printf("\t\t\t****************************\n");
printf("\t\t\t請按任意鍵繼續...");
/*while(!kbhit());*/
getch(); /*從鍵盤讀取一個字元,但不顯示於屏幕*/
system("cls"); /*調用DOS的清屏函數,TC中可用clrscr代替*/
while(1) /*主菜單*/
{
printf("\n\n\n\n\n");
printf("\t\t\t************************************\n");
printf("\t\t\t**\tF1 --幫助 **\n");
printf("\t\t\t**\tF2 --輸入數據並存入文件 **\n");
printf("\t\t\t**\tF3 --根據學號查詢成績 **\n");
printf("\t\t\t**\tF4 --根據姓名查詢成績 **\n");
printf("\t\t\t**\tF5 --輸出文件內容 **\n");
printf("\t\t\t**\tF6 --統計及格和優秀人數 **\n");
printf("\t\t\t**\tESC--退出系統 **\n");
printf("\t\t\t************************************\n");
printf("\n\t\t\t請輸入選項\t\t%d年%d月%d日\n\n",d.da_year,d.da_mon,d.da_day); /*提示信息,並顯示當前系統日期*/
key=GetKey(); /*調用自定義函數,讀取一個鍵*/
switch(key)
{
case F1: HelpMessage(); break;
case F2: CreatFile(); break;
case F3: Search_Xuehao(); break;
case F4: Search_Xingming();break;
case F5: ListFile(); break;
case F6: Statistics(); break;
case ESC:exit(1); break;
/*default: puts("\t\t\t輸入錯誤選項!");
printf("\t\t\t按任意鍵返回...");
getch();*/
}
clrscr(); /*每執行完一項功能後,自動清屏*/
}
}
CJ[1]>=60)pass[1] ;
if(stu.CJ[1]>=80)good[1] ;
if(highest[1]<stu.CJ[1])highest[1]=stu.CJ[1];
score[2]=score[2] stu.CJ[2]; /*英語*/
if(stu.CJ[2]>=60)pass[2] ;
if(stu.CJ[2]>=80)good[2] ;
if(highest[2]<stu.CJ[2])highest[2]=stu.CJ[2];
score[3]=score[3] stu.CJ[3]; /*總評*/
if(stu.CJ[3]>=60)pass[3] ;
if(stu.CJ[3]>=80)good[3] ;
if(highest[3]<stu.CJ[3])highest[3]=stu.CJ[3];
}
if(REC==0) /*可以防止記錄為0是REC作除數而造成的錯誤*/
{ printf("\t\t\t未輸入學生記錄!按任意鍵返回...");
getch();
return;
}
else{
printf("\t\t\t\t 語文\t 數學\t 英語\t 總評\n"); /*輸出統計信息*/
printf("\t\t\t平均分: %.1f\t %.1f\t %.1f\t %.1f\n",score[0]/REC,score[1]/REC,score[2]/REC,score[3]/REC);
printf("\t\t\t最高分: %.1f\t %.1f\t %.1f\t %.1f\n",highest[0],highest[1],highest[2],highest[3]);
printf("\t\t\t優秀人數:%d\t %d\t %d\t %d\n",good[0],good[1],good[2],good[3]);
printf("\t\t\t及格人數:%d\t %d\t %d\t %d\n",pass[0],pass[1],pass[2],pass[3]);
}
}
fclose(fp);
printf("\n\t\t\t請按任意鍵繼續...");
getch();
}
/*-------------11-------------*/
void HelpMessage()
{ clrscr();
printf("\n\n\n\n\n 此系統是應老師所布置的作業編制而成,該系統具有存貯學生數據,按學號、姓名查詢,列出學生成績和統計功能。\n \n 使用方法:系統輸入數據後,將在當前目錄中建立一個名為stu.dat文件,用於保存輸入的數據。學號輸入只能用數字輸入,並且學號只能是10位。姓名輸入符合中國人的姓名,只能用中文,且最長為5個漢字。\n 此程序在Turbo C2.0下運行通過\n\n 由於是初學者,水平有限此系統還有許多不夠完整和嚴密性,敬請指正!");
getch();
}
/*-------------12-------------*/
int GetKey(void) /*此函數返回一個按鍵的數值*/
{ int key;
key=bioskey(0); /*bioskey為調用BIOS鍵盤介面*/
if(key<<8) /*位移*/
{
key=key&0x00ff;
}
return key; /*返回按鍵*/
}
/*-------------13-------------*/
void main()
{ int key;
suct date d; /*定義時間結構體*/
geate(&d); /*讀取系統日期並把它放到結構體d中*/
clrscr(); /*清除屏幕*/
printf("\n\n\n\n\n");
printf("\t\t\t****************************\n"); /*版本信息*/
printf("\t\t\t 學生成績管理系統1.0 \n");
printf("\t\t\t****************************\n");
printf("\t\t\t 製作群: 404 1工作室 \n");
printf("\t\t\t 指導老師:--- \n");
printf("\t\t\t 製作時間:2004年5月 \n");
printf("\t\t\t****************************\n");
printf("\t\t\t請按任意鍵繼續...");
/*while(!kbhit());*/
getch(); /*從鍵盤讀取一個字元,但不顯示於屏幕*/
system("cls"); /*調用DOS的清屏函數,TC中可用clrscr代替*/
while(1) /*主菜單*/
{
printf("\n\n\n\n\n");
printf("\t\t\t************************************\n");
printf("\t\t\t**\tF1 --幫助 **\n");
printf("\t\t\t**\tF2 --輸入數據並存入文件 **\n");
printf("\t\t\t**\tF3 --根據學號查詢成績 **\n");
printf("\t\t\t**\tF4 --根據姓名查詢成績 **\n");
printf("\t\t\t**\tF5 --輸出文件內容 **\n");
printf("\t\t\t**\tF6 --統計及格和優秀人數 **\n");
printf("\t\t\t**\tESC--退出系統 **\n");
printf("\t\t\t************************************\n");
printf("\n\t\t\t請輸入選項\t\t%d年%d月%d日\n\n",d.da_year,d.da_mon,d.da_day); /*提示信息,並顯示當前系統日期*/
key=GetKey(); /*調用自定義函數,讀取一個鍵*/
switch(key)
{
case F1: HelpMessage(); break;
case F2: CreatFile(); break;
case F3: Search_Xuehao(); break;
case F4: Search_Xingming();break;
case F5: ListFile(); break;
case F6: Statistics(); break;
case ESC:exit(1); break;
/*default: puts("\t\t\t輸入錯誤選項!");
printf("\t\t\t按任意鍵返回...");
getch();*/
}
clrscr(); /*每執行完一項功能後,自動清屏*/
}
}
G. c程序課程設計實例
第一題:
#include <iostream>
using namespace std;
void main()
{ int i, j, k, count=0;
for( i=1; i<=9; i++)
for( j=0; j<=9; j++)
if ( i==j )
continue;
else
for( k=0; k<=9; k++)
if ( k!=i&&k!=j)
{count++;
cout<<i<<j<<k<<ends;
}
cout<<endl;
cout<<"所有這樣的三位數個數有:"<<count<<" 個"<<endl;
}
第二題
#include <iostream>
using namespace std;
int fun(char*s,int n)
{
int flag=1;
for(int i=0;i<n;i++)//比較前n個字元是否為*
if(s[i]!='*')
{
flag=0;
break;
}
if(flag==0)
return 0;
else
{
int k=n;
while(s[k]!='\0')//移動到非*字元
{
if(s[k]=='*')
k++;
else
break;
}
int j=0;
while(s[k]!='\0')//向前復制
{
s[n+j]=s[k];
k++;
j++;
}
s[n+j]='\0';
}
return 1;
}
void main()
{
static char str[15];
int m;
cout<<"請輸入一個只含*和字母的字元串:"<<endl;
cin>>str;
cout<<"請輸入n值:"<<endl;
cin>>m;
fun(str,m);
cout<<str<<endl;
}
第三題
#include "iostream"
#include "string"
#include "list"
#include "cassert"
using namespace std;
/*
編號、姓名、部門、應付工資、保險、稅金、實付工資。
其中實付工資由公式計算得到:實付工資=應付工資 - 保險- 稅金
*/
struct employee{
string m_num;//編號
string m_name;//姓名
string m_dep;//部門
double m_salary;//應付工資
double m_insurance;//保險
double m_tax;//稅金
};
/*
(1)錄入:輸入職工數據,其中「實付工資」通過計算得到;
(2)刪除:刪除指定的職工信息(輸入姓名,若找到則刪除該信息)
(3) 修改:允許對已經錄入的數據重新進行編輯、修改;
(4) 顯示:顯示全體職工數據;
(5)查詢:
a. 輸入職工姓名,顯示該職工的全部數據;
b. 輸入某部門值,顯示該部門職工的數據、工資總額、平均工資。
(6) 退出程序。
*/
list<employee> emps;
int main(int argc, char argv[])
{
void print(const employee &e);
void input();
void del();
void mod();
void show_all();
void show_name();
void show_dep();
cout<<"請選擇操作:1.錄入 2.刪除 3.修改 4.查詢 5.顯示所有員工 6.退出 :"<<endl;
int choose=0;
cin>>choose;
assert(!cin.fail());
while (choose!=6)
{
if (choose==1) input();
if (choose==2) del();
if (choose==3) mod();
if (choose==4)
{
int choice=0;
cout<<"請選擇操作 1.按姓名查詢 2.按部門查詢 3.退出:"<<endl;
cin>>choice;
if (choice==1) show_name();
if (choice==2) show_dep();
if (choice==3)
{
cout<<"請選擇操作:1.錄入 2.刪除 3.修改 4.查詢 5.顯示所有員工 6.退出 :"<<endl;
cin>>choose;
assert(!cin.fail());
continue;
}
}
if (choose==5) show_all();
cout<<"請選擇操作:1.錄入 2.刪除 3.修改 4.查詢 5.顯示所有員工 6.退出 :";
cin>>choose;
assert(!cin.fail());
}
return 0;
}
void print(const employee &e)
{
cout<<"編號:"<<e.m_num<<endl;
cout<<"姓名:"<<e.m_name<<endl;
cout<<"部門:"<<e.m_dep<<endl;
cout<<"保險:"<<e.m_insurance<<endl;
cout<<"稅金:"<<e.m_tax<<endl;
cout<<"應付工資:"<<e.m_salary<<endl;
cout<<"實付工資:"<<e.m_salary-e.m_insurance-e.m_tax<<endl;
}
void input()
{
string num,name,dep;
double salary,ins,tax;
cout<<"請輸入員工編號:"<<endl;
cin>>num;
cout<<"請輸入員工姓名:"<<endl;
cin>>name;
cout<<"請輸入員工部門:"<<endl;
cin>>dep;
cout<<"請輸入員工保險:"<<endl;
cin>>ins;
assert(!cin.fail());
cout<<"請輸入員工稅金:"<<endl;
cin>>tax;
assert(!cin.fail());
cout<<"請輸入員工應付工資:"<<endl;
cin>>salary;
assert(!cin.fail());
employee temp;
temp.m_dep=dep;
temp.m_insurance=ins;
temp.m_name=name;
temp.m_num=num;
temp.m_salary=salary;
temp.m_tax=tax;
emps.push_back(temp);
cout<<"員工錄入操作完畢."<<endl;
}
void del()
{
if (emps.size()==0)
{
cout<<"沒有員工記錄."<<endl;
return;
}
string name;
bool isfind=false;
cout<<"請輸入要刪除的員工姓名:"<<endl;
cin>>name;
list<employee>::iterator iter;
for (iter=emps.begin();iter!=emps.end();iter++)
{
if (iter->m_name==name)
{
isfind=true;
emps.erase(iter);
cout<<"姓名為"<<name<<"的員工記錄已刪除."<<endl;
return;
}
}
if (!isfind)
{
cout<<"沒有找到姓名為"<<name<<"的員工."<<endl;
return;
}
}
void mod()
{
if (emps.size()==0)
{
cout<<"員工記錄為空."<<endl;
return;
}
bool isfind=false;
string name;
cout<<"請輸入要修改的員工姓名:"<<endl;
cin>>name;
list<employee>::iterator iter;
for (iter=emps.begin();iter!=emps.end();iter++)
{
if (iter->m_name==name)
{
isfind=true;
cout<<"姓名為"<<name<<"的員工記錄已找到."<<endl;
break;
}
}
if (isfind)
{
string num,name,dep;
double tax,ins,salary;
print(*iter);
cout<<endl;
cout<<"請輸入新的員工編號:"<<endl;
cin>>num;
cout<<"請輸入新的員工姓名:"<<endl;
cin>>name;
cout<<"請輸入新的員工部門:"<<endl;
cin>>dep;
cout<<"請輸入新的員工保險:"<<endl;
cin>>ins;
assert(!cin.fail());
cout<<"請輸入新的員工稅金:"<<endl;
cin>>tax;
assert(!cin.fail());
cout<<"請輸入新的員工工資:"<<endl;
cin>>salary;
assert(!cin.fail());
iter->m_dep=dep;
iter->m_insurance=ins;
iter->m_name=name;
iter->m_num=num;
iter->m_salary=salary;
iter->m_tax=tax;
cout<<"1 員工記錄被成功修改."<<endl;
}
else
{
cout<<"沒有找到姓名為"<<name<<"的員工記錄."<<endl;
}
}
void show_all()
{
if (emps.size()==0)
{
cout<<"員工記錄為空."<<endl;
return;
}
cout<<"顯示全體員工數據:"<<endl;
cout<<"--------------------"<<endl;
list<employee>::iterator iter;
for(iter=emps.begin();iter!=emps.end();iter++)
{
cout<<endl;
print(*iter);
cout<<endl;
}
cout<<"--------------------"<<endl;
}
void show_name()
{
if (emps.size()==0)
{
cout<<"員工記錄為空."<<endl;
return;
}
bool isfind=false;
string name;
cout<<"請輸入要查詢的員工姓名:"<<endl;
cin>>name;
list<employee>::iterator iter;
for(iter=emps.begin();iter!=emps.end();iter++)
{
if (iter->m_name==name)
{
isfind=true;
cout<<"姓名為"<<name<<"的員工記錄已找到."<<endl;
print(*iter);
break;
}
}
if (!isfind)
{
cout<<"沒有找到姓名為"<<name<<"的員工."<<endl;
return;
}
}
void show_dep()
{
if (emps.size()==0)
{
cout<<"員工記錄為空."<<endl;
return;
}
double isfind=0.00;
double total_salary=0.00;
string dep;
cout<<"請輸入要查詢的部門名稱:"<<endl;
cin>>dep;
cout<<"部門["<<dep<<"]的員工信息:"<<endl;
cout<<"--------------------"<<endl;
list<employee>::iterator iter;
for(iter=emps.begin();iter!=emps.end();iter++)
{
if (iter->m_dep==dep)
{
isfind++;
total_salary+=iter->m_salary;
print(*iter);
cout<<endl;
continue;
}
}
cout<<"--------------------"<<endl;
if (isfind==0)
{
cout<<"沒有找到名稱為["<<dep<<"]的部門."<<endl;
}
else
{
cout<<"部門["<<dep<<"]工資統計:"<<endl;
cout<<"工資總額:"<<total_salary<<endl;
cout<<"平均工資:"<<total_salary/isfind<<endl;
}
}
好了 我都運行過的
H. 大一c語言課程設計案例取石子游戲
你c語言課程設計案例其實自由性,這個可以按游戲的規則進行都就可以了。
I. 求C語言程序設計實例(200行)
時間函數舉常式序分析
2.程序源代碼:
#include "stdio.h"
#include "time.h"
void main()
{
time_t lt; /*define a longint time varible*/
lt=time(NULL);/*system time and date*/
printf(ctime(<)); /*english format output*/
printf(asctime(localtime(<)));/*tranfer to tm*/
printf(asctime(gmtime(<))); /*tranfer to Greenwich time*/
}
【程序92】
題目:時間函數舉例2
1.程序分析:
2.程序源代碼:
/*calculate time*/
#include "time.h"
#include "stdio.h"
main()
{
time_t start,end;
int i;
start=time(NULL);
for(i=0;i<3000;i++)
{
printf("\1\1\1\1\1\1\1\1\1\1\n");
}
end=time(NULL);
printf("\1: The different is %6.3f\n",difftime(end,start));
}
【程序93】
題目:時間函數舉例3
1.程序分析:
2.程序源代碼:
/*calculate time*/
#include "time.h"
#include "stdio.h"
main()
{
clock_t start,end;
int i;
double var;
start=clock();
for(i=0;i<10000;i++)
{
printf("\1\1\1\1\1\1\1\1\1\1\n");
}
end=clock();
printf("\1: The different is %6.3f\n",(double)(end-start));
}
【程序94】
題目:時間函數舉例4,一個猜數游戲,判斷一個人反應快慢。(版主初學時編的)
1.程序分析:
2.程序源代碼:
#include "time.h"
#include "stdlib.h"
#include "stdio.h"
main()
{
char c;
clock_t start,end;
time_t a,b;
double var;
int i,guess;
srand(time(NULL));
printf("do you want to play it.('y' or 'n') \n");
loop:
while((c=getchar())=='y')
{
i=rand()%100;
printf("\nplease input number you guess:\n");
start=clock();
a=time(NULL);
scanf("%d",&guess);
while(guess!=i)
{
if(guess>i)
{
printf("please input a little smaller.\n");
scanf("%d",&guess);
}
else
{
printf("please input a little bigger.\n");
scanf("%d",&guess);
}
}
end=clock();
b=time(NULL);
printf("\1: It took you %6.3f seconds\n",var=(double)(end-start)/18.2);
printf("\1: it took you %6.3f seconds\n\n",difftime(b,a));
if(var<15)
printf("\1\1 You are very clever! \1\1\n\n");
else if(var<25)
printf("\1\1 you are normal! \1\1\n\n");
else
printf("\1\1 you are stupid! \1\1\n\n");
printf("\1\1 Congralations \1\1\n\n");
printf("The number you guess is %d",i);
}
printf("\ndo you want to try it again?(\"yy\".or.\"n\")\n");
if((c=getch())=='y')
goto loop;
}
【程序95】
題目:家庭財務管理小程序
1.程序分析:
2.程序源代碼:
/*money management system*/
#include "stdio.h"
#include "dos.h"
main()
{
FILE *fp;
struct date d;
float sum,chm=0.0;
int len,i,j=0;
int c;
char ch[4]="",ch1[16]="",chtime[12]="",chshop[16],chmoney[8];
pp: clrscr();
sum=0.0;
gotoxy(1,1);printf("|----------------------------------------------------|");
gotoxy(1,2);printf("| money management system(C1.0) 2000.03 |");
gotoxy(1,3);printf("|----------------------------------------------------|");
gotoxy(1,4);printf("| -- money records -- | -- today cost list -- |");
gotoxy(1,5);printf("| ------------------------ |-----------------------------|");
gotoxy(1,6);printf("| date: -------------- | |");
gotoxy(1,7);printf("| | | | |");
gotoxy(1,8);printf("| -------------- | |");
gotoxy(1,9);printf("| thgs: ------------------ | |");
gotoxy(1,10);printf("| | | | |");
gotoxy(1,11);printf("| ------------------ | |");
gotoxy(1,12);printf("| cost: ---------- | |");
gotoxy(1,13);printf("| | | | |");
gotoxy(1,14);printf("| ---------- | |");
gotoxy(1,15);printf("| | |");
gotoxy(1,16);printf("| | |");
gotoxy(1,17);printf("| | |");
gotoxy(1,18);printf("| | |");
gotoxy(1,19);printf("| | |");
gotoxy(1,20);printf("| | |");
gotoxy(1,21);printf("| | |");
gotoxy(1,22);printf("| | |");
gotoxy(1,23);printf("|--------------------------------------------------|");
i=0;
getdate(&d);
sprintf(chtime,"%4d.%02d.%02d",d.da_year,d.da_mon,d.da_day);
for(;;)
{
gotoxy(3,24);printf(" Tab __browse cost list Esc __quit");
gotoxy(13,10);printf(" ");
gotoxy(13,13);printf(" ");
gotoxy(13,7);printf("%s",chtime);
j=18;
ch[0 ]=getch();
if(ch[0]==27)
break;
strcpy (chshop,"");
strcpy(chmoney,"");
if(ch[0]==9)
{
mm:i=0;
fp=fopen("home.dat","r+");
gotoxy(3,24);printf(" ");
gotoxy(6,4);printf(" list records ");
gotoxy(1,5);printf("|-------------------------------------|");
gotoxy(41,4);printf(" ");
gotoxy(41,5);printf(" |");
while(fscanf(fp,"%10s%14s%f\n",chtime,chshop,&chm)!=EOF)
{
if(i==36)
{
getch();
i=0;
}
if ((i%36)<17)
{
gotoxy(4,6+i);
printf(" ");
gotoxy(4,6+i);
}
else
if((i%36)>16)
{
gotoxy(41,4+i-17);
printf(" ");
gotoxy(42,4+i-17);
}
i++;
sum=sum+chm;
printf("%10s %-14s %6.1f\n",chtime,chshop,chm);}
gotoxy(1,23);printf("|----------------------------------------------|");
gotoxy(1,24);printf("| |");
gotoxy(1,25);printf("|----------------------------------------------|");
gotoxy(10,24);printf("total is %8.1f$",sum);
fclose(fp);
gotoxy(49,24);printf("press any key to.....");getch();goto pp;
}
else
{
while(ch[0]!='\r')
{
if(j<10)
{
strncat(chtime,ch,1);
j++;
}
if(ch[0]==8)
{
len=strlen(chtime)-1;
if(j>15)
{
len=len+1;
j=11;
}
strcpy(ch1,"");
j=j-2;
strncat(ch1,chtime,len);
strcpy(chtime,"");
strncat(chtime,ch1,len-1);
gotoxy(13,7);printf(" ");
}
gotoxy(13,7);printf("%s",chtime);ch[0]=getch();
if(ch[0]==9)
goto mm;
if(ch[0]==27)
exit(1);
}
gotoxy(3,24);printf(" ");
gotoxy(13,10);
j=0;
ch[0]=getch();
while(ch[0]!='\r')
{
if (j<14)
{
strncat(chshop,ch,1);
j++;
}
if(ch[0]==8)
{
len=strlen(chshop)-1;
strcpy(ch1,"");
j=j-2;
strncat(ch1,chshop,len);
strcpy(chshop,"");
strncat(chshop,ch1,len-1);
gotoxy(13,10);printf(" ");
}
gotoxy(13,10);printf("%s",chshop);ch[0]=getch();}
gotoxy(13,13);
j=0;
ch[0]=getch();
while(ch[0]!='\r')
{
if (j<6)
{
strncat(chmoney,ch,1);
j++;
}
if(ch[0]==8)
{
len=strlen(chmoney)-1;
strcpy(ch1,"");
j=j-2;
strncat(ch1,chmoney,len);
strcpy(chmoney,"");
strncat(chmoney,ch1,len-1);
gotoxy(13,13);printf(" ");
}
gotoxy(13,13);printf("%s",chmoney);ch[0]=getch();
}
if((strlen(chshop)==0)||(strlen(chmoney)==0))
continue;
if((fp=fopen("home.dat","a+"))!=NULL);
fprintf(fp,"%10s%14s%6s",chtime,chshop,chmoney);
fputc('\n',fp);
fclose(fp);
i++;
gotoxy(41,5+i);
printf("%10s %-14s %-6s",chtime,chshop,chmoney);
}
}
}
【程序96】
題目:計算字元串中子串出現的次數
1.程序分析:
2.程序源代碼:
#include "string.h"
#include "stdio.h"
main()
{
char str1[20],str2[20],*p1,*p2;
int sum=0;
printf("please input two strings\n");
scanf("%s%s",str1,str2);
p1=str1;p2=str2;
while(*p1!='\0')
{
if(*p1==*p2)
{
while(*p1==*p2&&*p2!='\0')
{
p1++;
p2++;
}
}
else
p1++ ;
if(*p2=='\0')
sum++;
p2=str2;
}
printf("%d",sum);
getch();
}
【程序97】
題目:從鍵盤輸入一些字元,逐個把它們送到磁碟上去,直到輸入一個#為止。
1.程序分析:
2.程序源代碼:
#include "stdio.h"
main()
{
FILE *fp;
char ch,filename[10];
scanf("%s",filename);
if((fp=fopen(filename,"w"))==NULL)
{
printf("cannot open file\n");
exit(0);
}
ch=getchar();
ch=getchar();
while(ch!='#')
{
fputc(ch,fp);putchar(ch);
ch=getchar();
}
fclose(fp);
}
【程序98】
題目:從鍵盤輸入一個字元串,將小寫字母全部轉換成大寫字母,然後輸出到一個磁碟文件"test"中保存。輸入的字元串以!結束。
1.程序分析:
2.程序源代碼:
#include "stdio.h"
main()
{
FILE *fp;
char str[100],filename[10];
int i=0;
if((fp=fopen("test","w"))==NULL)
{
printf("cannot open the file\n");
exit(0);
}
printf("please input a string:\n");
gets(str);
while(str[i]!='!')
{
if(str[i]>='a'&&str[i]<='z')
str[i]=str[i]-32;
fputc(str[i],fp);
i++;
}
fclose(fp);
fp=fopen("test","r");
fgets(str,strlen(str)+1,fp);
printf("%s\n",str);
fclose(fp);
}
【程序99】
題目:有兩個磁碟文件A和B,各存放一行字母,要求把這兩個文件中的信息合並(按字母順序排列),
輸出到一個新文件C中。
1.程序分析:
2.程序源代碼:
#include "stdio.h"
main()
{
FILE *fp;
int i,j,n,ni;
char c[160],t,ch;
if((fp=fopen("A","r"))==NULL)
{
printf("file A cannot be opened\n");
exit(0);
}
printf("\n A contents are :\n");
for(i=0;(ch=fgetc(fp))!=EOF;i++)
{
c[i]=ch;
putchar(c[i]);
}
fclose(fp);
ni=i;
if((fp=fopen("B","r"))==NULL)
{
printf("file B cannot be opened\n");
exit(0);
}
printf("\n B contents are :\n");
for(i=0;(ch=fgetc(fp))!=EOF;i++)
{
c[i]=ch;
putchar(c[i]);
}
fclose(fp);
n=i;
for(i=0;i<n;i++)
for(j=i+1;j<n;j++)
if(c[i]>c[j])
{
t=c[i];c[i]=c[j];c[j]=t;
}
printf("\n C file is:\n");
fp=fopen("C","w");
for(i=0;i<n;i++)
{
putc(c[i],fp);
putchar(c[i]);
}
fclose(fp);
}
【程序100】
題目:有五個學生,每個學生有3門課的成績,從鍵盤輸入以上數據(包括學生號,姓名,三門課成績),計算出平均成績,況原有的數據和計算出的平均分數存放在磁碟文件"stud"中。
1.程序分析:
2.程序源代碼:
#include "stdio.h"
struct student
{
char num[6];
char name[8];
int score[3];
float avr;
} stu[5];
main()
{
int i,j,sum;
FILE *fp;
/*input*/
for(i=0;i<5;i++)
{
printf("\n please input No. %d score:\n",i);
printf("stuNo:");
scanf("%s",stu[i].num);
printf("name:");
scanf("%s",stu[i].name);
sum=0;
for(j=0;j<3;j++)
{
printf("score %d.",j+1);
scanf("%d",&stu[i].score[j]);
sum+=stu[i].score[j];
}
stu[i].avr=sum/3.0;
}
fp=fopen("stud","w");
for(i=0;i<5;i++)
if(fwrite(&stu[i],sizeof(struct student),1,fp)!=1)
printf("file write error\n");
fclose(fp);
}
J. c語言程序設計實例
// 電話本Dlg.cpp : 實現文件
//
#include stdafx.h
#include 電話本.h
#include 電話本Dlg.h
#ifdef _DEBUG
#define new DEBUG_NEW
#endif
// C電話本Dlg 對話框
C電話本Dlg::C電話本Dlg(CWnd* pParent /*=NULL*/)
: CDialog(C電話本Dlg::IDD, pParent)
{
m_hIcon = AfxGetApp()-LoadIcon(IDR_MAINFRAME);
}
void C電話本Dlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
}
BEGIN_MESSAGE_MAP(C電話本Dlg, CDialog)
ON_WM_PAINT()
ON_WM_QUERYDRAGICON()
//}}AFX_MSG_MAP
ON_EN_CHANGE(IDC_EDIT1, C電話本Dlg::OnName)
ON_EN_CHANGE(IDC_EDIT2, C電話本Dlg::OnPhoto)
ON_EN_CHANGE(IDC_EDIT3, C電話本Dlg::OnAddress)
ON_EN_CHANGE(IDC_EDIT4, C電話本Dlg::OnShow)
ON_BN_CLICKED(IDC_BUTTON1, C電話本Dlg::OnFill)
ON_BN_CLICKED(IDC_BUTTON2, C電話本Dlg::OnInsert)
ON_BN_CLICKED(IDC_BUTTON3, C電話本Dlg::OnFind)
ON_BN_CLICKED(IDC_BUTTON4, C電話本Dlg::OnDelete)
ON_BN_CLICKED(IDC_BUTTON5, C電話本Dlg::OnEdit)
ON_BN_CLICKED(IDC_BUTTON7, C電話本Dlg::OnSave)
END_MESSAGE_MAP()
// C電話本Dlg 消息處理程序
BOOL C電話本Dlg::OnInitDialog()
{
CDialog::OnInitDialog();
// 設置此對話框的圖標。當應用程序主窗口不是對話框時,框架將自動
// 執行此操作
SetIcon(m_hIcon, TRUE); // 設置大圖標
SetIcon(m_hIcon, FALSE); // 設置小圖標
// TODO: 在此添加額外的初始化代碼
ifstream InFile(Wab.fsd,ios::in);
listWabList::iterator ItWab;
char Tmp1[8],Tmp2[16],Tmp3[32];
Wab.clear();
while(InFile Tmp1 Tmp2 Tmp3)
{
OutWab.Name=Tmp1;
OutWab.Photo=Tmp2;
OutWab.Address=Tmp3;
Wab.push_front(OutWab);
}
C電話本Dlg::OnFill();
return TRUE; // 除非將焦點設置到控制項,否則返回 TRUE
}
// 如果向對話框添加最小化按鈕,則需要下面的代碼
// 來繪制該圖標。對於使用文檔/視圖模型的 MFC 應用程序,
// 這將由框架自動完成。
void C電話本Dlg::OnPaint()
{
if (IsIconic())
{
CPaintDC dc(this); // 用於繪制的設備上下文
SendMessage(WM_ICONERASEBKGND, reinterpret_castWPARAM(dc.GetSafeHdc()), 0);
// 使圖標在工作矩形中居中
int cxIcon = GetSystemMetrics(SM_CXICON);
int cyIcon = GetSystemMetrics(SM_CYICON);
CRect rect;
GetClientRect(rect);
int x = (rect.Width() - cxIcon 1) / 2;
int y = (rect.Height() - cyIcon 1) / 2;
// 繪制圖標
dc.DrawIcon(x, y, m_hIcon);
}
else
{
CDialog::OnPaint();
}
}
//當用戶拖動最小化窗口時系統調用此函數取得游標顯示。
//
HCURSOR C電話本Dlg::OnQueryDragIcon()
{
return static_castHCURSOR(m_hIcon);
}
void C電話本Dlg::OnName()
{
CEdit *pMaxLen=(CEdit*)GetDlgItem(IDC_EDIT1);
pMaxLen-SetLimitText(6);
GetDlgItemText(IDC_EDIT1,InWab.Name);
}
void C電話本Dlg::OnPhoto()
{
CEdit *pMaxLen=(CEdit*)GetDlgItem(IDC_EDIT2);
pMaxLen-SetLimitText(11);
GetDlgItemText(IDC_EDIT2,InWab.Photo);
}
void C電話本Dlg::OnAddress()
{
CEdit *pMaxLen=(CEdit*)GetDlgItem(IDC_EDIT3);
pMaxLen-SetLimitText(30);
GetDlgItemText(IDC_EDIT3,InWab.Address);
}
void C電話本Dlg::OnShow()
{
// TODO: 如果該控制項是 RICHEDIT 控制項,則它將不會
// 發送該通知,除非重寫 CDialog::OnInitDialog()
// 函數並調用 CRichEditCtrl().SetEventMask(),
// 同時將 ENM_CHANGE 標志「或」運算到掩碼中。
// TODO: 在此添加控制項通知處理程序代碼
}
void C電話本Dlg::OnFill()
{
CString OutAll,OutTemp,Space,Enter;
Space=_T( );
Enter=_T(\r\n);
listWabList::iterator ItWab;
for(ItWab=Wab.begin();ItWab!=Wab.end();ItWab )
{
OutWab=*ItWab;
OutTemp=OutWab.Name Space OutWab.Photo Space OutWab.Address;
OutAll=OutAll OutTemp Enter;
}
SetDlgItemText(IDC_EDIT4,OutAll);
}
void C電話本Dlg::OnInsert()
{
Wab.push_front(InWab);
C電話本Dlg::OnFill();
}
void C電話本Dlg::OnFind()
{
CString OutAll,OutTemp,Space,Enter;
Space=_T( );
Enter=_T(\r\n);
listWabList::iterator ItWab;
for(ItWab=Wab.begin();ItWab!=Wab.end();ItWab )
{
if(ItWab-Name==InWab.Name)
{
OutTemp=ItWab-Name Space ItWab-Photo Space ItWab-Address;
OutAll=OutAll OutTemp Enter;
}
}
SetDlgItemText(IDC_EDIT4,OutAll);
}
void C電話本Dlg::OnDelete()
{
CString OutAll,OutTemp,Space,Enter;
Space=_T( );
Enter=_T(\r\n);
listWabList::iterator ItWab;
for(ItWab=Wab.begin();ItWab!=Wab.end();ItWab )
{
if(ItWab-Name==InWab.Name)
{
OutTemp=ItWab-Name Space ItWab-Photo Space ItWab-Address;
OutAll=OutAll OutTemp Enter;
break;
}
}
SetDlgItemText(IDC_EDIT4,OutAll);
if(ItWab!=Wab.end()) Wab.erase(ItWab);
}
void C電話本Dlg::OnEdit()
{
CString OutAll,OutTemp,Space,Enter;
Space=_T( );
Enter=_T(\r\n);
listWabList::iterator ItWab;
for(ItWab=Wab.begin();ItWab!=Wab.end();ItWab )
{
if(ItWab-Name==InWab.Name)
{
OutTemp=ItWab-Name Space ItWab-Photo Space ItWab-Address;
OutAll=OutAll OutTemp Enter;
break;
}
}
SetDlgItemText(IDC_EDIT4,OutAll);
if(ItWab!=Wab.end())
{
Wab.erase(ItWab);
Wab.push_front(InWab);
}
}
void C電話本Dlg::OnSave()
{
CString Tmp1,Tmp2,Tmp3;
ofstream OutFile(Wab.fsd,ios::out);
listWabList::iterator ItWab;
for(ItWab=Wab.begin();ItWab!=Wab.end();ItWab )
{
Tmp1=ItWab-Name;
Tmp2=ItWab-Photo;
Tmp3=ItWab-Address;
OutFile Tmp1 ' ' Tmp2 ' ' Tmp3 endl;
}
}
只是個用C語言編寫的電話本程序 很有實用意義