有以下程序#include<stdio.h>int f(int x);main(){int n=1,m;m=f(f(f(n)));printf(”%d\n”,m);}int f(int x){return x*2;}程序运行后的输出结果是()。
A.1
B.2
C.4
D.8
A.1
B.2
C.4
D.8
有以下程序: #include < stdio. h > main () int a=3,b=4,c=5,d=2; if(a>b) if(b>c)printf("%d",d++ +1); else printf("% d", + + d + 1 ); printf("% d \n" ,d); 程序运行后的输出结果是()。
A.2
B.3
C.43
D.44
有以下程序#include<stdio. h>main(){ char c1='1',c2='2'; c1=getchar(); c2=getchar(); putchar(c1); putchar(c2);} 当运行时输入:a<回车> 后,以下叙述正确的是
A.变量c1被赋予字符a,c2被赋予回车符
B.程序将等待用户输入第2个字符
C.变量c1被赋予字符a,c2中仍是原有字符2
D.变量c1被赋予字符a,c2中将无确定值
下列程序段的输出结果为()。#include<stdio. h>main(){ static char a[]="language"; char*p; p=a; for(p=a;p<a+8;p+=2) putchar(*p);}
A.language
B.lnug
C.有语法错误
D.lang
以下程序打开新文件f.txt,并调用字符输出函数将a数组中的字符写入其中,请填空。
include<stdio.h>
main()
{________*fp;
char a[5]=(’1’,’2’,’3’,’4’,’5’),i;
fp=fopen(”f.txt”,”w”);
for(i=0;i<5;i++)fputc(a[i],fp);
fclose(fp);
}
阅读以下说明和C++程序,将应填入(n)处的字句写在对应栏内。
【C++程序】
include < stdio. h >
include < string. h >
define Max 1000
class Bank
{
int index;
char date [Max] [10]; // 记录交易日
iht amount[Max]; // 记录每次交易金额,以符号区分存钱和取钱
int rest[ Max]; // 记录每次交易后余额
static iht sum; // 账户累计余额
public:
Bank() {index =0;}
void deposit(char d[ ] , int m) //存入交易
{
strcpy (date [ index ], d);
amount[ index] = m;
(1);
rest[ index] = sum;
index++;
}
void withdraw (char d[ ], int m) //取出交易
{
strcpy(date[ index] ,d);
(2);
(3);
rest[ index] = sum;
index++;
}
void display();
};
int Bank:: sum = 0;
void Bank:: display () //输出流水
{
int i;
printf("日期 存入 取出 余额\n");
for (4)
{
printf(" %8s" ,date[i] );
if (5)
printf(" %6d" , -amount[i] );
else
printf("%6d ",amount[i] );
printf("% 6d\n" ,rest[i] );
} }
void main()
{
Bank object;
object. deposit ("2006.2.5", 1 00 );
object. deposit("2006.3.2" , 200);
object. withdraw("2006.4.1", 50);
object. withdraw("2006.4.5", 80);
object. display ();
}
本程序的执行结果如下:
日期 存入 取出 余额 2006.2.5 100 100
2006.3.2 200 300
2006.4.1 50 250
2006.4.5 80 170
阅读以下说明和C++程序,将应填入(n)处的字句写在答题纸的对应栏内。
【说明】
本程序用于评选优秀教师和学生。当输入一系列教师或学生的记录后,将优秀学生及教师的姓名列出来。其类结构如下图所示:
【程序】
include <iostream.h>
include <stdio. h>
class base
{
protected:
char name[8];
public:
void getname(){cout<<"name:"; cin>>name;}
void printname(){cout<<"name:"<<name<<endl;}
(1)
};
class student: (2)
{
int num;
public:
void getnum()
{cout<<"score:"; cin>>num;}
bool isgood()
{return (3) }
};
class teacher: (2)
{
int num;
public:
void getnum()
{cout<<"paper:"; cin>>num;}
bool isgood()
{return (num>3)?true:false;}
void main()
{
base *p[50];
student *pstud;
teacher *ptech;
char ch;
int count=0;
do{
cout<<"input teacher(t) or student(s):";
cin>>ch;
if(ch=='s')
{
pstud=new student;
pstud->getname();
pstud->getnum();
p[count++]=pstud;
}
else if(ch=='t')
{
(4)
ptech->getname();
ptech->getnum();
p[count++]=ptech;
}
else
cout<<"input is wrong"<<endl;
cout<<"continue to iput(y/n)?";
cin>>ch;
}while(ch=='y');
for(int i=0;i<count;i++)
if((5))
p[i]->printname();
}
下列给定程序中,函数fun()的功能是;求S的值。设 S=(22/1*30))*(42/(3*5))*(62/(5*7))*…*(2k)2/((2k-1)*(2k+1))
例如,当k为10时,函数的值应为1.533852。
请改正程序中的错误,使它能得出正确的结果。
注童;不要改动main 函数,不得增行或删行,也不得更改程序的结构。
试题程序:
include <conio. h>
include <stdio. h>
include <math.h >
/**************found***************/
fun (int k)
{ iht n; float s, w, p, q;
n=1;
s=1.0;
while (n<=k)
{ w=2. 0*n;
p=w-1.0;
q=w+1.0;
s=s*w*w/p/q;
n++;
}
/***************found**************/
return s
}
main()
{ clrscr ();
printf ("%f\n ", fun (10));
}
请编写函数fun(),该函数的功能是:计算并输出
S=1+(1+20.5)+(1+20.5+30.5)+…+(1+20.5+30.5+…+n0.5)
例如,若主函数从键盘给n输入20后,则输出为
s=534.188884。
注意;部分源程序给出如下。
请勿改动主函数main 和其他函数中的任何内容,仅在函数fun 的花括号中填入所编写的若干语句。
试题程序:
include <math. h>
include <stdio. h>
double fun(int n)
{
}
main()
{
int n;
double s;
printf("\n\nInput n: ");
scanf ("%d", &n);
s=fun (n)
printf ("\n\ns=%f\n\n", s);
}
下列给定程序中,函数fun()的功能是:根据整型参数m,计算如下公式的值。
y=1/(100×100)+1/(200×200)+1/(300×300)+…+1/(m×m)
例如,若m=2000,则应输出0.000160。
请改正程序中的错误,使它能得出正确的结果。
注意:不要改动main函数,不得增行或删行,也不得更改程序的结构。
试题程序:
include <conio.h>
include <stdio. h>
/*************found**************/
fun (int m)
{ double y=0, d;
int i;
/*************found**************/
for (i=100, i<=m, i+=100)
{d= (double) i* (double) i;
y+=l. 0/d;
}
return (y);
}
main ()
{ int n=2000;
clrscr();
printf("\nThe result is %lf\n",fun(n));
已知C源程序如下:
/ * longIntAdd * /
include <stdio. h>
include <string. h>
define LENGTH 81
void addLInt(char sl[],char s2[]); void reverse(char s[]) ; int main()
{
char intstrl[LENGTH],intstr2[LENGTH];
printf("请输入超长整数的被加数和加数:\n")
scanf("%s%s" ,intstrl ,intstr2) ; addLInt(intstrl ,intstr2) j printf("超长整数和为: %s" .intstrl); return 0;
}
void addLInt(char sl[] ,char s2[]) {
int i=0,tmp,c=0;
char s[LENGTH];
if(strlen(s1)<strlen(s2)){ strcpy(s,sl); strcpy(sl,s2); strcpy(s2,s);
}
reverse(sl);reverse(s2);
while(s2[i]! ='\0'){
tmp=sl[i]-'0'+s2[i]-'0'+ c;
sl[i] = tmp%10+,0';
c=tmp/10;
i++; } while(sl[i]! ='\0,&&c){
tmp=sl[i] —'0' + c;
sl[i] = tmp%10+'0';
c=tmp/10;
i++; } If(c){
sl[i++] = c+'0';
sl[i] = '\0'; } reverse(sl);
}
void reverse(cliar s[])
{
inti,j,c;
for(i=0,j = strlen(s) -l;i<j;i++,j--){
c=s[i]; s[i] = s[j]; s[j] = c; } }
(1)画出程序中函数addLInt的控制流程图(10分);
(2)设计一组测试用例,使该程序addLInt函数的语句覆盖率和分支覆盖率均能达到100%。如果认为该函数的语句覆盖率或分支覆盖率无法达到100%,需说明为什么(10分)。
阅读以下说明,回答问题1~4,将解答填入对应的解答栏内。
[说明] 输入1个长整型,求各位数字的平方和。
例如:输入-123,输出14。
include <stdio. h>
void main()
{ int digit;
long in , s;
seanf(" % Id", &in );
(1);
(2);
while(in >0) {
(3);
s = s + digit* digit;
(4);
}
pfinff("sum = % 1dn", s );
}