题目详情
当前位置:首页 > 职业培训考试
题目详情:
发布时间:2023-10-22 15:31:33

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

// * * * * *

更多"请编写一个函数int stringLen(char*ps),该函数能计"的相关试题:

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

// * * * * *

[简答题]请编写一个函数 int find(char s[],char t[]), 该函数在字符串s中查找字符串t,如果找到,则返回字符串t在字符串s中的位置(整数值):否则返回-1。本题要求:用数组方式及两重循环来实现该函数。
注意:部分源程序已存在考生文件夹的文件PROC1.cpp中。
请勿修改主函数和其他函数中的任何内容,仅在函数find( )的花括号中填写若干语句。
文件PROC1.cpp的内容如下:
//PROC1.cpp
#include<iostream>
using namespace std;
int find(char s[],char t[]);
const int MAXLINE = 256;
int main( )

char source[MAXLINE],target[MAXLINE];
cout<<"Please input a string for searching:/n";
cin.getline(source,MAXLINE);
cout<<"Please input a string you want to find:/n";
cin.getline(target,MAXLINE);
int intPos=find(source,target);
if(intPos>=0)
cout<<"Finding it,The target string is at index"
<<intPos<<"of the source string/n";
else
cout<<"Not finding it /n";
return 0;

int find(char s[],char t[])

//********

[简答题]请编写一个函数char *fun(char *s,int n)。函数fun( )的功能是将字符串s中的字符“循环左移”n位。例如,输入“ABCDE”,则循环左移2位应输出“CDEAB”,输入“1234567”,循环左移3位应输出“4567123”。 注意:部分源程序已存在文件PROC13.cpp中。 请勿修改主函数和其他函数中的任何内容,仅在函数fun( )的花括号中填写若干语句。 文件PROC13.cpp的内容如下: //PROC13.cpp #include <iostream> #include <string> using namespace std; char *fun(char *s,int n); int main( ) { char str[81]; int n; cout<<"Enter a string(less than 80 char)/n”; cin>>str; cout<<"/n Enter n:"; cin>>n; if(n>strlen(str)) { cout<<"/n Data overflow"; return 0; } cout<<"The result is: "<<fun(str,n)<<end1; return 0; } char *fun(char*s,int n) { //* * * * * * }
[简答题]请编写一个函数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) { }
[简答题]请编写一个函数char *fun(char *s),其中s代表一个字符串。函数fun( )的功能是将字符串s的元素倒置。例如,输入为“teacher”,则应输出“rehcaet”。 注意:部分源程序已存在文件PROC10.cpp中。 请勿修改主函数和其他函数中的任何内容,仅在函数fun( )的花括号中填写若干语句。 文件PROC10.cpp的内容如下: //PROC10. cpp #include <iostream> #include <string> using namespace std; char *fun(char *s); int main ( ) { char str[81]; cout<<"Please enter a string:/n"; cin>>str; cout<<"The result is:"<<fun(str)); cout<<end1; return 0; } char*fun(char*s) { //* * * * * * * * * }
[单项选择]有以下程序(strcpy为字符串复制函数,strcat为字符串连接函数):
# include <stdio.h>
# include <string.h>
main( )
char a[10]="abc", b[10]="012", c[10]="xyz";
strcpy(a+1, b+2);
puts(strcat(a, c+1));

程序运行后的输出结果是( )。


A. a12xyz
B. 12yz
C. a2yz
D. bc2yz
[简答题]

请编写函数fun, 函数的功能是:统计一行字符串中单词的个数,作为函数值返 回。一行字符串在主函数中输入, 规定所有单词由小写字母组成,单词之间由若干 个空格隔开, 一行的开始没有空格。
注意:部分源程序在文件PROG1.C中。
请勿改动主函数main和其它函数中的任何内容, 仅在函数fun的花括号中填入你编写的若干语句。
给定源程序:
#include
#include
#define N 80
int fun( char *s)
{
}
main( )
{ char line[N]; int num=0;
printf("Enter a string :/n"); gets(line);
num=fun( line );
printf("The number of word is : %d/n/n",num);
NONO( );
}


[简答题]请编写一个函数fun( ),其功能是比较两个字符串的长度(不得调用C语言提供的求字符串长度的函数),函数返回较长的字符串。若两个字符串长度相同,则返回第一个字符串。
例如,输入beijing<CR>shanghai<CR>(<CR>为回车键),函数将返回shanghai。
#include<stdio.h>
char*fun(char*s,char*t)


main( )
char a[20],b[20];
void NONO( );
printf("Input 1th string:");
gets(a);
printf("Input 2th string:");
gets(b);
printf("%s/n",fun(a,b));

[简答题]请编写一个函数proc( ),它的功能是:比较两个字符串的长度(不得调用C语言中求字符串长度的函数),函数返回较长的字符串。若两个字符串长度相等,则返回第1个字符串。
例如,若输入jiangxi<CR>
beijing<CR>(<CR>为回车键)
则函数返回jiangxi。
注意:部分源程序已给出。
请勿改动主函数main和其他函数中的任何内容,仅在函数proc的花括号中填入所编写的若干语句。
试题程序:
#include<stdio.h>
char * proc(char *s, char *t)


void main( )

char a[20], b[10], *p, *q;
printf("Input 1th string: ");
gets(a);
printf("Input 2th string: ");
gets(b);
printf("%s", proc(a,b));

[简答题]请编写一个函数fun( ),它的功能是将一个数字字符串转换为一个整数(不得调用C语言提供的将字符串转为整数的函数)。
例如,若输入字符串“-1234”,则函数把它转换为整数值 -1234。
注意:部分源程序给出如下。
请勿改动主函数main和其他函数中的任何内容,仅在函数fun的花括号中填入所编写的若干语句。
试题程序:
#include <stdio.h>
#include <string.h>
long fun(char *p)


main ( )

char s[6];
long n;
printf("Enter a string:/n");
gets(s);
n=fun(s);
printf("%ld/n",n);

[简答题]请编写一个函数fun( ),该函数的功能是:返回给定字符串中大写字母字符的个数。
如字符串"Hello World"中,大写字母的个数为2个。
注意:部分源程序已存在文件PROC5.CPP中。
请勿修改主函数和其他函数中的任何内容,仅在函数fun( )的花括号中填写若干语句。
文件PROC5.cpp的内容如下:
//PROC5.cpp
#include<iostream>
#include<string>
using namespace std;
int fun(char *str);
int main( )

char str[ ]="Chinese Computer World";
cout<<fun(str)<<end;
return 0;

int fun(char *str)

//**********

[简答题]下列程序的功能是:把s字符串中的所有字符左移一个位置,字符串中的第一个字符移到最后。请编写函数chg(char*s)实现程序要求,最后调用函数readwriteDAT( )从in.dat文件中读取50组数据,分别得出结果,且把结果输出到out.out文件中。
例如:s字符串中原有内容为:Mn.123xyZ,调用该函数后结果为:n.123xyZM。
注意:部分源程序已经给出。
请勿改动主函数main( )和输出数据函数readwriteDAT( )的内容。
#include<string.h>
#include<stdio.h>
#define N 81
void readwriteDAT( );
void chg(char*s)


main( )

char a[N];
printf("Enter a string:");
gets(a);
printf("The original string is:");
puts(a);
chg(a);
printf("The string after modified:");
puts(a);
readwriteDAT( );

void readwriteDAT( )

int i;
char a[N];
FILE *rf,*wf;
rf=fopen("in.dat","r");
wf=fopen("out.dat","w");
for(i=0;i<50; i++)

fscanf(rf,"%s",a);
chg(a);
fprintf(wf,"%s/n",a);

fclose(rf);
fclose(wf);

[简答题]请编写函数fun,该函数的功能是:移动字符串中的内容,移动的规则如下:把第1~m个字符平移到字符串的最后,把第m+1到最后的字符移到字符串的前部。
例如:字符串中原有的内容为ABCDEFGHIJK,m的值为3,则移动后字符串中的内容应该是DEFGHIJKABC。
注意:部分源程序在文件PROG1.C中,请勿改动主函数main和其他函数中的任何内容,仅在函数fun的花括号中填入你编写的若干语句。
文件PROG1.C内容如下:
#include<stdio.h>
#include<string.h>
#define N 80
void fun(char *w,int m)


void main( )
char a[N]="ABCDEFGHIJK":
int m;
printf("The original string:/n");
puts(a);
printf("/nEnter m:/n");
scanf("%d",&m);
fun(a,m);
printf(:/n The string after moving: /n");
puts(a);
printf("/n");

我来回答:

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

订单号:

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