首页
外语
计算机
考研
公务员
职业资格
财经
工程
司法
医学
专升本
自考
实用职业技能
登录
计算机
使用VC6打开考生文件夹proj3下的工程proj3,其中定义了一个字符串变量类StringVar。类成员的说明在程序注释中。请在//**********333**********和//**********666**********之间填写StringVa
使用VC6打开考生文件夹proj3下的工程proj3,其中定义了一个字符串变量类StringVar。类成员的说明在程序注释中。请在//**********333**********和//**********666**********之间填写StringVa
admin
2021-05-06
91
问题
使用VC6打开考生文件夹proj3下的工程proj3,其中定义了一个字符串变量类StringVar。类成员的说明在程序注释中。请在//**********333**********和//**********666**********之间填写StringVar成员函数和友元函数的实现代码。在main函数中给出了一组测试数据,运行时输入:
Hello Kitty
此情况下程序的输出应该是:
Hello Kitty
Borg
Borg
注意:只需在//**********333**********和//**********666**********之间填入所编写的若干语句,不要改动程序中的其他内容。
//StringVar.h
#include
#include
#include
#include
USing namespace std;
void writeToFile (const char *
path);
class StringVar
{
public:
StringVar(int size);//构造函数,size为字符串长度(字符个数)初始值;字符串内容初始化为空串
StringVar(const char a[]);//构造函数,用参数数组a的内容初始化当前对象
StringVar (const StringVar&strobj);//复制构造函数
一StringVar(){delete[]value;
};//析构函数
int length()const{return Strlen
(value);)
//从输入流ins输入一个字符串,其中可以包括空格
void input_line(istream&ins);
//返回字符串首地址
char*getValue()const{return
value;}
private:
char*value,//字符串首地址
int max_length;//字符串最大长度(字符
个数最大值)
};
//将the_string通过输出流outs输出
ostream&operator<<(ostream&outs,const
StringVar the_string);
//main.cpp
#include
#include
#include”StringVar.h”
//*********333*********
//*********666*********
int main()
{
StringVar namel(30),name2(”
Borg”);
namel.input_line(cin);
StringVar name3(name2);
cout<
cout<
cout<
writeToFile(”.\\”);
return 0;
}
//writeToFile.cpp
#include
#include
#include
#include
using namespace std;
#include”StringVar.h”
void writeToFile(const char*path)
{
char filename[30];
strcpy(filename,path);
strcat(filename,”out.dat”);
ofstream fout(filename);
istringstream is(string(”Jenny
Zheng”));
StringVar namel(40),name2(”
John”);
name1.input_line(is);
StringVar name3(name2);
fout<
fout.close();
}
选项
答案
StringVar::StringVar(int size):max length(size)//使用成员初始化列表初始化 max_length { value=new char[size]; value[0]=’\0’; } StringVar::StringVar(const char a []) { max_length=strlen(a)+1; value=new char[max_length]; strcpy(value,a), } StringVar:: StringVar (const StringVar&strobj) { max_length=strobJ.max_length; value=new char[strlen(strobj. value)+1]; strcpy(value,strobj.value); } void StringVar::input_line(istream& ins) { int i=0; char ch; while(i
解析
转载请注明原文地址:https://kaotiyun.com/show/tPfp777K
本试题收录于:
二级C题库NCRE全国计算机二级分类
0
二级C
NCRE全国计算机二级
相关试题推荐
设有以下定义和程序:#inc1ude<iostream.h>c1assTestClass1{pubitic:voidshowl0{cout<<"TestClass1"<<end1;
下列有关内联函数的叙述中,正确的是()。
有如下程序:#includeusingnamespacestd;classA{public:A(){COUI
若有以下程序:#includeusingnamespacestd;intfun(){staticinti=0;ints=1;s+=i:i++;Feturn
设有程序段:intk=10;while(k=0)k=k-1;则下面描述中正确的是()。
在对函数进行原型声明时,下列语法成分中,不需要的是()。
下列有关C++流的叙述中,错误的是()。
一棵二叉树中共有80个叶子结点与70个度为1的结点,则该二叉树中的总结点数为()。
一棵二叉树中共有80个叶子结点与70个度为1的结点,则该二叉树中的总结点数为
随机试题
期末考试结束了,初三(14)班的班主任助理王老师需要对本班学生的各科考试成绩进行统计,按照下列要求完成该班的成绩统计工作。调整工作表“期末总成绩”的页面布局以便打印:纸张方向为横向,缩减打印输出使得所有列只占一个页面宽(但不得缩小列宽),水平居中打印在
下列关于数字图书馆的叙述中,不正确的是______。
已知题1—135图中电容器极板间的距离为d,极板面积为s,ε0、ε1介质厚度为d/2,则该电容器的电容应为()。
下列关于实体现金流量的说法中,正确的有()。
某高校赵教授2014年取得部分收入项目如下:(1)1月从学校取得的收入包括基本工资3200元、教授津贴6000元,因公出差取得差旅费津贴420元,按照所在省人民政府规定的比例提取并缴付的“五险一金”1455元。(2)5月10日因担任另一高校的博士论文答
意向缺乏的表现有()。
生产力和生产关系、经济基础和上层建筑之间的矛盾已经不再是社会主义社会的基本矛盾。()
A、Sheoncequittedajobsuddenlywithoutanexplanation.B、Shewasnotongoodtermswithherco-workers.C、Sheoncequittedaf
Cantreestalk?Yes,butnotinwords.Scientistshavereasontobelievethattreesdocommunicatewitheachother.Notlongago
A、Thetime.B、Theschedule.C、Whotreats.D、Bywhatthey’llgo.D本题是细节题。约会的时间,安排,由谁请客都提到了。但没有提到他们怎么去。
最新回复
(
0
)