题目详情
当前位置:首页 > 职业培训考试
题目详情:
发布时间:2024-01-24 07:30:34

[简答题](1)编写一个函数change( )实现两个实型变量的值交换;(2)写出主函数,从键盘上输入两个数,然后调用函数change( )交换两个实型数的值并输出。

更多"(1)编写一个函数change( )实现两个实型变量的值交换;(2)写"的相关试题:

[简答题]请编写一个函数int stringLen(char*ps),该函数能计算出字符串ps的长度,函数返回值就是字符串的长度(不包括字符串结束标识号’/0’)。本题要求:用指针方式及循环来实现该函数。
注意;部分源程序已存在考生文件夹下的文件PROC6,cpp中。
请勿修改主函数和其他函数中的任何内容,仅在函数stringLen( )的花括号中填写若干语句。
文件PROC6.cpp的内容如下:
//PROC6.cpp
#include<iostream>
using namespace std;
int stringLen(char *);
int main( )

char str[100],*p;
cout<<"Input your string please!/n";
cin>>str;
p=str;
cout<<"The lenth of your string is "<<stringLen(p)<<end1;
return 0;

int stringLen(char *ps)

// * * * * *

[简答题]请编写一个函数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);

[简答题]简单应用题 请编写一个函数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<
[简答题]请编写一个函数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);

[简答题]

请编写一个函数,函数的功能是删除字符串中的所有空格。
例如, 主函数中输入"asd af aa z67", 则输出为 "asdafaaz67"。
注意:部分源程序在文件PROG1.C中。
请勿改动主函数main和其它函数中的任何内容,仅在函数fun的花括号中填入你编写的若干语句。
给定源程序:
#include
#include
int fun(char *str)
{
}
main( )
{
char str[81];
int n;
printf("Input a string:") ;
gets(str);
puts(str);
fun(str);
printf("*** str: %s/n",str);
NONO( );
}


[简答题]请编写一个函数unsigned short fun(unsigned short s)。其中s是一个大于10的无符号整数,若s是一个n(n≥2)位整数,函数求出s的n位数之和作为函数的返回值。 例如,s值为4315,则函数返回13。s值为13函数,则返回4。 注意:部分源程序已存在文件PROC15.cpp中。 请勿修改主函数和其他函数中的任何内容,仅在函数fun( )的花括号中填写若干语句。 文件PROC15.cpp的内容如下: //PROC15.cpp #include<iostream> using namespace std; unsigned short fun(unsigned short s); int main( ) { unsigned short a; cout<<"Enter a unsigned short integer number:"; cin>>a; if(a<10) cout<<"Data error!"; else cout<<"The result: "<<fun(a)<<end1; return 0; } unsigned short fun(unsigned short s) { //* * * * * * }
[简答题]简单应用题 请编写一个函数sortnum(intnum),参数num是一个三位的整数,该函数将num的百位、十位和个位的数字进行重排,并返回由上述的三个数字组成的最大的三位数。 注意:部分源程序已存在文件kt13_2.cpp中。 如输入456后,输出结果如下: 654 请勿修改主函数main和其他函数中的内容,仅在函数sortnum的花括号中填写若干语句。 文件kt13_2.cpp的内容如下: #include intsortnum(intnum) { } voidmain( ) { intnum; intresult=0; cout<<"请输入一个三位数"; cin>>num; cout<
[简答题]编写一个函数findStr( ),该函数统计一个长度为2的字符串在另一个字符串中出现的次数。例如,假定输入的字符串为"asd asasdfg asd as zx67 asd mklo",子字符串为"as",函数返回值是6。
函数ReadWrite( )的功能是实现从文件in68.dat中读取两个字符串,并调用函数findStr( ),最后把结果输出到文件out68.dat中。
注意:部分源程序已给出。
请勿改动主函数main( )和其他函数中的任何内容,仅在函数findStr( )的花括号中填入你所编写的若干语句。
[试题程序]
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
void ReadWrite( );
int findStr(char * str,char * substr)


void main( )

char str[81],substr[3];
int n;
system("CLS");
printf("输入原字符串:");
gets(str);
printf("输入子字符串:");
gets(substr);
puts(str);
puts(substr);
n=findStr(str,substr);
printf("n=% d/n",n);
ReadWrite( );

void meadWrite( )

char ch,str[81],substr[3];
int n,len,i=0;
FILE * rf, * wf;
rf=fopen("in68.dat","r");
wf=fopen("out68.dat","w");
while(i<5)

fgets(str,80,rf);
fgets(substr,10,r
[简答题]编写一个函数findStr( ),该函数统计一个长度为2的子字符串在另一个字符串中出现的次数。例如,假定输入的字符串为"asd asasdfg asd as zx67 asd mklo",子字符串为"as",函数返回值是6。
函数ReadWrite( )实现从文件in.dat中读取两个字符串并调用函数findStr( ),最后把结果输出到文件out.dat中。
注意:部分程序已经给出。
请勿改动主函数main( )和其他函数中的任何内容,仅在函数findStr( )的花括号中填入你编写的若干语句。
#include <stdio.h>
#include <string.h>
#include <conio.h>
int findStr(char *str,char *substr)


main( )

char str[81],substr[3];
int n;
clrscr( );
printf("输入原字符串");
gets(str) ;
printf("输入子字符串:");
gets(substr);
puts(str);
puts(substr);
n=findStr(str, substr);
printf("n=%d/n", n);
ReadWrite( );

ReadWrite( )

char str[81],substr[3],ch;
int n, len,i=0;
FILE *rf, *wf;
rf=fopen("in.dat", "r");
wf=fopen("out.dat", "w");
while(i<25)

fgets(str, 80, rf);
fgets(substr, 10, rf);
len=strlen(substr)-1;
ch=substr[l
[简答题]请编写一个函数char MaxCharacmr(char *str),该函数返回参数str所指向的字符串中具有最大ASCII码的那个字符(如字符串“world”中字符‘w’具有最大的ASCII码)。当str所指向的字符串为空时,则返回空字符0x0或‘/0’。
输出结果如下:
Good Morning!
Max char:r
注意:部分源程序已存在文件test15_2.cpp中。
请勿修改主函数main和其他函数中的任何内容,仅在函数MaxCharacter的花括号中填写若干语句。
文件test15_2.cpp的内容如下:
#include<iostream.h>
#include<string.h>
char MaxCharacter(char *str);
void main( )

char str[100];
strcpy(str,"Good Morning!");
char maxc=MaxCharacter(str);
cout<<str<<endl;
cout<<"Max char:"<<maxc<<endl;

char MaxCharacter(char*str)


[简答题]简单应用题 请编写一个函数inlinelongsum(intn),用递归函数完成运算:sum(n)=1*1+2*2++n*n,递归表达式为sum(n)=sum(n-1)+n2。 注意:部分源程序已存在文件kt10_2.cpp中。 请勿修改主函数main和其他函数中的任何内容,仅在函数sum的花括号中填写若干语句。 文件kt10_2.cpp的内容如下: #include inlinelongsum(intn) { } voidmain( ) { intn; cout<<"输入n:"; cin>>n; cout<<"结果为:"<
[简答题]简单应用题 请编写一个函数intCalcDigital(char*str),该函数可返回字符串str中数字字符(即“0”-“9”这10个数字)的个数,如字符串"olympic2008"中数字字符的个数为4。请用if条件判断语句与for循环语句来实现该函数。 注意:部分源程序已存在文件中。 请勿修改主函数main和其他函数中的任何内容,仅在函数find的花括号中填写若干语句。 文件kt9_2.cpp的内容如下: #include #include intCalcDigital(char*str); voidmain( ) { char*str; str=newchar[255]; cout<<"输入字符串:"; cin>>str; intnum=CalcDigital(str); cout<
[简答题]编写一个函数,该函数可以统计一个长度为2的字符串在另一个字符串中出现的次数。例如,假定输入的字符串为asd asasdfg asd as zx67 asd mklo,子字符串为as,则应当输出6。
注意:部分源程序给出如下。
请勿改动主函数main和具他函数中的任何内容,仅在函数fun的花括号中填入所编写的若干语句。
试题程序:
#include <conio.h>
#include <stdio.h>
#include <string.h>
int fun(char *str, char *substr)


main ( )

char str[81],substr[3];
int n;
clrscr ( );
printf ("输入主字符串 ");
gets (str);
printf ("输入子字符串");
gets (substr);
puts (str);
puts (substr);
n=fun (shr, substr);
printf("n=%d/n ",n);

[简答题]编写一个函数,用该函数可以统计一个长度为3的字符串在另一个字符串中出现的次数。例如,假定输入字符串“the abcthe they have theren”,子字符串为“the”,则应输出4。 注意:部分源程序在文件PROC2.CPP中。 请勿改动主函数和其他函数中的任何内容,仅在fun( )的花括号中填入编写的若干语句。 部分源程序如下: //PROC2.CPP #include <iostream> using namespace std; #define MAX 100 int fun(char *str,char *substr); int main( ){ char str[MAX],substr[3]; int n; cout<<"Please Input the source String/n"; cin>>str; cout<<"Please Input the subString/n"; cin>>substr; n=fun(str, substr); cout<<"The counter is: "<<n<<end1; return 0; } int fun(char *str,char *substr) { //****** }
[简答题]请编写一个函数int CalcDigital(char *str),该函数可返回字符串str中数字字符(即0~9这10个数字)的个数,如字符串“olympic2008”中数字字符的个数为4。请用if条件判断语句与for循环语句来实现该函数。 注意:部分源程序已存在文件test9_2.cpp中。 请勿修改主函数main和其他函数中的任何内容,仅在函数find的花括号中填写若干语句。 文件test9_2.cpp的内容如下: #include<iostream.h> #include<string.h> int CalcDigital(char*str); void main( ) { char *str; str=new char[255]; cout<<"输入字符串:"; cin>>str; int num=CalcDigital(str); cout<<str<<":"<<num<<endl; } int CalcDigital(char *str) { }

我来回答:

购买搜题卡查看答案
[会员特权] 开通VIP, 查看 全部题目答案
[会员特权] 享免全部广告特权
推荐91天
¥36.8
¥80元
31天
¥20.8
¥40元
365天
¥88.8
¥188元
请选择支付方式
  • 微信支付
  • 支付宝支付
点击支付即表示同意并接受了《购买须知》
立即支付 系统将自动为您注册账号
请使用微信扫码支付

订单号:

请不要关闭本页面,支付完成后请点击【支付完成】按钮
恭喜您,购买搜题卡成功
重要提示:请拍照或截图保存账号密码!
我要搜题网官网:https://www.woyaosouti.com
我已记住账号密码