首页
外语
计算机
考研
公务员
职业资格
财经
工程
司法
医学
专升本
自考
实用职业技能
登录
计算机
使用Vc6打开考生文件夹proj3下的工程proj3,其中声明了NyString类,它是一个用于表示字符串的类。成员函数reverse将字符串反转,例如“abode”反转后就成了“edcba”。请补充完整函数reverse。在main函数中给出了一个测试数
使用Vc6打开考生文件夹proj3下的工程proj3,其中声明了NyString类,它是一个用于表示字符串的类。成员函数reverse将字符串反转,例如“abode”反转后就成了“edcba”。请补充完整函数reverse。在main函数中给出了一个测试数
admin
2019-06-05
29
问题
使用Vc6打开考生文件夹proj3下的工程proj3,其中声明了NyString类,它是一个用于表示字符串的类。成员函数reverse将字符串反转,例如“abode”反转后就成了“edcba”。请补充完整函数reverse。在main函数中给出了一个测试数据,此情况下程序的输出应该是:
This is a string
gnirtS a si sihT
注意:只需在函数reverse的//********333********和//********666********之间填入若干语句,不要改动程序中的其他内容。
//NyString.h
#include<iostream>
usirig namespace std;
char * dup(const char *);
class NyString{
char * str;
public:
NyString(const char * s=""):str(dup(s){}
NyString(const NyString&m):str(dup(m.str)){}
~HySting(){delete[]str;}
void reverse();
void show(ostream&os=tout)
const{os<<str<<end1;)
};
inline ostream&operator<<fostrearn& os,const NyString&m){
m.show(os);
return os;
}
void writeTOFile(const char *
path);
//NyString.cpp
#include"NyString.h"
char * clup(const ohar * s){
char * p=new char[strlen(s)+1];
strcpy(p,s);
return p;
}
void NyString∷EeveEse(){
//********333********
//********666********
}
void writeToFile(const char *path);
//writetoFile.cpp
#include<fstream>
#include"MyString.h"
void writeToFile(const char *path){
char full150;
strcpy(full,path);
Strcat(full,"out.dat");
OfStream outfile(full);
if(outfile.fail()){cerr<<"打开输出文件失败!";return;}
MyString m1:"This is another string";
MyString m2("字符串反转演不");
outfile<<m1<<m2:
m1.reverse();
m2.reverse();
outfile<<m1<<m2;
outfile.close();
}
选项
答案
void MyString∷reverse() { int i,i; char ch; int len=strlen(str); for(i=0,j=len-1;i<j;i++,j--) { ch=str[i]; str[i]=str[j]; str[j]=ch; } }
解析
转载请注明原文地址:https://kaotiyun.com/show/Y18p777K
本试题收录于:
二级C题库NCRE全国计算机二级分类
0
二级C
NCRE全国计算机二级
相关试题推荐
下面类的声明中的几个语句,正确的是(设定语句是主函数中的语句)()。classTestClass{private:intdata;public:TestClass(intg_data)
下面关于虚函数的描述中,正确的是()。A)基类中利用virtual关键字说明一个虚函数后,其派生类中定义相同的原型函数时可不必加virtual来说明B)虚函数是非成员函数C)虚函数是static类型的成员函数D)派生类中的虚函数与基
有如下定义:intb[10]={1,2,3,4,5,6,7,8,9,10},*q=b;则数值为8的表达式是()。A)*q+8B)*(q+7)C)*q+=8D)q+7
下列工具中,不属于结构化分析的常用工具的是()。A)PAD图B)数据字典C)判定树D)数据流图
C++中将两个字符串连接起来组成一个字符串的函数是______。
A、 B、 C、 D、 C软件的生命周期可分为软件定义、软件开发及软件运行维护三个阶段。其中软件定义阶段的主要工作有可行性研究与计划制订和需求分析等;软件开发阶段的主要工作有概要设计、详细设计和测试等;软件运
A、 B、 C、 D、 B常用的软件结构设计工具是结构图,也称程序结构图。DFD图(数据流图)是以图形的方式描述数据在系统中流动和处理的过程,只反映系统必须完成的逻辑功能,它是需求分析阶段的图形工具。盒式图(
有如下语句序列:intx=-10;while(++x){}运行时while循环体的执行次数为______。
C++中的模板分为函数模板和______。
在对函数进行原型声明时,下列语法成分中,不需要的是()。A)函数返回类型B)函数参数列表C)函数名D)函数体
随机试题
A.肝细胞广泛水样变性、点灶状坏死B.肝细胞广泛脂肪变性、点灶状坏死C.肝细胞碎片坏死D.肝细胞亚大片坏死E.肝细胞大片坏死(2002年)急性普通型肝炎的病变特点
以下何项不是癫证的表现
国际标准化组织推荐的噪声强度卫生学评阶指标是
体内合成N-亚硝基化合的主要部位
化疗药剂量计算的主要依据是()
[2008年第25题]博物馆采光设计不宜采取下列哪种措施?
纳税人改变单位名称或法人代表不需要办理税务登记。 ( )
下列关于准备金的24个半月提存法,表述正确的有()。
橘生淮南则为橘,生于淮北则为枳。外部环境对人的影响虽不是根本的,但也是十分重大的。这句话意味着( )。
Youwillhearfiveshortrecordingsaboutdeliveryproblems.Foreachrecording,decidewhichproblemthespeakertalksabou
最新回复
(
0
)