写出下列程序的运行结果。
#include
void Fun()
{
int num=20;
cout<<"the fun's num is"<
}
void main()
{
int num=10;
cout<<"the main's num is "<
Fun();
{
int num=30;
cout<<"the field's num is "<
}
cout<<"the main's num is "<
}
第1题
注意:部分源程序已存在文件test8_2.cpp中。
请勿改动主函数main和其他函数中的任何内容,仅在函数fun的花括号中填入所编写的若干语句。
文件test8_2.cpp的内容如下:
include<iostream.h>
include<string.h>
include<conio.h>
define N 10
typedef struct ss
{char num[10];
int s;
} STU;
void fun(STU a[],STU *s)
{
}
void main( )
{STU
a[N]={{"A01”,81},{"A02",89},{"A03",66},{"A04",87},{"A05",77},{"A06",90},{"A07",79}, {"A08",61},{"A09",80},{"A10",71}},m;
fun(a,&m);
cout<<"***** The original date *****"<<endl;
cout<<"The lowest :"<<m.num<<m.s<<endl;
}
第2题
下列程序运行结果是 。 class Student { int score ; static int count ; public : Student ( int n=0) { score =n ; count++ ; } Student (Student &p) { score =p. score ; count++ ;} ~Student ( ) { cout<<"the number of the students: endl; } void showscore( )> < <endl; } static int getcount( ){ return count="0" ; student fun(student p0) { p1="p0;" number of the students: endl p1; :: void main( ) john(80) cout "the score john: "; john.showscore( ); tom; tom="fun(John);" tom: tom.showscore(>
第3题
例如,输入一个字符串world,然后输入3,则调用该函数后的结果为word。
注意:部分源程序给出如下。
请勿改动主函数main 和其他函数中的任何内容,仅在函数fun的花括号中填入所编写的若干语句。
试题程序:
include <stdio.h>
include <conio.h>
define LEN 20
void fun (char a[], char b [], int n)
{
}
main ()
{
char str1 [LEN], str2 [LEN];
int n ;
clrscr ();
printf ("Enter the string : \n") ;
gets (str1) ;
printf ("Enter the position of the string
deleted: ");
scanf ("%d", &n) ;
fun (str1, str2, n) ;
printf ("The new string is : %s \n",
str2) ;
}
第4题
注意:部分源程序已存在文件test13_2.cpp中。如输入7和8时,结果是56。
请勿修改主函数main和其他函数中的任何内容,仅在函数fun的花括号中填写若干语句。
文件test13_2的内容如下;
include<iostream.h>
int fun(int nFirst,int nSecond);
void main()
{
int nFirst,nSecond;
cout<<"Please input the first one";
cin>>nFirst;
cout<<" Please input the second one";
cin>>nSecond;
cout<<"最小公倍数:"<<fun(nFirst,nSecond)<<endl;
}
int fun(int nFirst,int nSecond)
{
}
第5题
A.oPEN tHE dOOR
B.ope the door
C.OPEN THE DOOR
D.Open The Door
第6题
例如:a中的字符串为fshADfg,b中的字符串为sdAEdi,则c中的字符串应为fdAADf。
请改正程序中的错误,使它能得到正确结果。
注意:不要改动main函数,不得增行或删行,也不得更改程序的结构。
试题程序:
include <stdio.h>
include <strinq.h>
void fun(char *p,char *q,char *c)
{int k=0;
while(*p || *q)
/**********found**************/
{ if (*p<=*q)
c[k]=*q;
else c[k]:*p;
if(*p) p++;
if(*q)q++;
/**+**********found**************/
k++
}
}
main()
{char a[10]="fshADfg",b[10]="sdAEdi",
c[80]={'\0');
fun(a,b,c);
printf("The string a:");puts(a);
printf("The string b:");puts(b);
printf("The result:");puts(c);
}
第7题
请改正程序中的错误,使它能得到正确结果。
注意,不要改动主函数,不得删行或增行,也不得更改程序的结构。
源程序文件RevMain7.cpp中的程序清单如下:
//RevMain7.cpp
include<iostream>
include<string>
using namespace std;
void fun(char *p,char *q,char *c)
{
int k=1;
while(*p!=*q)
{
if(*p<*q)
c[k]=*q;
else
c[k]=*p;
if(*p)
p++;
if(*q)
q++;
}
}
int main()
{
char a[10]="aBCDeFgH",b[10]="ABcd",c[80]={'\0'};
fun(a,b,c);
cout<<"The string a is "<<a<<'\n';
cout<<"The string b is "<<b<<'\n';
cout<<"The string c is "<<c<<endl;
return 0;
}
第8题
例如,若学生的成绩是85.5,76,69.5,85,91,72,64.5, 87.5,则他的平均分应当是78.875。
注意:部分源程序给出如下。
请勿改动主函数main和其他函数中的任何内容,仅在函数fun的花括号中填入所编写的若干语句。
试题程序:
include<stdio.h>
define N 8
typedef struct
{ char num [10];
double s[N];
double ave;
} STREC;
void fun()
{
}
main()
{
STREC s={"GA005",85.5,76,69.5,85,91, 72,64.5,87.5);
int i;
fun (&s);
printf("The %s' s student data:\n",s.num)/ /*输出学号*/
for(i=0;i<N; i++)
printf("%4.1f\n", s.s[i]);
/*输出各科成绩*/
printf("\nave=%7.3f\n",s.ave);
/*输出平均分*/
}
第9题
[注意] 部分源程序给出如下。
请勿改动主函数main和其他函数中的任何内容,仅在fun函数的花括号中填入所编写的若干语句。
[试题源程序]
include<stdio.h>
define N 8
typedef struct
{
char num[10];
double s;
}STREC;
double fun(STREC *a, STREC *b, int *n)
{
}
void main()
{
STREC s[N]={{"GA05", 85},
{"GA03", 76}, {"GA02", 69}, {"GA04", 85},
{"GA01", 91}, {"GA07", 72}, {"GA08", 64},
{"GA06", 87}};
STREC h[N], t; FILE *out;
int i, j, n;
double ave;
ave=fun(s, h, &n);
printf("The %d student data which is lower than %7.3 f:\n", n, ave);
for(i=0; i<n; i++)
printf("%s %4.1f\n", h[i]. num, h[i].s);
printf("\n");
ut=fopen("out.dat", "W");
fprintf(out, "%d\n%7.3f\n", n, ave);
for(i=0; 2<n-1; i++)
for(j=i+1; j<n; j++)
if(h[i]. s>h[j].s)
{
t=h[i];
h[i]=h[j];
h[j]=t;
}
for(i=0; 2<n; i++)
fprintf(out, "%4.1f\n", h[i].s);
fclose(out);
}
第10题
注意:部分源程序给出如下。
请勿改动主函数main 和其他函数中的任何内容,仪在函数fun()的横线上填入所编写的若干表达式或语句。
试题程序:
include<stdio. h>
include<conio. h>
include<stdlib. h>
typedef struct ss
{
int data;
struct ss *next;
} NODE;
void fun(int n,char*filename)
{
NODE *h,*p, *s;
FILE *pf;
int i;
h=p= (NODE *) malloc (sizeof (NODE));
h->data=0;
for (i=1; i {
s=(NODE *)malloc (sizeof (NODE));
s->data=【 】;
【 】;
p=【 】
}
p->next=NULL;
if ( (pf=fopen (filename, "w") ) ==NULL)
{
printf {"Can not open out9B.clat! ");
exit (0);
}
p=h;
fprintf (pf, "\n***THE LIST***\n");
print f ("\n***THE LIST***\n")
while (p)
{
fprintf (pf, "%3d", p->data)
printf ("%3d",p->data);
if (p->next ! =NULL)
{
fprintf (pf, "->");
printf ("->");
}
p=p->next;
}
fprintf (pf, "\n");
printf ("\n");
fclose (pf);
p=h;
while (p)
{
s=p;
p=p->next;
free (s);
}
}
main()
{
char * filename="out98. dat";
int n;
clrscr ();
printf (" \nInput n: ");
scanf ("%d", &n);
fun (n, filename);
}
为了保护您的账号安全,请在“上学吧”公众号进行验证,点击“官网服务”-“账号验证”后输入验证码“”完成验证,验证成功后方可继续查看答案!