全國(guó)計(jì)算機(jī)等級(jí)考試三級(jí)網(wǎng)絡(luò)技術(shù)南開上機(jī)100題_第1頁
全國(guó)計(jì)算機(jī)等級(jí)考試三級(jí)網(wǎng)絡(luò)技術(shù)南開上機(jī)100題_第2頁
全國(guó)計(jì)算機(jī)等級(jí)考試三級(jí)網(wǎng)絡(luò)技術(shù)南開上機(jī)100題_第3頁
全國(guó)計(jì)算機(jī)等級(jí)考試三級(jí)網(wǎng)絡(luò)技術(shù)南開上機(jī)100題_第4頁
全國(guó)計(jì)算機(jī)等級(jí)考試三級(jí)網(wǎng)絡(luò)技術(shù)南開上機(jī)100題_第5頁
已閱讀5頁,還剩85頁未讀, 繼續(xù)免費(fèi)閱讀

下載本文檔

版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請(qǐng)進(jìn)行舉報(bào)或認(rèn)領(lǐng)

文檔簡(jiǎn)介

1、全國(guó)計(jì)算機(jī)等級(jí)考試三級(jí)網(wǎng)絡(luò)技術(shù)南開上機(jī)100題幾點(diǎn)說明:1、題目標(biāo)題號(hào)前用“”顯示的是2005年4月份本人根據(jù)各大論壇考生聵的題號(hào)集中而來,題號(hào)前加“”為2005年9月上機(jī)考試題,其中難免有題型相同而題號(hào)增加的現(xiàn)象,此類標(biāo)明,僅供參考。2、每種題目,只用一種解題方法,蘭色部分為解題答案,此種方法本人覺得容易理解,不易出錯(cuò),適合初學(xué)者。3、特別說明:所有解法,本人均上機(jī)驗(yàn)證通過。4、個(gè)別南開題如57、100題,題目與原書有所不同,是按實(shí)際考試的題目所來,并對(duì)今年在實(shí)際上機(jī)中出現(xiàn)的考題,用紅色部分表示實(shí)際上機(jī)題中的注明事項(xiàng)。題目1請(qǐng)編寫一個(gè)函數(shù)jsValue(int m,int k,int xx)

2、,該函數(shù)的功能是:將大于整數(shù)m且緊靠m的k個(gè)素?cái)?shù)存入數(shù)組xx傳回。    最后調(diào)用函數(shù)writeDat()讀取10組數(shù)據(jù),分別得出結(jié)果且把結(jié)果輸出到文件out.dat中。    部分源程序存在文件prog1.c中。    例如:若輸入17 5 則應(yīng)輸出:19,23,29,31,37。    請(qǐng)勿改動(dòng)主函數(shù)main()和寫函數(shù)writeDat()的內(nèi)容。#include <conio.h>#include <stdio.

3、h>void readwriteDat();int isP(int m)int i;for(i=2;i<m;i+)   if(m % i=0)return 0;return 1;void num(int m,int k,int xx) int s=0;  for(m=m+1;k>0;m+)   if(isP(m) xxs+=m; k-;main()  int m,n,xx1000;  clrscr();  printf("nPl

4、ease enter two integers:");  scanf("%d%d",&m,&n);  num(m,n,xx);  for(m=0;m<n;m+)  printf("%d ",xxm);  printf("n");  readwriteDat();void readwriteDat()int m,n,xx1000, i;FILE *rf,*wf;rf=fopen(&quo

5、t;in.dat","r");wf=fopen("out.dat","w");for(i=0;i<10;i+)   fscanf(rf,"%d %d",&m,&n);   num(m,n,xx);   for(m=0;m<n;m+)fprintf(wf,"%d ",xxm);   fprintf(wf,"n");fclo

6、se(rf);fclose(wf);     題目2已知數(shù)據(jù)文件IN.DAT中存有200個(gè)四位數(shù),并已調(diào)用讀函數(shù)readDat()把這些數(shù)存入數(shù)組a中,請(qǐng)考生編制一函數(shù)jsVal(),其功能是:如果四位數(shù)各位上的數(shù)字均是0或2或4或6或8,則統(tǒng)計(jì)出滿足此條件的個(gè)數(shù)cnt,并把這些四位數(shù)按從大到小的順序存入數(shù)組b中。最后main( )函數(shù)調(diào)用寫函數(shù)writeDat()把結(jié)果cnt以及數(shù)組b中符合條件的四位數(shù)輸出到OUT.DAT文件中。    注意:部分源程序存在文件prog1.c中。  

7、  程序中已定義數(shù)組:a200,b200,已定義變量:cnt    請(qǐng)勿改動(dòng)數(shù)據(jù)文件IN.DAT中的任何數(shù)據(jù)、主函數(shù)main()、讀函數(shù)readDat()和寫函數(shù)writeDat()的內(nèi)容。#include <stdio.h>#define MAX 200int aMAX, bMAX, cnt = 0 ;void jsVal() int i,j,qw,bw,sw,gw;for(i=0;i<MAX;i+)    qw=ai/1000; bw=ai/100%10;   &

8、#160;   sw=ai%100/10; gw=ai%10;      if(qw&&qw%2=0&&bw%2=0&&sw%2=0&&gw%2=0) bcnt+=ai;       for(i=0;i<cnt-1;i+)     for(j=i+1;j<cnt;j+)       if(bi<b

9、j) qw=bi; bi=bj; bj=qw;void readDat()int i ;FILE *fp ;fp = fopen("in.dat", "r") ;for(i = 0 ; i < MAX ; i+) fscanf(fp, "%d", &ai) ;fclose(fp) ;void main()int i ;readDat() ;jsVal() ;printf("滿足條件的數(shù)=%dn", cnt) ;for(i = 0 ; i < cnt ; i+) printf("%d &

10、quot;, bi) ;printf("n") ;writeDat() ;writeDat()FILE *fp ;int i ;fp = fopen("out.dat", "w") ;fprintf(fp, "%dn", cnt) ;for(i = 0 ; i < cnt ; i+) fprintf(fp, "%dn", bi) ;fclose(fp) ;題目3函數(shù)ReadDat( )實(shí)現(xiàn)從文件IN.DAT中讀取一篇英文文章存入到字符串?dāng)?shù)組xx中;請(qǐng)編制函數(shù)StrOR( ),其函數(shù)的功能是

11、:以行為單位依次把字符串中所有小寫字母o左邊的字符串內(nèi)容移到該串的右邊存放,然后把小寫字母o刪除,余下的字符串內(nèi)容移到已處理字符串的左邊存放,之后把已處理的字符串仍按行重新存入字符串?dāng)?shù)組xx中。最后main()函數(shù)調(diào)用函數(shù)WriteDat()把結(jié)果xx輸出到文件OUT5.DAT中。      原始數(shù)據(jù)文件存放的格式是:每行的寬度均小于80個(gè)字符,含標(biāo)點(diǎn)符號(hào)和空格。    注意:部分源程序存放在文件prog1.c中。    請(qǐng)勿改動(dòng)主函數(shù)main()、讀數(shù)據(jù)

12、函數(shù)ReadDat()和輸出數(shù)據(jù)函數(shù)WriteDat()的內(nèi)容。#include <stdio.h>#include <string.h>#include <conio.h>char xx5080 ;int maxline = 0 ; /* 文章的總行數(shù) */int ReadDat(void) ;void WriteDat(void) ;void StrOR(void)int i,righto,j,s,k;char tem80;for(i=0;i<maxline;i+)   for(j=strlen(xxi)-1;j>

13、;=0;j-)       k=0; memset(tem,0,80);         if(xxij='o')           righto=j;           for(s=righto+1;s<strlen(xxi);s+) tem

14、k+=xxis; for(s=0;s<righto;s+)     if(xxis!='o') temk+=xxis;    strcpy(xxi,tem);                    else continue;       

15、; void main()clrscr() ;if(ReadDat()      printf("數(shù)據(jù)文件IN.DAT不能打開!n007") ;     return ;StrOR() ;WriteDat() ;int ReadDat(void)FILE *fp ;int i = 0 ;char *p ;if(fp = fopen("IN.DAT", "r") = NULL) return 1 ;while(fgets(xxi, 80, fp) != NU

16、LL)      p = strchr(xxi, 'n') ;     if(p) *p = 0 ;     i+ ;maxline = i ;fclose(fp) ;return 0 ;void WriteDat(void)FILE *fp ;int i ;clrscr() ;fp = fopen("OUT5.DAT", "w") ;for(i = 0 ; i < maxline ; i+)  

17、0;   printf("%sn", xxi) ;     fprintf(fp, "%sn", xxi) ;fclose(fp) ;題目4函數(shù)ReadDat()實(shí)現(xiàn)從文件IN.DAT中讀取一篇英文文章存入到字符串?dāng)?shù)組xx中,請(qǐng)編制函數(shù)StrOL(),其函數(shù)的功能是:以行為單位對(duì)行中以空格或標(biāo)點(diǎn)符號(hào)為分隔的所有單詞進(jìn)行倒排。最后把已處理的字符串(應(yīng)不含標(biāo)點(diǎn)符號(hào))仍按行重新存入字符串?dāng)?shù)組xx中,最后調(diào)用函數(shù)writeDat()把結(jié)果xx輸出到文件OUT6.DAT中。  

18、0; 例如:原文:You He Me                 I am a student.結(jié)果:Me He You                 student a am I    原始數(shù)據(jù)文件存放的格式是:每行的寬度

19、均小于80個(gè)字符,含標(biāo)點(diǎn)符號(hào)和空格。    部分源程序存在文件prog1.c中。    請(qǐng)勿改動(dòng)主函數(shù)main()、讀數(shù)據(jù)函數(shù)ReadDat()和輸出數(shù)據(jù)函數(shù)writeDat()的內(nèi)容。#include <stdio.h>#include <string.h>#include <conio.h>#include <ctype.h>char xx5080;int maxline=0;/*文章的總行數(shù)*/int ReadDat(void);void WriteDat(vo

20、id);void StrOL(void) int i,j,k,s,m,strl;char str80;for(i=0;i<maxline;i+)    strl=strlen(xxi);memset(str,0,80);     s=k=0;for(j=strl-1;j>=0;j-)       if(isalpha(xxij) k+;      else for(m=1;m<=k;m+)strs+=xxij+m;&#

21、160;                k=0;                            if(!isalpha(xxij) strs+=' '  &

22、#160;         for(m=1;m<=k;m+)        strs+=xxij+m;strs='0'    strcpy(xxi,str);    void main()clrscr();if(ReadDat()printf("數(shù)據(jù)文件IN.DAT不能打開!n007");return;StrOL();WriteDat();int

23、 ReadDat(void)FILE *fp;int i=0;char *p;if(fp=fopen("IN.DAT","r")=NULL) return 1;while(fgets(xxi,80,fp)!=NULL)    p=strchr(xxi,'n');    if(p)*p=0;    i+;maxline=i;fclose(fp);return 0;void WriteDat(void)FILE *fp;int i;clrscr();fp

24、=fopen("OUT6.DAT","w");for(i=0;i<maxline;i+)     printf("%sn",xxi);     fprintf(fp,"%sn",xxi);fclose(fp);*題目5(整數(shù)排序題)在文件in.dat中有200個(gè)正整數(shù),且每個(gè)數(shù)均在1000至9999之間。函數(shù)ReadDat()讀取這200個(gè)數(shù)存放到數(shù)組aa中。請(qǐng)編制函數(shù)jsSort(),其函數(shù)的功能是:要求按每個(gè)數(shù)的后三位的大小進(jìn)

25、行升序排列,然后取出滿足此條件的前10個(gè)數(shù)依次存入數(shù)組bb中,如果后三位的數(shù)值相等,則按原先的數(shù)值進(jìn)行降序排列。最后調(diào)用函數(shù)WriteDat()把結(jié)果bb輸出到文件out.dat中。    例:處理前 6012 5099 9012 7025 8088        處理后 9012 6012 7025 8088 5099    部分源程序存在文件prog1.c中。請(qǐng)勿改動(dòng)主函數(shù)main()、讀數(shù)據(jù)函數(shù)ReadDat()和輸出數(shù)據(jù)函數(shù)Wr

26、iteDat()的內(nèi)容。#include <stdio.h>#include <string.h>#include <conio.h>int aa200,bb10;void jsSort()int i,j,data;for(i=0;i<199;i+)for(j=i+1;j<200;j+)    if(aai%1000>aaj%1000|aai%1000=aaj%1000&&aai<aaj)        

27、60;  data=aai;aai=aaj;aaj=data;for(i=0;i<10;i+)    bbi=aai;void main()readDat();jsSort();writeDat();readDat()FILE *in;int i;in=fopen("in.dat","r");for(i=0; i<200; i+) fscanf(in,"%d,",&aai);fclose(in);writeDat()FILE *out;int i;clrscr();out=f

28、open("out.dat","w");for(i=0; i<10; i+)    printf(" %d",bbi);    fprintf(out,"%dn",bbi);題目6 正整數(shù)排序在文件in.dat中有200個(gè)正整數(shù),且每個(gè)數(shù)均在1000至9999之間。函數(shù)ReadDat()讀取這200個(gè)數(shù)存放到數(shù)組aa中。請(qǐng)編制函數(shù)jsSort(),其函數(shù)的功能是:要求按每個(gè)數(shù)的后三位的大小進(jìn)行降序排列,然后取出滿足此條件的前10個(gè)數(shù)依次存入數(shù)組b中,

29、如果后三位的數(shù)值相等,則按原先的數(shù)值進(jìn)行升序排列。最后調(diào)用函數(shù)WriteDat()把結(jié)果bb輸出到文件out.dat中。例:處理前 9012 5099 6012 7025 8088    處理后 5099 8088 7025 6012 9012    注意:部分源程序已給出。請(qǐng)勿改動(dòng)主函數(shù)main()、讀數(shù)據(jù)函數(shù)ReadDat()和輸出數(shù)據(jù)函數(shù)WriteDat()的內(nèi)容。#include<stdio.h>#include<string.h>#include<conio.h>int

30、 aa200,bb10;void jsSort()int i,j,data;for(i=0;i<199;i+)for(j=i+1;j<200;j+)    if(aai%1000<aaj%1000|aai%1000=aaj%1000&&aai>aaj)           data=aai;aai=aaj;aaj=data;for(i=0;i<10;i+)    bbi=aai;void m

31、ain()readDat();jsSort();writeDat();system("pause");readDat()FILE *in;int i;in=fopen("in.dat","r");for(i=0; i<200; i+) fscanf(in,"%d,",&aai);fclose(in);writeDat()FILE *out;int i;clrscr();out=fopen("out.dat","w");for(i=0; i<10; i+)p

32、rintf("i=%d,%dn",i+1,bbi);fprintf(out,"%dn",bbi);fclose(out);*題目7(結(jié)構(gòu)體操作題)已知在文件IN.DAT中存有100個(gè)產(chǎn)品銷售記錄,每個(gè)產(chǎn)品銷售記錄由產(chǎn)品代碼dm(字符型4位),產(chǎn)品名稱mc(字符型10位),單價(jià)dj(整型),數(shù)量sl(整型),金額je(長(zhǎng)整型)五部分組成。其中:金額=單價(jià)*數(shù)量計(jì)算得出。函數(shù)ReadDat()是讀取這100個(gè)銷售記錄并存入結(jié)構(gòu)數(shù)組sell中。請(qǐng)編制函數(shù)SortDat(),其功能要求:按產(chǎn)品代碼從大到小進(jìn)行排列,若產(chǎn)品代碼相同,則按金額從大到小進(jìn)行排列,最終排

33、列結(jié)果仍存入結(jié)構(gòu)數(shù)組sell中,最后調(diào)用函數(shù)WriteDat()把結(jié)果輸出到文件OUT6.DAT中。    部分源程序存在文件prog1.c中。請(qǐng)勿改動(dòng)主函數(shù)main()、讀數(shù)據(jù)函數(shù)ReadDat()和輸出數(shù)據(jù)函數(shù)WriteDat()的內(nèi)容。#include <stdio.h>#include <mem.h>#include <string.h>#include <conio.h>#include <stdlib.h>#define MAX 100typedef structchar dm5;

34、/*產(chǎn)品代碼*/char mc11; /*產(chǎn)品名稱*/int dj;       /*單價(jià)*/int sl;       /*數(shù)量*/long je;      /*金額*/PRO;PRO sellMAX;void ReadDat();void WriteDat();void SortDat()int i,j;PRO xy;for(i=0;i<99;i+)for(j=i+1;j<100;j+)  

35、;  if(strcmp(selli.dm,sellj.dm)<0|strcmp(selli.dm,sellj.dm)=0&&selli.je<sellj.je)      xy=selli; sell i=sellj; sellj=xy;void main()memset(sell,0,sizeof(sell);ReadDat();SortDat();WriteDat();void ReadDat()FILE *fp;char str80,ch11;int i;fp=fopen("IN.DAT&

36、quot;,"r");for(i=0;i<100;i+)    fgets(str,80,fp);    memcpy(selli.dm,str,4);    memcpy(selli.mc,str+4,10);    memcpy(ch,str+14,4);ch4=0;    selli.dj=atoi(ch);    memcpy(ch,str+18,5);ch5=0; 

37、60;  selli.sl=atoi(ch);    selli.je=(long)selli.dj*selli.sl;fclose(fp);void WriteDat(void)FILE *fp;int i;fp=fopen("OUT6.DAT","w");for(i=0;i<100;i+)printf("%s %s %4d %5d %5dn", selli.dm,selli.mc,selli.dj,selli.sl,selli.je);fprintf(fp,"%s %s %4

38、d %5d %5dn", selli.dm,selli.mc,selli.dj,selli.sl,selli.je);fclose(fp);*題目8(字符替換題)函數(shù)ReadDat()實(shí)現(xiàn)從文件ENG.IN中讀取一篇英文文章,存入到字符串?dāng)?shù)組xx中;請(qǐng)編制函數(shù)encryptChar(),按給定的替代關(guān)系對(duì)數(shù)組xx中的所有字符進(jìn)行替代,仍存入數(shù)組xx的對(duì)應(yīng)的位置上,最后調(diào)用函數(shù)WriteDat()把結(jié)果xx輸出到文件PS1.DAT中。替代關(guān)系:f(p)=p*11 mod 256(p是數(shù)組中某一個(gè)字符的ASCII值,f(p)是計(jì)算后新字符的ASCII值),如果計(jì)算后f(p)值小于等于32

39、或大于130,則該字符不變,否則將f(p)所對(duì)應(yīng)的字符進(jìn)行替代。(注意中間變量用無符號(hào)整型),部分源程序存在文件prog1.c中。原始數(shù)據(jù)文件存放的格式是:每行的寬度均小于80個(gè)字符。請(qǐng)勿改動(dòng)主函數(shù)main()、讀數(shù)據(jù)函數(shù)ReadDat()和輸出數(shù)據(jù)函數(shù)WriteDat()的內(nèi)容。#include <stdio.h>#include <string.h>#include <conio.h>#include <ctype.h>unsigned char xx5080;int maxline=0;/*文章的總行數(shù)*/int ReadDat(void)

40、;void WriteDat(void);void encryptChar() int i,j;for(i=0;i<maxline;i+)     for(j=0;j<strlen(xxi);j+)       if(xxij*11%256<=32|xxij*11%256>130) continue;       else xxij=xxij*11%256;void main()clrscr();if(ReadD

41、at()printf("數(shù)據(jù)文件ENG.IN不能打開!n007");return;encryptChar();WriteDat();int ReadDat(void)FILE *fp;int i=0;unsigned char *p;if(fp=fopen("eng.in","r")=NULL) return 1;while(fgets(xxi,80,fp)!=NULL)    p=strchr(xxi,'n');    if(p)*p=0; 

42、60;  i+;maxline=i;fclose(fp);return 0;void WriteDat(void)FILE *fp;int i;fp=fopen("ps1.dat","w");for(i=0;i<maxline;i+)    printf("%sn",xxi);    fprintf(fp,"%sn",xxi);fclose(fp);*題目9(字符串排序題)函數(shù)ReadDat()實(shí)現(xiàn)從文件IN.DAT中讀取一篇英文文章存入到

43、字符串?dāng)?shù)組xx中,請(qǐng)編制函數(shù)SortCharD(),其函數(shù)的功能是:以行為單位對(duì)字符按從大到小的順序進(jìn)行排序,排序后的結(jié)果仍按行重新存入字符串?dāng)?shù)組xx中,最后調(diào)用函數(shù)writeDat()把結(jié)果xx輸出到文件OUT2.DAT中。    例:原文:dAe,BfC.               CCbbAA        結(jié)果:fedCBA. 

44、              bbCCAA    原始數(shù)據(jù)文件存放的格式是:每行的寬度均小于80個(gè)字符,含標(biāo)點(diǎn)符號(hào)和空格。    部分源程序存在文件prog1.c中。    請(qǐng)勿改動(dòng)主函數(shù)main()、讀數(shù)據(jù)函數(shù)ReadDat()和輸出數(shù)據(jù)函數(shù)writeDat()的內(nèi)容。#include <stdio.h>#include <str

45、ing.h>#include <conio.h>char xx5080;int maxline=0;/*文章的總行數(shù)*/int ReadDat(void);void WriteDat(void);void SortCharD(void)int i,j,k,strl;char ch;for(i=0;i<maxline;i+)strl=strlen(xxi);    for(j=0;j<strl-1;j+)     for(k=j+1;k<strl;k+)    

46、    if(xxij<xxik)         ch=xxij; xxij=xxik; xxik=ch;void main()clrscr();if(ReadDat()printf("數(shù)據(jù)文件IN.DAT不能打開!n007");return;SortCharD();WriteDat();int ReadDat(void)FILE *fp;int i=0;char *p;if(fp=fopen("IN.DAT","r"

47、)=NULL) return 1;while(fgets(xxi,80,fp)!=NULL)    p=strchr(xxi,'n');    if(p)*p=0;    i+;maxline=i;fclose(fp);return 0;void WriteDat(void)FILE *fp;int i;fp=fopen("OUT2.DAT","w");for(i=0;i<maxline;i+)printf("%sn",xx

48、i);fprintf(fp,"%sn",xxi);fclose(fp);*題目10(替換字符題)函數(shù)ReadDat()實(shí)現(xiàn)從文件IN.DAT中讀取一篇英文文章存入到字符串?dāng)?shù)組xx中,請(qǐng)編制函數(shù)ConvertCharA(),其函數(shù)的功能是:以行為單位把字符串中的所有小寫字母改寫成該字母的下一個(gè)字母,如果是字母z,則改寫成字母a。大寫字母仍為大寫字母,小寫字母仍為小寫字母,其他字符不變。把已處理的字符串仍按行重新存入字符串?dāng)?shù)組xx中,最后調(diào)用函數(shù)writeDat()把結(jié)果xx輸出到文件OUT1.DAT中。  例:原文:Adb.Bcdza  

49、;             abck.LLhj        結(jié)果:Aec.Bdeab               bcdl.LLik    原始數(shù)據(jù)文件存放的格式是:每行的寬度均小于80個(gè)字符,含標(biāo)點(diǎn)符號(hào)和空格。

50、60;   部分源程序存在文件prog1.c中。    請(qǐng)勿改動(dòng)主函數(shù)main()、讀數(shù)據(jù)函數(shù)ReadDat()和輸出數(shù)據(jù)函數(shù)writeDat()的內(nèi)容。#include <stdio.h>#include <string.h>#include <conio.h>char xx5080;int maxline=0;/*文章的總行數(shù)*/int ReadDat(void);void WriteDat(void);void ConvertCharA(void) int i,j;for(i=0;i

51、<maxline;i+)     for(j=0;j<strlen(xxi);j+)        if(xxij='z') xxij='a'         else if(xxij>='a'&&xxij<='y') xxij+=1;     void main(

52、)clrscr();if(ReadDat()printf("數(shù)據(jù)文件IN.DAT不能打開!n007");return;ConvertCharA();WriteDat();int ReadDat(void)FILE *fp;int i=0;char *p;if(fp=fopen("IN.DAT","r")=NULL) return 1;while(fgets(xxi,80,fp)!=NULL)    p=strchr(xxi,'n');    if(p)*p=0

53、;    i+;maxline=i;fclose(fp);return 0;void WriteDat(void)FILE *fp;int i;clrscr();fp=fopen("OUT1.DAT","w");for(i=0;i<maxline;i+)    printf("%sn",xxi);    fprintf(fp,"%sn",xxi);fclose(fp);題目11(字符串字母移位題)程序prog1.c的功能

54、是:把 s 字符串中的所有字母改寫成該字母的下一個(gè)字母,字母z改寫成字母a。要求大寫字母仍為大寫字母,小寫字母仍為小寫字母,其它字符不做改變。    請(qǐng)考生編寫函數(shù)chg(char *s)實(shí)現(xiàn)程序要求,最后調(diào)用函數(shù)readwriteDAT( )把結(jié)果輸出到文件bc1.out中。  例如:s 字符串中原有的內(nèi)容為:Mn.123Zxy,則調(diào)用該函數(shù)后,結(jié)果為:No.123Ayz。    注意:部分源程序存在文件prog1.c文件中。    請(qǐng)勿改動(dòng)主函數(shù)mai

55、n( )和輸出數(shù)據(jù)函數(shù)readwriteDAT()的內(nèi)容。#include <conio.h>#include <string.h>#include <stdio.h>#include <ctype.h>#define N 81void readwriteDAT();void chg(char *s)int I;for(I=0;I<strlen(s);I+)if(si='z'|si='Z') si-=25; else if(si>='a'&&si<='y&#

56、39;|si >='A'&&si<='Y') si+=1;main( )char aN;clrscr();printf("Enter a string : "); gets(a);printf("The original string is : "); puts(a);chg(a);printf("The string after modified : ");puts (a);readwriteDAT() ;void readwriteDAT()int i ;char aN

57、;FILE *rf, *wf ;rf = fopen("bc1.in", "r") ;wf = fopen("bc1.out", "w") ;for(i = 0 ; i < 50 ; i+)      fscanf(rf, "%s", a) ;     chg(a) ;     fprintf(wf, "%sn", a) ;fclose(rf) ;fc

58、lose(wf) ;*題目12(結(jié)構(gòu)體運(yùn)算題題)已知在文件IN.DAT中存有100個(gè)產(chǎn)品銷售記錄,每個(gè)產(chǎn)品銷售記錄由產(chǎn)品代碼dm(字符型4位),產(chǎn)品名稱mc(字符型10位),單價(jià)dj(整型),數(shù)量sl(整型),金額je(長(zhǎng)整型)五部分組成。其中:金額=單價(jià)*數(shù)量計(jì)算得出。函數(shù)ReadDat()是讀取這100個(gè)銷售記錄并存入結(jié)構(gòu)數(shù)組sell中。請(qǐng)編制函數(shù)SortDat(),其功能要求:按產(chǎn)品名稱從小到大進(jìn)行排列,若產(chǎn)品名稱相等,則按金額從小到大進(jìn)行排列,最終排列結(jié)果仍存入結(jié)構(gòu)數(shù)組sell中,最后調(diào)用函數(shù)WriteDat()把結(jié)果輸出到文件OUT5.DAT中。   &

59、#160;部分源程序存在文件prog1.c中。請(qǐng)勿改動(dòng)主函數(shù)main()、讀數(shù)據(jù)函數(shù)ReadDat()和輸出數(shù)據(jù)函數(shù)WriteDat()的內(nèi)容。#include <stdio.h>#include <mem.h>#include <string.h>#include <conio.h>#include <stdlib.h>#define MAX 100typedef structchar dm5; /*產(chǎn)品代碼*/char mc11; /*產(chǎn)品名稱*/int dj;      

60、; /*單價(jià)*/int sl;       /*數(shù)量*/long je;      /*金額*/PRO;PRO sellMAX;void ReadDat();void WriteDat();void SortDat()int i,j;PRO xy;for(i=0;i<99;i+)for(j=i+1;j<100;j+)     if(strcmp(selli.mc,sellj.mc)>0|strcmp(selli.mc,sellj

61、.mc)=0&&selli.je>sellj.je)        xy=selli;selli=sellj;sellj=xy;void main()memset(sell,0,sizeof(sell);ReadDat();SortDat();WriteDat();void ReadDat()FILE *fp;char str80,ch11;int i;fp=fopen("IN.DAT","r");for(i=0;i<100;i+)  &

62、#160; fgets(str,80,fp);    memcpy(selli.dm,str,4);    memcpy(selli.mc,str+4,10);    memcpy(ch,str+14,4);ch4=0;    selli.dj=atoi(ch);    memcpy(ch,str+18,5);ch5=0;    selli.sl=atoi(ch);    selli.j

63、e=(long)selli.dj*selli.sl;fclose(fp);void WriteDat()FILE *fp;int i;fp=fopen("OUT5.DAT","w");for(i=0;i<100;i+)printf("%s %s %4d %5d %5dn",selli.dm,selli.mc,selli.dj,selli.sl,selli.je);fprintf(fp,"%s %s %4d %5d %5dn", selli.dm,selli.mc,selli.dj,selli.sl,selli

64、.je);fclose(fp);*題目13(結(jié)構(gòu)體運(yùn)算題)已知在文件IN.DAT中存有100個(gè)產(chǎn)品銷售記錄,每個(gè)產(chǎn)品銷售記錄由產(chǎn)品代碼dm(字符型4位),產(chǎn)品名稱mc(字符型10位),單價(jià)dj(整型),數(shù)量sl(整型),金額je(長(zhǎng)整型)五部分組成。其中:金額=單價(jià)*數(shù)量計(jì)算得出。函數(shù)ReadDat()是讀取這100個(gè)銷售記錄并存入結(jié)構(gòu)數(shù)組sell中。請(qǐng)編制函數(shù)SortDat(),其功能要求:按產(chǎn)品代碼從小到大進(jìn)行排列,若產(chǎn)品代碼相等,則按金額從大到小進(jìn)行排列,最終排列結(jié)果仍存入結(jié)構(gòu)數(shù)組sell中,最后調(diào)用函數(shù)WriteDat()把結(jié)果輸出到文件OUT9.DAT中。  &#

65、160; 部分源程序存在文件prog1.c中。請(qǐng)勿改動(dòng)主函數(shù)main()、讀數(shù)據(jù)函數(shù)ReadDat()和輸出數(shù)據(jù)函數(shù)WriteDat()的內(nèi)容。#include <stdio.h>#include <mem.h>#include <string.h>#include <conio.h>#include <stdlib.h>#define MAX 100typedef structchar dm5; /*產(chǎn)品代碼*/char mc11; /*產(chǎn)品名稱*/int dj;     

66、  /*單價(jià)*/int sl;       /*數(shù)量*/long je;      /*金額*/PRO;PRO sellMAX;void ReadDat();void WriteDat();void SortDat()int i,j;PRO xy;for(i=0;i<99;i+)for(j=i+1;j<100;j+)     if(strcmp(selli.dm,sellj.dm)>0|strcmp(selli.dm,

67、sellj.dm)=0&&selli.je<sellj.je)        xy=selli;selli=sellj;sellj=xy;void main()memset(sell,0,sizeof(sell);ReadDat();SortDat();WriteDat();void ReadDat()FILE *fp;char str80,ch11;int i;fp=fopen("IN.DAT","r");for(i=0;i<100;i+) &#

68、160;  fgets(str,80,fp);    memcpy(selli.dm,str,4);    memcpy(selli.mc,str+4,10);    memcpy(ch,str+14,4);ch4=0;    selli.dj=atoi(ch);    memcpy(ch,str+18,5);ch5=0;    selli.sl=atoi(ch);    selli.je=(long)selli.dj*selli.sl;fclose(fp);void WriteDat()FILE *fp;int i;fp=fopen("OUT9.DAT","w");for(i=0;i<100;i+)printf("%s %s %4d %5d %5dn", selli.dm,selli.mc,selli.dj,selli.sl,selli.je);fprintf(fp,"%s %s %4d %5d %5dn", selli.dm,selli.mc

溫馨提示

  • 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請(qǐng)下載最新的WinRAR軟件解壓。
  • 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請(qǐng)聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
  • 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會(huì)有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
  • 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
  • 5. 人人文庫網(wǎng)僅提供信息存儲(chǔ)空間,僅對(duì)用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對(duì)用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對(duì)任何下載內(nèi)容負(fù)責(zé)。
  • 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請(qǐng)與我們聯(lián)系,我們立即糾正。
  • 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時(shí)也不承擔(dān)用戶因使用這些下載資源對(duì)自己和他人造成任何形式的傷害或損失。

最新文檔

評(píng)論

0/150

提交評(píng)論