更多"简单应用题
请编写两个函数void sort(int &x, &y)"的相关试题:
[多项选择]简单应用题
请编写两个函数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);
}
[简答题]请编写两个函数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<iostream.h>
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);
}
[多项选择]简单应用题
请编写一个函数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 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<
[简答题]简单应用题
请编写一个函数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<
[简答题]简单应用题请编写函数fun,其功能是将两个两位数的正整数a,b合并形成一个整数放在c中。合并的方式是将a数的个位和十位数依次在c数千位和十位上,b数的十位和个位数依次放在c数的个位和百位。注意:部分源程序以存在文件test3_2.cpp中。请勿修改主函数main和其他函数中的任何内容,仅在函数fun的花括号中填写若干语句。文件test3_2.cpp的内容如下:#includevoid fun(int a ,int b,long *c){}void main( ){int a,b; long c; cout<<"Input a,b;"<>a>>b; fun(a,b,&c); cout<<"The result is:/n"<
[简答题]简单应用题
请编写一个函数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<<"逆序后的字符串:"<
[简答题]请编写两个函数int sum_of_powers(int k,int n),powers(int m,int n),求1~6的k次方的和,sum_of_powers中参数k和n分别表示k次方和所求数列中最大的一个自然数,最后返回所求值,powers中参数m和n分别表示m为底数n为指数,最后返回所求值。要求使用for循环和函数嵌套(int sum_of_powers中调用powers)实现算法。输出结果如下:
sum of 4 powers of intergers from 1 to 6=2275
注意:部分源程序已存在文件test25_2.cpp中。
请勿修改主函数main和其他函数中的任何内容,仅在函数sum_of_powers和powers的花括号中填写若干语句。
文件test25_2.cpp的内容如下:
#include<iostream.h>
const int k(4);
const int n(6);
int sum_of_powers(int k,int n),powers(int m,int n);
void main( )
cout<<"sum of "<<k<<" powers Of intergers from 1 to "<<n<<"=";
cout<<sum_of_powers(k,n)<<endl;
int sum_of_powers(int k,int n)
int powers(int m, int n)
[简答题]请编写一个函数int fun (int nFirst, int nSecond),求两个数的最小公倍数并返回这个值。
注意:部分源程序已存在文件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)
{
}
[多项选择]简单应用题
编写一个函数int charnum(char fn[10]),该函数以只读方式打开文件fn,,通过统计,返回文件中字符的个数,请使用while循环实现计数功能。
注意:部分源程序已存在文件test7_2.cpp中。
请勿修改主函数main和其他函数中的任何内容,仅在函数charnum的花括号中填写若干语句。
文件test7_2.cpp的内容如下:
#include
#include
#include
int charnum(char fn[10]);
void main( )
{
int num;
num=charnum("abc.txt");
cout<<"num="<
[简答题]请编写一个函数int compare(char *s,char *t)), 该函数的功能是对两个字符串进行比较。当s所指字符串和t所指字符串相等时,返回值为0;当s所指字符串大于是t指字符串时,返回值大于0;当s所指字符串小于t所指字符串时,返回值小于0。
注意:部分源程序已存在文件PROC8.cpp中。
文件PROC8.cpp的内容如下:
//PROC8.cpp
#include <iostream>
#include <string>
using namespace std;
int compare(char *s,char *t)
{
//* * * * * * * * *
}
int main ( )
{
char str1[100],str2[100];
int result;
cout<<"Input the first string/n";
cin>>str1;
cout<<"Input the second string/n";
cin>>str2;
result=compare(str1,str2);
if (result==0)
cout<<"string1=string2 ! /n";
else if (result>0)
cout<<"string1>string2 ! /n";
else
cout<<"string1<string2 ! /n";
return 0;
}