首页
外语
计算机
考研
公务员
职业资格
财经
工程
司法
医学
专升本
自考
实用职业技能
登录
计算机
请使用VC6或使用【答题】菜单打开考生文件夹proj3下的工程prog3,其中声明了MyString类。MyString是一个用于表示字符串的类。成员函数startsWith的功能是判断此字符串是否以指定的前缀开始,其参数8用于指定前缀字符串。如果参数s表
请使用VC6或使用【答题】菜单打开考生文件夹proj3下的工程prog3,其中声明了MyString类。MyString是一个用于表示字符串的类。成员函数startsWith的功能是判断此字符串是否以指定的前缀开始,其参数8用于指定前缀字符串。如果参数s表
admin
2015-06-27
32
问题
请使用VC6或使用【答题】菜单打开考生文件夹proj3下的工程prog3,其中声明了MyString类。MyString是一个用于表示字符串的类。成员函数startsWith的功能是判断此字符串是否以指定的前缀开始,其参数8用于指定前缀字符串。如果参数s表示的字符串是MyString对象表示的字符串的前缀,则返回true;否则返回false。注意,如果参数S是空字符串或等于MyString对象表示的字符串,则结果为true。
例如,字符串“abc”是字符串“abcde”的前缀,而字符串“abd”不是字符串“abcde”的前缀。请编写成员函数startsWith。在main函数中给出了一组测试数据,此种情况下程序的输出应为:
s1=abcde
s2=abc
s3=abd
s4=
s5=abcde
s6=abcdef
s1startsWiths2:true
s1startsWiths3:false
s1startsWiths4:true
s1startsWiths5:true
s1startsWiths6:false
要求:
补充编制的内容写在“//**********333**********”与“//**********666**********”之间,不得修改程序的其他部分。
注意:程序最后将结果输出到文件out.dat中。输出函数writeToFile已经编译为obj文件,并且在本程序中调用。
//MyStving.h
#include
#include
usingnamespacestd;
classMyString{
public:
MyString(constchar*s)
{
size=strlen(s);
str=newchar[size+1];
strcpy(str,s);
}
~MyString(){delete[]str;)
boolstartsWith(constchar*s)
const;
private:
char*str;
intSize;
};
voidwriteToFile(constchar*);
//main.cpp
#include"MyString.h"
boolMyString::startsWith(const
char*s)const
{
//********333********
//********666********
}
intmain()
{
chars1[]="abcde";
chars2[]="abc";
chars3[]="abd";
chars4[]="";
chars5[]="abcde";
chars6[]="abcdef";
MyStringstr(s1);
cout<<"s1="<
<<"s2="<
<<"s3="<
<<"s4="<
<<"s5="<
<<"s6="<
cout<
<<"s1startSWiths2:"<
<<"s1startSWiths3:"<
<<"s1StartSWiths4:"<
<<"s1startSWiths5:"<
<<"s1StartsWiths6:"<
writeToFile("");
return0;
}
选项
答案
if (s == NULL) return true; int len = strlen(s); if (len > size) return false; for (int i = 0; i < len; i++) if ( str[i] != s[i]) return false; return true;
解析
主要考查考生对动态数组的掌握情况,根据题目要求知,函数的功能是判断此字符串是否以指定的前缀开始。利用for循环,逐个字符进行判断,如果满足条件str
!= s
,返回false,否则返回true。
转载请注明原文地址:https://jikaoti.com/ti/yfE0FFFM
本试题收录于:
二级C题库NCRE全国计算机二级分类
0
二级C
NCRE全国计算机二级
相关试题推荐
结构化程序设计主要强调的是______。
有以下函数charfun(char*P){returnp;}该函数的返回值是______。
要在类的对象上使用运算符,除了运算符【】和【】以外,其他的运算符都必须被重载。
重载的流运算符函数经常定义为类的【】函数。
在类中定义和实现的函数称为【】。
软件测试过程一般按4个步骤进行:单元测试、集成测试、验收测试(确认测试)和系统测试。在程序编码阶段进行的测试通常是______。
长度为n的简单插入排序法,最坏情况需要______次比较。
下列______是正确的语句。
用二维表来表示实体及实体之间联系的数据模型称为______。
一个项目具有一个项目主管,一个项目主管可管理多个项目。则实体集“项目主管”与实体集“项目”的联系属于【】的联系。
随机试题
材料一:“苏联共产党是一个拥有88年历史,1500万党员的大党,却在20世纪80年代末,在一纸禁令下,一夜之间被解散了,执政地位被剥夺,苏联社会主义不战而败。”材料二:“党的十六届四中全会通过的《决定》指出,党的执政地位不是与生俱来的,也不是一劳永逸的。
下列结论正确的是().
冠心病猝死的最主要原因是()。
症见呕吐酸腐,脘腹胀满,嗳气厌食,大便或溏或结,舌苔厚腻,脉滑实,治法为
下列结论中,正确的为()。
“征免性质”栏应填()。
请你用三分钟的时间简要介绍一下你自己的基本情况,并说说你主要的优缺点,有哪些特长和爱好?【追问】(1)喜欢书、报、刊吗?(2)喜欢读哪类书籍?(3)经常看的刊物有哪几种?
《我国》刑法第133条规定:“违反交通运输管理法规,因而发生重大事故,致人重伤、死亡或者使公私财产遭受重大损失的,处三年以下有期徒刑或者拘役;交通运输肇事后逃逸或者有其他特别恶劣情节的,处三年以上七年以下有期徒刑;因逃逸致人死亡的,处七年以上有期徒刑。”
A、It’smypleasure.B、It’sheavy.C、Yes,itis.D、That’sgreat.A这是请求对方帮助自己,恰当的回答应是A,“乐意之至”。
CybercrimewhichistheillegalactivitycommittedontheInternetisthefastestgrowingcriminalactivityintheworldandis
最新回复
(
0
)