更多"请编写一个函数int pattern_index(char subst"的相关试题:
[简答题]请编写一个函数int pattern_index(char substr[],char str[]),该函数执行含通配符“”的字符串的查找时,该通配符可以与任一个字符匹配成功。当子串substr在str中匹配查找成功时,返回子串substr在str中的位置,否则返回值为0。要求使用 for循环实现。输出结果如下:
子串起始位置:5
注意:部分源程序已存在文件test20_2.cpp中。
请勿修改主函数main和其他函数中的任何内容,仅在函数pattern_index的花括号中填写若干语句。
文件test20_2.cpp的内容如下:
#include<iostream.h>
int pattern_index(char substr[],char str[])
{
}
void main ( )
{
char *substring,*string;
int same;
substring="gram";
string="this program return index of substring";
same=pattern_index(substring, string);
if(same)
cout<<"子串起始位置: "<<same<<end1;
else
cout<<"匹配不成功" <<end1;
}
[简答题]请编写一个函数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)
{
}
[简答题]请编写一个函数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;
[简答题]【说明】
请编写一个函数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
[多项选择]简单应用题
请编写一个函数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<<"最小公倍数:"<
[简答题]请编写一个函数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)
[简答题]请编写一个函数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)
[多项选择]编程题
请编写一个函数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
[简答题]请编写一个函数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");
}