更多"简单应用题
编写一个函数int charnum(char fn[10"的相关试题:
[简答题]编写一个函数int charnum(char fn[10]),该函数以只读方式打开文件fn,通过统计,返回文件中字符的个数,请使用while循环实现计数功能。
注意:部分源程序已存在文件test7_2.cpp中。
请勿修改主函数main和其他函数中的任何内容,仅在函数charnum的花括号中填写若干语句。
文件test7_2.cpp的内容如下:
#include<iostream.h>
#include<fstream.h>
#include<stdlib.h>
int charnum(char fn[10]);
void main( )
{
int num;
num=charnum("abc.txt");
cout<<"num="<<num<<endl;
}
int charnum(char fn[10])
{
}
[多项选择]简单应用题
请编写一个函数int fun(int nFirst,int nSecond),求两个数的最小公倍数并返回这个值。
注意:部分源程序已存在文件test13_2.cpp中。如输入7和8时,结果是56。
请勿修改主函数main和其他函数中的任何内容,仅在函数fun的花括号中填写若干语句。
文件test13_2的内容如下:
#include
int fun(int nFirst,int nSecond);
void main( )
{
int nFirst, nSecond;
cout<<"Please input the first one/n";
cin>>nFirst;
cout<<"Please input the second one/n";
cin>>nSecond;
cout<<"最小公倍数:"<
[多项选择]简单应用题
请编写一个函数void swap(int *x,int *y),用来交换两个数的值。
注意:部分源程序已存在文件test14_2.cpp中。
请勿修改主函数main和其他函数中的任何内容,仅在函数swap的花括号中填写若干语句。
文件test14_2.cpp的内容如下:
#include
void swap(int *x,int *y);
void main( )
{
int a=1,b=3;
swap(&a,&b);
cout<<"a="<
[多项选择]简单应用题
请编写两个函数void sort(int &x, &y)和void sort(int x,int y,int z),实现对2个和3个元素的排序并在屏幕上输出排序结果(数字之间使用跳格)。
注意:部分源程序已存放在文件test2_2.cpp中。
请勿修改主函数main和其他函数中的任何内容,仅在函数的花括号中填写若干语句。
输出结果如下:
3 4
2 3 4
文件test2_2.cpp的内容如下:
#include
void sort(int &x,int &y)
{
/**1**/
}
void sort(int x,int y,int z)
{
/**2**/
}
void main( )
{
int a=4,b=3,c=2;
sort(a,b);
sort(a,b,c);
}
[简答题]简单应用题
请编写一个函数char MaxCharacter(char * str),该函数返回参数str所指向的字符串中具有最大ASCII码的那个字符(如字符串"world"中字符’’w’’具有最大的ASCII码)。当str所指向的字符串为空时,则返回空字符0x0或’’/0’’。
输出结果如下:
Good Morning!
Max char:r
注意:部分源程序已存在文件test15_2.cpp中。
请勿修改主函数main和其他函数中的任何内容,仅在函数MaxCharacter的花括号中填写若干语句。
文件test15_2.cpp的内容如下:
#include
#include
char MaxCharacter(char * str);
void main( )
{
char str[100];
strcpy(str,"Good Morning!");
char maxc=MaxCharacter(str);
cout<
[简答题]简单应用题
请编写一个函数void fun(char ss[]),该函数将字符串ss翻转,如ss为"123abc"则翻转后为"cba321"。注意:用数组方式及for循环来实现该函数。
注意:部分源程序已存在文件test16_2.cpp中。
请勿修改主函数main和其他函数中的任何内容,仅在函数fun的花括号中填写若干语句。
文件test16_2.cpp的内容如下:
#include
#include
void fun(char ss[]);
void main( )
{
char s[80];
cout<<"请输入字符串:";
cin>>s;
fun(s);
cout<<"逆序后的字符串:"<
[多项选择]简单应用题
请编写函数void swap(int *px,int *py) 与void swap(int &px,int &py),实现主程序中变量a和b值的交换。
输出结果如下:
3 2
2 3
注意:部分源程序已存在文件test5_2.cpp中。
请勿修改主函数main和其他函数中的任何内容,仅在函数相应的花括号中填写若干语句。
文件test5_2.cpp的内容如下:
#include
void swap(int *px,int *py)
{
/***1***/
}
void swap(int &px,int &py)
{
/***2***/
}
void main( )
{
int a=2,b=3;
swap(a,b);
cout<
[简答题]请编写一个函数printdate(int year,int month,int day),该函数实现将输入的3个数字转换成英语数字纪年输出的功能,如输入March9,1978,则输出1978 3 9。注意:使用switch结构实现该函数的基本功能并应该能够判断错误的输入。部分源程序已存在文件test40_2.cpp中。请勿修改主函数main和其他函数中的任何内容,仅在函数printdate的花括号中填写若干语句。
源程序文件rest40_2.cpp清单如下:
#include<iostream.h>
void printdate(int year, int month, int day)
{
}
void main( )
{
printdate(1978,3,9);
}
[简答题]请编写一个函数int SeqSearch(int list[],int start,int n,int key),该函数从start开始,在大小为n的数细list中查找key值,返回最先找到的key值的位置,如果没有找到则返回-1。请使用for循环实现。
注意:部分源程序已存在文件test19_2.cpp中。
请勿修改主函数main和其他函数中的任何内容,仅在函数SeqSearch的花括号中填写若干语句。
文件test19_2.cpp的内容如下:
#include <iostream.h>
int SeqSearch(int list[], int start, int n, int key)
void main( )
int A[10];
int key, count=0, pos;
cout<<"Enter a list of 10 integers: ";
for(pos=0;pos<10;pos++)
cin>>A[pos];
cout<<"Enter a key: ";
cin>>key;
pos=0;
while( (pos=SeqSearch(A, pos,10,key))!=-1)
count++;
pos++;
cout<<key<<" occurs "<<count<<(count!=1" times":" time")<<" in the list."<<end1;
[简答题]请编写一个函数comm(int n,int k),该函数将用递归算法计算从n个人中选择k个人组成一个委员会的不同组合数,由n个人里选k个人的组合数=由(n-1)个人里选k个人的组合数+由(n-1)个人里选(k-1)个人的组合数。
注意:部分源程序已存在文件test41_2.cpp中。
请勿修改主函数main和其他函数中的任何内容,仅在函数comm的花括号中填写若干语句。
源程序文件test41-2.cpp清单如下:
#include<iostream.h>
int comm(int n, int k)
{
}
void main ( )
{
int n=7, k=3;
cout<<"n=7,k=3"<<endl;
cout<<comm(n,k)<<endl;
}
[简答题]请编写一个函数maxofarray(atype*p,int count),该函数从一个数组中找出其中的最大元素,并且数组中可以存放多种数据类型的元素。
注意:部分源程序己存在文件test42_2.cpp中。
请勿修改主函数main和其他函数中的任何内容,仅在函数maxofarray的花括号中填写若干语句。
文件test42_2.cpp清单如下:
#include<iostream.h>
#include<string.h>
#include<conio.h>
template<class atype>
void maxofarray(atype* p,int count)
{
}
void main ( )
{
int len=5;
char *p1;
cout<<"the char type array and it’s length is 5:/n";
cout<<"the array element is a b c d e/n";
p1=new char[len];
for (int i=0;i<len;i++)
p1[i]=’a’+i;
maxofarray(p1,len);
}
[多项选择]编程题
请编写一个函数void fun(int m, int k, int xx[]),该函数的功能是:将大于整数m且紧靠m的k个非素数存入所指的数组中。
例如,若输入15,5,则应输出16,18,20,21,22。
注意:部分源程序给出如下。
请勿改动主函数main和其他函数中的任何内容,仅在函数fun的花括号中填入所编写的若干语句。
试题程序:
#include
#include
void fun(int m, int k, int xx[])
{
}
main( )
{
int m,n,zz[1000];
clrscr( );
printf("/nPlease enter two integers: ");
scanf("%d%d",&m,&n);
fun(m, n, zz);
for(m=0;m
[简答题]请编写一个函数fun(int score [][3],int num),该函数返回有一门成绩以上课程成绩在85分以上,其余课程成绩不低于70分的人数。数组score按行存放num名考生各自的三门期末考试成绩。
注意:部分源程序已存在文件test31_2.cpp中。
请勿修改主函数main和其他函数中的任何内容,仅在函数fun的花括号中填写若干语句。
程序输出结果如下:
3
文件test31_2.cpp清单如下:
#include <iostream.h>
int fun(int score[] [3],int num)
{
}
void main ( )
{
int score[4] [3]={{70,89,92},{70,76,93},(80,86,98},{65,73,45});
cout<<fun(score,4)<<end1;
}
[简答题]【说明】
请编写一个函数int SeqSearch(int list[],int start,int n,int key),该函数从start开始,在大小为n的数组list中查找key值,返回最先找到的key值的位置,如果没有找到则返回-1。请修改程序中画线部分的错误并将不同情况下的输出结果补充完整。
【程序】
文件search.cpp的内容如下:
#include <iostream. h >
int SeqSearch( int list[ ] ,int start,int n,int key)
for(int i=start;i<=n;i++) //(1)
if( list[i] = key)//(2)
return i;
return -1;
void main( )
int A[10]
int key,count=0,pos;
cout <<" Enter a list of 10 integers:";
for(pos=0;pos<10;pos++)
cin >>A; //(3)
cout <<" Enter a key; ";
cin >> key;
pos=0;
while(( pos = SeqSearch ( A, pos, 10, key)) !=-1 )
count ++;
pos ++;
cout<<key<<"occurs" <<count<< (count!=1" times":" time") <<" in the list,"
<< endl;
第一种情况:输入2 3 12 6 8 45 8 33 7输入key:8
输出: (4)
第二种情况:输入2 3 126
[简答题]请编写一个函数void fun(int m, int k, int xx[]),该函数的功能是将大于整数m且紧靠m的k个非素数存入所指的数组中。
例如,若输入15,5,则应输出16,18,20,21,22。
注意:部分源程序给出如下。
请勿改动主函数main和其他函数中的任何内容,仅在函数fun的花括号中填入所编写的若干语句。
试题程序:
#include <conio.h>
#include <stdio.h>
void fun(int m,int k,int xx[])
main( )
int m,n,zz[1000];
clrscr( );
printf("/nPlease enter two integers:");
scanf("%d%d",&m,&n);
fun(m,n,zz);
for(m=0;m<n;m++)
printf("%d",zz[m]);
printf("/n");