第1题
请在程序的下划线处填人正确的内容并将下划线删除,使程序得出正确的结果。注意:部分源程序在文件BLANKl.C中.不得增行或删行,也不得更改程序的结构!
第3题
第4题
第5题
第6题
第7题
注意:不改动程序结构,不得增行或删行。
package ch3;
import java.io.*;
class File1
{
private char ch;
private int i='a'-'A';
void savetoFile()
{
System.out.println("请输入一个字符串:");
try
{
______out=new______("ch3/file.txt");
while((ch=(char)System.in.______()) !='')
{
if(ch >='a' && ch <='z')
ch=(char) ((int)ch-i);
out.______;
}
out.close();
}
catch(IOException e)
{
e.printStackTrace();
}
}
}
public class ex3
{
public static void main(String[] args)
{
File1 bj=new File1();
Obj.savetoFile();
}
}
第8题
第9题
[说明] 从键盘输入一个字符ch,输出该字符在文本文件input.txt 的每一行中出现的次数。(必须调用函数鳋统计ch的出现次数,函数ff (str,ch)的功能是统计并返回字符ch在字符串str 中出现的次数。)。
例如:如果文件input. txt 中存放了下列数据:
every
121
I am a student
运行程序,并输入e后,输出:
2
0
1
int ff( char * str, char ch)
{ int count =0;
while ((1)) {
if( *str= =ch) count++;
str ++;
}
return count;
}
include < stdio. h >
include < stdlib. h >
void main( )
{ char ch, c, s [80];
int k;
FILE *fp;
if((2)){
printf( “打不开文件!n”); return;
}
ch = getchar( );
k=0;
while( ! feof(fp) ) {
c = fgete(fp);
if (3)
s[k++ ] =c;
else {
s[k]= ";
printf ( "%dn" ,ff(s, ch) );
k=0;
}
}
(4)
printf( "% dn", ff( s, ch ) );
}
第10题
阅读下列函数说明和C代码,将应填入(n)处的字句写在答题纸的对应栏内。
【说明】
以下程序的功能是:从键盘上输入一个字符串,把该字符串中的小写字母转换为大写字母,输出到文件test.txt中,然后从该文件读出字符串并显示出来。
【程序】
#include<stdio.h>
main()
{FILE*fp;
charstr[100];inti=0;
if((fp=fopen("text.txt" (1) ))==NULL)
{printf("can't open this file.\n");exit(0);}
printf("input astring:\n");gest(str);
while(str[i])
{if(str[i]>=′a′ && str[i]<=′z′)
str[i]= (2) ;
fputc(str[i], (3) );
i++;
}
fclose(fp);
fp=fopen("test.txt", (4) );
fgets(str,100,fp);
printf("%s\n",str);
(5) ;
}
为了保护您的账号安全,请在“上学吧”公众号进行验证,点击“官网服务”-“账号验证”后输入验证码“”完成验证,验证成功后方可继续查看答案!