DCDC
DCBA
BABA
ABCD
第1题:
使用VC6打开考生文件夹下的工程test11_1,此工程包含一个源程序文件test11_1.cpp,但该程序运行有问题,请改正程序中的错误,使程序的输出结果如下:
ch1=7 ch2=9
源程序文件test11_1.cpp清单如下:
include<iostream.h>
class Sample
{
/**************** found ***************/
char ch1,ch2
public:
/************** found ***************/
friend void set(Sample s, char c1,char c2)
{
s.ch1=c1;
s.ch2=c2;
}
void print() {cout<<"ch1="<<" ch2="<<ch2<<end1;}
};
void main()
{
Sample obj;
/************* found ****************/
obj.set(obj,'7','9');
obj.print();
}
第2题:
在执行以下程序时,如果从键盘上输入ABCdef<回车>,则输出为______。#include <stdio.h>main (){ char ch; while ((ch=getchar())!="\n") { if (ch>='A'&& ch<='B')ch=ch+32; else if (ch>='a'&& ch<='z')ch=ch-32; printf("%c",ch); } printf("\n");}
A.ABCdef
B.abcDEF
C.abc
D.DEF
第3题:
有以下程序: #include<stdio.h> union pw { int i; char ch[2]; }a; main() { a.ch[0]=13;a.ch[1]=0;printf("%d\n",a.i);} 程序的输出结果是( )。
A.13
B.14
C.208
D.209
第4题:
请编写函数fun(),它的功能是:求出ss所指字符串中指定字符的个数,并返回此值。
例如,若输入字符串123412132,输入字符1,则输出3。
注意:部分源程序给出如下。
请勿改动主函数main和其他函数中的任何内容,仅在函数fun的花括号中填入所编写的若干语句。
试题程序:
include<coio.h>
include<stdio.h>
define M 81
int fun(char *ss,char c)
{
}
main()
{ char a[M],ch;
clrscr();
printf("\nPlease enter a string:");
gets(a);
printf("\nPlease enter a char:");
ch=getchar();
printf("\nThe number of the char is:%d \n",fun(a,ch));
}
第5题:
下列程序的输出结果是【 】。
include<iostream>
include<cstring>
using namespace std;
void fun(const char *s,char &c){c=s[strlen(s)/2];}
int main()
{
char str[]="ABCDE";
char ch=str[1];
fun(str,ch);
cout<<ch;
return 0;
}
第6题:
有如下程序 #include<stdio.h> main() { int v1=0,v2=0; char ch; while((ch=getchar())!='#') switch(ch) { case 'a'; casff 'h'; default:v1++; case '0';v2++; } printf("%d,%d\n",v1,v2); } 如果从键盘上输入china#<回车>,则程序运行结果为 ( )
A.2,0
B.5,0
C.5,5
D.2,5
第7题:
有以下程序:
include <fstream>
include <string>
using namespace std;
int main ()
{
char ch[] = "The end";
ofstream outstr( "d:\\put.txt", ios_base: :app);
for (int i = 0; i < strlen( ch ); i++ )
outstr.put(ch[i]);
outstr.close();
return 0;
}
程序实现的功能是【 】。
第8题:
下列程序段中,不能正确赋值的是
A.char*p,ch; p=&ch; scanf("%c,&p")
B.char*p; p=(char*)malloc(1); scanf("%c",p);
C.char*p; *p=getchar();
D.char*p,ch; p=缸h; *p=getchar();
第9题:
以下程序的执行结果为【 】。
include<iostream>
using namespace std;
void overload(int num)
{
cout<<num<<end1;
}
void overload(char ch)
{
char c=ch+1;
cout<<c<<end1;
}
int main()
{
overload('X');
return 0;
}
第10题:
有以下程序:
include <stdio.h>
main()
{ char ch1,ch2;int n1,n2;
ch1=getchar();ch2=getehar();
n1=ch1-'0'; n2=n1*10+(ch2-'0');
printf("%d\n",n2);
}
程序运行时输入:12<回车>,执行后的输出结果是【 】。
第11题:
有以下程序: #include <stdio.h> union pw { int i; char ch[2]; } a; main() { a.ch[0]=13; a.ch[1]=0; printf("%d\n",a.i); } 程序的输出结果是(注意:ch[0]在低字节,ch[1]在高字节)( )。
A.13
B.14
C.208
D.209
第12题:
ABCDDCBA
ABCD
A
DCBA
第13题:
下列程序段中,不能正确赋值的是( )。
A.char*p,ch; p=&Ch; scanf("%c",&p);
B.char*p; p=char*)malloc(1); scanf("%c",p);
C.char*p; *p=getchar();
D.char*p,ch; p=&ch; *p=getchar();
第14题:
执行下面的程序时,输入abc<CR>(其中CR代表回车),输出结果是( )。 #include<stdio.h> #include <string.h> main() { char ch; while((cn=getchar())!='n') { switch(ch-'a') { case 0: putchar(ch+1); case 1:putchar(ch+1);break; case 2:putchar(ch+2); caSe 3:putchar(ch+2);break; } } }
A.abc
B.bbc
C.abcd
D.bbcee
第15题:
以下程序的输出结果是( )。 #include <stdio.h> charcchar(char eh) { if(ch>='A,&&ch<='Z') ch=ch-'A'+'a'; return ch; } main() { char s[]="ABC+abc=defDEF",*p=s; while(*p) { *p=cchsr(*p); p++; } printf("%s\n",s); }
A.abc+ABC=DEFdef
B.abc+abc=defdef
C.abcABCDEFdef
D.abcabcdefdef
第16题:
当执行以下程序时,输入1234567890<回车>,则其中while循环体将执行【 】次。
include<stdio.h>
main()
{ char ch;
while((ch=getchar())=='0')prinft("");
}
第17题:
下列程序运行时,若输入labcedf2df<回车>输出结果为【 】。
include<stdio.h>
main()
{ char a=0,ch;
while((ch==getchar())!='\n')
{ if(a%2!=0&&(ch>='a'&&ch<='z')) ch=ch'a'+'A';
a++;prtchar(ch);
}
printf("\n");
}
第18题:
下面程序输出的结果是( )。 #include<iostream> using namespace std; void main() { char ch[][8]={"good","better","best"}; for(int i=1;i<3;++i) { cout<<ch[i]<<endl; } }
A.good better
B.better best
C.good best
D.good
第19题:
下列程序的输出结果是______。
include <iostream.h>
include <cstring.h>
using namespace std;
void fun(const char*s,char &C) {c=s[strlen (s)/2];}
int main {)
{
char str [] ="ABCDE";
char ch=str[1];
fun(str,sh);
cout<<Ch;
return 0;
}
第20题:
有以下程序: #include <iostream> #include <fstream> using namespace std; int main ( ) { ofstream ofile; char ch; ofile.open ("abc.txt"); cin>>ch; while (ch!='#' ) { cin>>ch; ofile.put(ch);
A.程序编译时出错
B.abc#
C.abc
D.#
第21题:
运行下面程序时,从键盘输入字母H,则输出结果是 #include<stdio.h> main() { char ch; ch=getchar(); switch(ch) { case 'H':printf("Hello!\n"); case 'G':printf("Good morning!\n"); default:printf("Bye_Bye!\n"); } }
A.Hello!
B.Hello! GoodMoring!
C.Hello! Goodmorning! Bye_Bye!
D.Hello! Bye_Bye!
第22题:
A.Z
B.Y
C.B
D.A
第23题:
1234
4321
4444
1111