㈠ 鍒朵綔鍥句功棣嗕俊鎮緋葷粺鐨勪唬鐮
#include<stdio.h>
#include<string.h>/*閫氳繃瀹氫箟姝ゅ嚱鏁幫紝鏉ュ紩鐢ㄥ瓧絎︿覆姣旇緝銆佹祴瀹氶暱搴︾瓑鐩稿叧鍑芥暟*/
#include<stdlib.h>/*閫氳繃瀹氫箟姝ゅ嚱鏁幫紝寮曠敤exit()絳夊嚱鏁*/
#include<conio.h>/*閫氳繃瀹氫箟姝ゅ嚱鏁幫紝鏉ュ紩鐢╣etch()絳夊嚱鏁*/
#define MAX 100
struct Student/*瀹氫箟緇撴瀯浣揝tudent*/
{
int num;/*鐧誨綍鍙*/
char name[100];/*涔﹀悕*/
char author[100];/*浣滆呭悕*/
char fn[100];/*鍒嗙被鍙*/
char place[100];/*鍑虹増鍗曚綅*/
char day[100];/*鍑虹増鏃墮棿*/
float money;/*浠鋒牸*/
}stu[MAX];/*緇撴瀯浣撴暟緇*/
main()/*涓誨嚱鏁*/
{
void Input();/*杈撳叆*/
void Display();/*杈撳嚭*/
void Find();/*鏌ユ壘*/
void Modify();/*鍒犻櫎*/
void Change();/*淇鏀*/
int n;
for(;;)
{
printf("\n");
printf("*************************************************************\n");
printf(" \n");
printf(" 嬈㈣繋鏉ュ埌鍥句功淇℃伅綆$悊緋葷粺 \n");
printf(" \n");
printf(" \n");
printf(" 涓昏彍鍗 \n");
printf(" \n");
printf(" &&1.鍥句功淇℃伅褰曞叆 \n");
printf(" \n");
printf(" &&2.鍥句功淇℃伅嫻忚 \n");
printf(" \n");
printf(" &&3.鍥句功淇℃伅鏌ヨ \n");
printf(" \n");
printf(" &&4.鍥句功淇℃伅鍒犻櫎 \n");
printf(" \n");
printf(" &&5.鍥句功淇℃伅淇鏀 \n");
printf(" \n");
printf(" &&6.閫鍑虹郴緇 \n");
printf(" \n");
printf("*************************************************************\n\n");
printf("璇瘋緭鍏ラ夋嫨欏(1-6):");
scanf("%d",&n);
printf("\n\n\n\n");
if(n>0&&n<7)
{
switch(n)
{
case 1:Input();break;
case 2:Display();break;
case 3:Find();break;
case 4:Modify();break;
case 5:Change();break;
case 6:printf("************************************************\n");
printf(" \n");
printf(" 璋㈣阿浣跨敤 \n");
printf(" 鍐嶈! \n");
printf(" \n");
printf("************************************************\n");
exit(0);
}
}
else
{
printf("************************************************\n");
printf(" \n");
printf(" 杈撳叆閿欒! \n");
printf(" 璇烽鍑! \n");
printf(" \n");
printf("************************************************\n");
break;
}
}
}
void Find()/*鏌ユ壘*/
{
FILE *fp; /*瀹氫箟緇撴瀯浣撴寚閽堝彉閲*/
int i;
int choose,t;
char ans[100];
do
{
printf("1.鎸変功鍚嶆煡鎵\n");
printf("2.鎸変綔鑰呭悕鏌ユ壘\n");
printf("榪斿洖涓昏彍鍗(鍏朵粬鏁板瓧)\n");
scanf("%d",&choose);
if(choose==1)
{
printf("杈撳叆鎵鏌ヤ功鍚嶏細\n");
scanf("%s",ans);
t=-1;
if(choose==1)
{
for(i=0;i<MAX;i++) if(strcmp(ans,stu[i].name)==0)
{
t=i;
fp=fopen("student","rb");
for(i=0;fread(&stu[i],sizeof(struct Student),1,fp)==1;i++)
printf("%d %s %s %s %s %s %f\n",stu[t].num,stu[t].name,stu[t].author,stu[t].fn,stu[t].place,stu[t].day,stu[t].money);
}
}
if(t==-1) printf("涓嶅瓨鍦ㄨヤ俊鎮\n");
}
else if(choose==2)
{
printf("杈撳叆鎵鏌ヤ綔鑰呭悕錛\n");
scanf("%s",ans);
t=-1;
if(choose==2)
{
for(i=0;i<MAX;i++)
if(strcmp(ans,stu[i].author)==0)
{ t=i;
fp=fopen("student","rb");
for(i=0;fread(&stu[i],sizeof(struct Student),1,fp)==1;i++)
printf("%d %s %s %s %s %s %f\n",stu[t].num,stu[t].name,stu[t].author,stu[t].fn,stu[t].place,stu[t].day,stu[t].money);
}
}
if(t==-1) printf("涓嶅瓨鍦ㄨヤ俊鎮\n");
}
else return;
}while(1);
}
void Display()/*杈撳嚭*/
{
FILE *fp;
int i;
fp=fopen("student","rb");
printf("*************************************************************\n");
printf(" 鍥句功鍒楄〃\n");
printf("-----------------------------------------------------------\n");
printf("鐧誨綍鍙 涔﹀悕 浣滆呭悕 鍒嗙被鍙 鍑虹増鍗曚綅 鍑虹増鏃墮棿 浠鋒牸\n");
printf("-----------------------------------------------------------\n");
for(i=0;fread(&stu[i],sizeof(struct Student),1,fp)==1;i++)
{
printf("%6d %8s %8s %8s %8s %8s %8.2f\n",stu[i].num,stu[i].name,stu[i].author,stu[i].fn,stu[i].place,stu[i].day,stu[i].money);
}
fclose(fp);
}
void Input()/*杈撳叆*/
{
FILE *fp;
int n;
fp=fopen("student","wb");
for(n=0;n<MAX;n++)
{
printf("n=%d 杈撳叆搴忓彿n(褰撹緭鍏n=-1鏃,榪斿洖),n=",n++);
scanf("%d",&n);
if(n==-1)
{
fclose(fp);
return;
}
else
{
printf("璇瘋緭鍏ョ櫥褰曞彿 涔﹀悕 浣滆呭悕 鍒嗙被鍙 鍑虹増鍗曚綅 鍑虹増鏃墮棿 浠鋒牸\n");
scanf("%d%s%s%s%s%s%f",&stu[n].num,stu[n].name,stu[n].author,stu[n].fn,stu[n].place,stu[n].day,&stu[n].money);
fwrite(&stu[n],sizeof(struct Student),1,fp);
}
}
fclose(fp);
}
void Modify()/*鍒犻櫎*/
{
FILE *fp;
int i,flag,n,s,j;
fp=fopen("student","rb+");
rewind(fp);
printf(" 鍥句功鍒楄〃\n");
printf("-----------------------------------------------------------\n");
printf("鐧誨綍鍙 涔﹀悕 浣滆呭悕 鍒嗙被鍙 鍑虹増鍗曚綅 鍑虹増鏃墮棿 浠鋒牸\n");
printf("-----------------------------------------------------------\n");
for(i=0;fread(&stu[i],sizeof(struct Student),1,fp)==1;i++)
{
printf("%6d %8s %8s %8s %8s %8s %8.2f\n",stu[i].num,stu[i].name,stu[i].author,stu[i].fn,stu[i].place,stu[i].day,stu[i].money);
printf("\n");
}
n=i;
printf("杈撳叆寰呭垹闄ゅ浘涔﹀彿:\n");
scanf("%d",&s);
for(i=0,flag=1;flag&&i<n;i++)
{
if(s==stu[i].num)
{
for(j=i;j<n-1;j++)
{
stu[j].num=stu[j+1].num;
strcpy(stu[j].name,stu[j+1].name);
strcpy(stu[j].author,stu[j+1].author);
strcpy(stu[j].fn,stu[j+1].fn);
strcpy(stu[j].place,stu[j+1].place);
strcpy(stu[j].day,stu[j+1].day);
stu[j].money=stu[j+1].money;
}
flag=0;
}
}
if(!flag)
n=n-1;
else
printf("娌℃湁姝ゅ彿\n");
fp=fopen("student","wb");
for(i=0;i<n;i++)
fwrite(&stu[i],sizeof(struct Student),1,fp);
fclose(fp);
fp=fopen("student","r");
printf(" 鍥句功鍒楄〃\n");
printf("-----------------------------------------------------------\n");
printf("鐧誨綍鍙 涔﹀悕 浣滆呭悕 鍒嗙被鍙 鍑虹増鍗曚綅 鍑虹増鏃墮棿 浠鋒牸\n");
printf("-----------------------------------------------------------\n");
for(i=0;i<n;i++)
{
fread(&stu[i],sizeof(struct Student),1,fp);
printf("%6d %8s %8s %8s %8s %8s %8.2f\n",stu[i].num,stu[i].name,stu[i].author,stu[i].fn,stu[i].place,stu[i].day,stu[i].money);
printf("\n");
}
fclose(fp);
}
void Change()/*淇鏀*/
{
FILE *fp;
int i,num,n;
int flag=0;
printf("璇瘋緭鍏ヨ佷慨鏀圭殑鍥句功鍙:");
scanf("%d",&num);
for(i=0;i<=MAX;i++)
if(stu[i].num==num)
{
printf(" 鍥句功鍒楄〃\n");
printf("-----------------------------------------------------------\n");
printf("鐧誨綍鍙 涔﹀悕 浣滆呭悕 鍒嗙被鍙 鍑虹増鍗曚綅 鍑虹増鏃墮棿 浠鋒牸\n");
printf("-----------------------------------------------------------\n");
printf("%6d %8s %8s %8s %8s %8s %8.2f\n",stu[i].num,stu[i].name,stu[i].author,stu[i].fn,stu[i].place,stu[i].day,stu[i].money);
printf("-----------------------------------------------------------\n\n");
n=i;
flag=1;
break;
}
if(flag==0)
{
printf("******************************************************************\n");
printf(" 杈撳叆閿欒!\n");
printf(" 璇瘋繑鍥!\n");
printf("******************************************************************\n");
return;
}
printf("\n\n\n");
fp=fopen("student","rb+");
fseek(fp,n*sizeof(struct Student),0);
printf("鐧誨綍鍙 涔﹀悕 浣滆呭悕 鍒嗙被鍙 鍑虹増鍗曚綅 鍑虹増鏃墮棿 浠鋒牸\n");
scanf("%d%s%s%s%s%s%f",&stu[n].num,stu[n].name,stu[n].author,stu[n].fn,stu[n].place,stu[n].day,&stu[n].money);
fwrite(&stu[i],sizeof(struct Student),1,fp);
fclose(fp);
fp=fopen("student","rb");
printf(" 鍥句功鍒楄〃\n");
printf("-----------------------------------------------------------\n");
printf("鐧誨綍鍙 涔﹀悕 浣滆呭悕 鍒嗙被鍙 鍑虹増鍗曚綅 鍑虹増鏃墮棿 浠鋒牸\n");
printf("-----------------------------------------------------------\n");
for(i=0;fread(&stu[i],sizeof(struct Student),1,fp)==1;i++)
{
printf("%6d %8s %8s %8s %8s %8s %8.2f\n",stu[i].num,stu[i].name,stu[i].author,stu[i].fn,stu[i].place,stu[i].day,stu[i].money);;
}
printf("-----------------------------------------------------------\n\n");
fclose(fp);
}
㈡ 計算機常用的信息編碼有哪幾種
信息編碼(InformationCoding)是為了方便信息的存儲、檢索和使用,在進行信息處理時賦予信息元素以代碼的過程。即用不同的代碼與各種信息中的基本單位組成部分建立一一對應的關系。信息編碼必須標准、系統化,設計合理的編碼系統是關系信息管理系統生命力的重要因素。
一般應有的代碼有兩類,一類是有意義的代碼,即賦予代碼一定的實際意義,便於分類處理;一類是無意義的代碼,僅僅是賦予信息元素唯一的代號,便於對信息的操作。常用的代碼類型有:
(1)順序碼,即接信息元素的順序依次編碼;
(2)區間碼,即用一代碼區間代表某一信息組;
(3)記憶碼,即能幫助聯想記憶的代碼。
信息的表現形式多種多樣,因而編碼的方案也非常多。例如:我國制定的包括一、二級漢字和常用符號的圖形字元代碼(GB5007-85),日文、韓文等其他文字與符號的「大5碼」(BIG5),英文字元的「ASCII碼」()。