学习坊广告 网站建设咨询电话0711-3202220 、 QQ:215665888        将学习坊设为主页     广告赞助QQ:410899793     主页申请

计算机三级C语言上机试题总结(之三)

来源:网络 【www.cn0711.net】   作者:未知【学习坊转】 [字体: ]

160
91
5517.16


200个四位数之三(共四题)
code:
/*
已知在文件IN.DAT中存有若干个(个数<200)四位数字的正整


数, 函数ReadDat( )读取这若干个正整数并存入数组xx中。请编
制函数Calvalue( ), 其功能要求: 1. 求出这文件中共有多少个
正整数totNum; 2. 求这些数右移1位后, 产生的新数是奇数的数
的个数totCnt, 以及满足此条件的这些数(右移前的值)的算术平
均值totPjz。最后main()函数调用函数WrITeDat()把所求的结果
输出到文件OUT.DAT中。
注意: 部分源程序存放在PROG1.C中。
请勿改动数据文件IN.DAT中的任何数据,主函数main()、读
数据函数ReadDat()和输出数据函数WrITeDat()的内容。
*/
#include
#include
#define MAXNUM 200

int xx[MAXNUM] ;
int totNum = 0 ; /* 文件IN.DAT中共有多少个正整数 */
int totCnt = 0 ; /* 符合条件的正整数的个数 */
double totPjz = 0.0 ; /* 平均值 */

int ReadDat(void) ;
void WrITeDat(void) ;

void Calvalue(void)
{/**/
for(; xx[totNum]; totNum++)
if((xx[totNum]>>1)%2)
{ totCnt++; totPjz+=xx[totNum];}
if(totCnt) totPjz/=totCnt;
/**/
}

void main()
{
int i ;
clrscr() ;
for(i = 0 ; i < MAXNUM ; i++) xx[i] = 0 ;
if(ReadDat()) {
printf(数据文件IN.DAT不能打开!\007\n) ;
return ;
}
Calvalue() ;
printf(文件IN.DAT中共有正整数=%d个\n, totNum) ;
printf(符合条件的正整数的个数=%d个\n, totCnt) ;
printf(平均值=%.2lf\n, totPjz) ;
WrITeDat() ;
}

int ReadDat(void)
{
FILE *fp ;
int i = 0 ;

if((fp = fopen(in.dat, r)) == NULL) return 1 ;
while(!feof(fp)) {
fscanf(fp, %d,, &xx[i++]) ;
}
fclose(fp) ;
return 0 ;
}

void WrITeDat(void)
{
FILE *fp ;

fp = fopen(OUT.DAT, w) ;
fprintf(fp, %d\n%d\n%.2lf\n, totNum, totCnt, totPjz) ;
fclose(fp) ;
}

out.dat 文件内容应当如下:
160
80
5537.54

小于200个四位数之四(共四题)
code:
/*
已知在文件IN.DAT中存有若干个(个数<200)四位数字的正整
数, 函数ReadDat( )读取这若干个正整数并存入数组xx中。请编
制函数Calvalue( ), 其功能要求: 1. 求出这文件中共有多少个
正整数totNum; 2. 求这些数右移1位后, 产生的新数是偶数的数
的个数totCnt, 以及满足此条件的这些数(右移前的值)的算术平
均值totPjz。最后main()函数调用函数WrITeDat()把所求的结果
输出到文件OUT.DAT中。
注意: 部分源程序存放在PROG1.C中。
请勿改动数据文件IN.DAT中的任何数据,主函数main()、读
数据函数ReadDat()和输出数据函数WrITeDat()的内容。
*/
#include
#include
#define MAXNUM 200

int xx[MAXNUM] ;
int totNum = 0 ; /* 文件IN.DAT中共有多少个正整数 */
int totCnt = 0 ; /* 符合条件的正整数的个数 */
double totPjz = 0.0 ; /* 平均值 */

int ReadDat(void) ;
void WrITeDat(void) ;

void Calvalue(void)
{/**/
for(; xx[totNum]>0; totNum++)
if((xx[totNum]>>1)%2==0)
{ totCnt++; totPjz+=xx[totNum]; }
if(totCnt) totPjz/=totCnt;
/**/
}

void main()
{
int i ;
clrscr() ;
for(i = 0 ; i < MAXNUM ; i++) xx[i] = 0 ;
if(ReadDat()) {
printf(数据文件IN.DAT不能打开!\007\n) ;
return ;
}
Calvalue() ;
printf(文件IN.DAT中共有正整数=%d个\n, totNum) ;
printf(符合条件的正整数的个数=%d个\n, totCnt) ;
printf(平均值=%.2lf\n, totPjz) ;
WrITeDat() ;
}

int ReadDat(void)
{
FILE *fp ;
int i = 0 ;

if((fp = fopen(in.dat, r)) == NULL) return 1 ;
while(!feof(fp)) {
fscanf(fp, %d,, &xx[i++]) ;
}
fclose(fp) ;
return 0 ;
}

void WrITeDat(void)
{
FILE *fp ;

fp = fopen(OUT.DAT, w) ;
fprintf(fp, %d\n%d\n%.2lf\n, totNum, totCnt, totPjz) ;
fclose(fp) ;
}

out.dat 文件内容应当如下:
160
80
5447.93

英文文章——字符串处理(共10题)
之一

code:
/*
函数ReadDat( )实现从文件IN.DAT中读取一篇英文文章存入到
字符串数组xx中; 请编制函数SortCharD( ), 其函数的功能是: 以
行为单位对字符按从大到小的顺序进行排序, 排序后的结果仍按行
重新存入字符串数组xx中。最后main()函数调用函数WrITeDat()把
结果xx输出到文件OUT2.DAT中。
例: 原文: dAe,BfC.
CCbbAA
结果: fedCBA.,
bbCCAA
原始数据文件存放的格式是: 每行的宽度均小于80个字符, 含
标点符号和空格。
注意: 部分源程序存放在PROG1.C中。
请勿改动主函数main( )、读数据函数ReadDat()和输出数据函
数WrITeDat()的内容。
*/
#include <stdio.h>
#include <string.h>
#include <conio.h>

char xx[50][80] ;
int maxline = 0 ; /* 文章的总行数 */

int ReadDat(void) ;
void WrITeDat(void) ;

void SortCharD(void)
{/**/
int i,j,k,m,n; char ch;
for(i=0; i < maxline; i++)
{ j=strlen(xx[i]);
for(m=0; m < j-1; m++)
{ k=m;
for(n=m+1; n < j; n++)
if(xx[i][k] < xx[i][n]) k=n;
if(k!=m)
{ ch=xx[i][k]; xx[i][k]=xx[i][m]; xx[i][m]=ch; }
}
}

/**/
}

void main()
{
clrscr() ;
if(ReadDat()) {
printf(数据文件IN.DAT不能打开!\n\007) ;
return ;
}
SortCharD() ;
WrITeDat() ;
}

int ReadDat(void)
{
FILE *fp ;
int i = 0 ;
char *p ;

if((fp = fopen(IN.DAT, r)) == NULL) return 1 ;
while(fgets(xx[i], 80, fp) != NULL) {
p = strchr(xx[i], \n) ;
if(p) *p = 0 ;
i++ ;
}
maxline = i ;
fclose(fp) ;
return 0 ;
}

void WrITeDat(void)
{
FILE *fp ;
int i ;

clrscr() ;
fp = fopen(OUT2.DAT, w) ;
for(i = 0 ; i < maxline ; i++) {
printf(%s\n, xx[i]) ;
fprintf(fp, %s\n, xx[i]) ;
}
fclose(fp) ;
}


in.dat 文件内容为:
You can create an index on any field, on several fields to be
used
together, or on parts thereof, that you want to use as a key.
The
keys in indexes allow you quick access to specific records and
define
orders for sequential processing of a ISAM file. After you no
longer
need an index, you can delete IT. AddITion and indexes have no
effect
on the data records or on other indexes.
You may want a field in field in each record to uniquely
identify that
record from all other records in the file. For example, the
Employee
Number field is unique if you do not assign the same number to
two
different employees, and you never reassign these numbers to
other
employees. If you wish to find or modify the record belonging
to a
specific employee, this unique field saves the thouble of
determining
whether you have the correct record.
If you do not have a unique field, you must find the first
record
the matches your key and determine whether the record is the
one you
want. If IT is not the correct one, you must search again to
find others.
If you know that you have a unique field wIThin your records,
you
can include this fact in the key description, and ISAM will
allow only
unique keys. For example, if you specify that the employee
numbers are
unique, ISAM only lets you add records to the file for, or
change
numbers to, employee numbers that do not alreadly exist int
file.

out2.dat 文件内容应当为:
yxvuuttsssrroooonnnnnnllliiiffeeeeeeeeeddddccbaaaaaY,
yywuuttttttttsssrrrrpoooooonnkhhhhgfeeeeeeeaaaaaT.,,
yyxwuutssssssrrqpoooonnnnllkkiiiiiiffeeeeeeeeddddccccccaaa
yuuttssssrrrrrrqpooooooonnnnllliiiggffffeeeeeeedcaaSMIAA.
yxxvuttttsooonnnnnnnnliiiiihffeeeeeeeeeeedddddddccaaaaA.,
xtttssrrrrooooonnnihheeeeedddcaa.
yyywuuutttttrrqooonnnnnmllliiiiiiihhfffeeeeeeddddccaaaaaY
yxtttsrrrrrrrppoooooonmmmllllliihhhffeeeeeeeeeeddccaaFE.,
ywuuuuuttttssssrrqooooonnnnmmmliiiiihgffeeeeeeddbbaaN
yyvuuttttsssssrrrrrpoooonnnnnmmliihhgffeeeeeeeeeeeeddbaa,
yyywutttssrrrpoooooooonnnmmlliiiihhggfffeeeeeedddcbaI.
yvuuuttttssssrqppooonnnmmllliiiiiiihhhgfffeeeeeeeeeeeddccba,
ywvutttrrrrrooohhhheeeeeedccca.
yyvuuuuuttttssrrrqooooonnnmliiiihhffffeeeeeddddcaaI,
yyywuuttttttssrrrrroooonnnmmkiihhhhhheeeeeeeeeeeedddccaa
ywuuttttttttssssrrrroooooonnnnnmiiiihhhgffeeeeedcccaaaaI..,
yyyywwvuuuuuutttsrrrqoooooonnnlkiiiihhhffeeeeddcaaaI,
yywwuttttssrpooonnnnnnllllllkiiiiiihhfeeeedddccccaaaaSMIA,
yyyyxuuuutttsssrrrqpppooonnmmmllkiiihhffeeeeeeeeeeecbaaaF.,
yyuuutttssrrrrqoooooonnnllliihhgffeeeeeedddccaaSMIA,,
yyxuuttttttsssrrrpoooonnnnmmmlllliiihfeeeeeeeeddbbaaa.,


字符串处理之二
code:
/*
函数ReadDat( )实现从文件IN.DAT中读取一篇英文文章存入
到字符串数组xx中; 请编制函数ConvertCharA(), 其函数的功能
是: 以行为单位把字符串中的所有小写字母改写成该字母的下一
个字母, 如果是字母z, 则改写成字母a,大写字母和其它字符保
持不变。把已处理的字符串仍按行重新存入字符串数组xx中。最
后main()函数调用函数WrITeDat()把结果xx输出到文件OUT3.DAT
中。
例: 原文: Adb.Bcdza
abck.LLhj
结果: Aec.Bdeab
bcdl.LLik
原始数据文件存放的格式是: 每行的宽度均小于80个字符, 含
标点符号和空格。
注意: 部分源程序存放在PROG1.C中。
请勿改动主函数main( )、读数据函数ReadDat()和输出数据函
数WrITeDat()的内容。
*/
#include
#include
#include

char xx[50][80] ;
int maxline = 0 ; /* 文章的总行数 */

int ReadDat(void) ;
void WrITeDat(void) ;

void ConvertCharA(void)
{/**/
int i,j;
for(i=0; i < maxline; i++)
for(j=0; j < strlen(xx[i]); j++)
if(xx[i][j]==z) xx[i][j]=a;
else if((xx[i][j]>=a)&&(xx[i][j]<z)) xx[i][j]++;
/**/
}

void main()
{
clrscr() ;
if(ReadDat()) {
printf(数据文件IN.DAT不能打开!\n\007) ;
return ;
}
ConvertCharA() ;
WrITeDat() ;
}

int ReadDat(void)
{
FILE *fp ;
int i = 0 ;
char *p ;

if((fp = fopen(IN.DAT, r)) == NULL) return 1 ;
while(fgets(xx[i], 80, fp) != NULL) {
p = strchr(xx[i], \n) ;
if(p) *p = 0 ;
i++ ;
}
maxline = i ;
fclose(fp) ;
return 0 ;
}

void WrITeDat(void)
{
FILE *fp ;
int i ;

clrscr() ;
fp = fopen(OUT3.DAT, w) ;
for(i = 0 ; i < maxline ; i++) {
printf(%s\n, xx[i]) ;
fprintf(fp, %s\n, xx[i]) ;
}
fclose(fp) ;
}


out3.dat文件内容应当如下:
Ypv dbo dsfbuf bo joefy po boz gjfme, po tfwfsbm gjfmet up cf
vtfe
uphfuifs, ps po qbsut uifsfpg, uibu zpv xbou up vtf bt b lfz.
Tif
lfzt jo joefyft bmmpx zpv rvjdl bddftt up tqfdjgjd sfdpset boe
efgjof
psefst gps tfrvfoujbm qspdfttjoh pg b ISAM gjmf. Agufs zpv op
mpohfs
offe bo joefy, zpv dbo efmfuf ju. Aeejujpo boe joefyft ibwf op
fggfdu
po uif ebub sfdpset ps po puifs joefyft.
Ypv nbz xbou b gjfme jo gjfme jo fbdi sfdpse up vojrvfmz




 

录入:学习坊

查看对 计算机三级C语言上机试题总结(之三) 的评论 【 发表见解 】 【 查看见解 】 【 打印资料 】  
上一篇:100个产品销售记录排序(此类共10题)
下一篇:
百度中>“计算机三级C语言上机试题总结(之三)”相关内容 google中>“计算机三级C语言上机试题总结(之三)”相关内容
雅虎中>“计算机三级C语言上机试题总结(之三)”相关内容 搜狗中>“计算机三级C语言上机试题总结(之三)”相关内容
中搜中>“计算机三级C语言上机试题总结(之三)”相关内容 爱问中>“计算机三级C语言上机试题总结(之三)”相关内容