㈠ 鍒朵綔锲句功棣嗕俊鎭绯荤粺镄勪唬镰
#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码”()。