题目内容 (请给出正确答案)
[主观题]

阅读下列程序说明和C++程序,把应填入其中(n)处的字句,写对应栏内。【说明】 下面的程序实现了类Stri

阅读下列程序说明和C++程序,把应填入其中(n)处的字句,写对应栏内。

【说明】

下面的程序实现了类String的构造函数、析构函数和赋值函数。

已知类String的原型为:

class String

{

public:

String(coust char * str = NULL); //普通构造函数

String(const String &other); //拷贝构造函数

~String(void); //析构函数

String & perate =(const String &other); //赋值函数

private:

char * m_data; // 用于保存字符串

};

//String 的析构函数

String:: ~String (void)

{

(1);

}

//String 的普通构造函数

String: :String(const char * str)

{

if (2)

{

m_data = new char[1];

*m_data = '\0';

}

else

{

int length = strlen(str);

m_data = new ehar[ length + 1 ];

strepy(m_data, str);

}

}

//拷贝的构造函数

String:: String(const String &other)

{ int length = strlen(other. m_data);

m_data = new char[ length + 1 ];

strepy(m_data, other, m_data); //赋值函数

String & String::operate = (eonst String &other) //

{

if (3)

return * this;

delete [] m_clara; //释放原有的内存资源

int length = strlen(other, m_data);

m_data = new chart length + 1 ];

(4);

return (5);

}

查看答案
如搜索结果不匹配,请 联系老师 获取答案
您可能会需要:
您的账号:,可能会需要:
您的账号:
发送账号密码至手机
发送
更多“阅读下列程序说明和C++程序,把应填入其中(n)处的字句,写…”相关的问题

第1题

阅读下列程序说明和C++程序,把应填入其中(n)处的字句,写在对应栏内。【说明】阅读下面几段C++程序回

阅读下列程序说明和C++程序,把应填入其中(n)处的字句,写在对应栏内。

【说明】

阅读下面几段C++程序回答相应问题。

比较下面两段程序的优缺点。

①for (i=0; i<N; i++ )

{

if (condition)

//DoSomething

else

//DoOtherthing

}

②if (condition) {

for (i =0; i<N; i++ )

//DoSomething

}else {

for (i=0; i <N; i++ )

//DoOtherthing

}

点击查看答案

第2题

阅读下列C++程序和程序说明,将应填入(n)处的字句写在对应栏内。【说明】 以下C++程序的功能是计算三

阅读下列C++程序和程序说明,将应填入(n)处的字句写在对应栏内。

【说明】

以下C++程序的功能是计算三角形、矩形和正方形的面积并输出。程序由4个类组成:类Triangle、Rectangle和Square分别表示三角形、矩形和正方形;抽象类Figure提供了一个纯虚拟函数getArea(),作为计算上述3种图形面积的通用接口。

include<iostream.b>

include<math.h>

class Figure{

public:

virtual double getArea0=0; //纯虚拟函数

};

class Rectangle: (1) {

protected:

double height;

double width;

public:

Rectangle(){};

Rectangle(double height, double width){

This->height=height;

This->width=width;

}

double getarea(){

return (2);

}

};

class Square: (3) {

public:

Square(double width){

(4);

}

};

class Triangle: (5) {

double la;

double lb;

double lc;

public:

Triangle(double la, double lb, double lc){

this->la=la; this->lb; this->lc;

}

double getArea(){

double s=(la+lb+lc)/2.0;

return sqrt(s*(s-la)**(s-lb)*(s-lc));

}

};

viod main(){

Figure* figures[3]={

new Triangle(2,3,3), new Rectangle(5,8), new Square(5));

for(int i=0;i<3;i++){

cout<<"figures["<<i<<"]area="<<(figures[i])->getarea()<<endl;

}

}

点击查看答案

第3题

●试题五 阅读下列程序说明和C++代码,将应填入(n)处的字句写在答卷的对应栏内。 【说明】 ①在类体

●试题五

阅读下列程序说明和C++代码,将应填入(n)处的字句写在答卷的对应栏内。

【说明】

①在类体中添加函数move(double ax, double ay)的定义,使得点的坐标x和y分别移动ax和ay个单位。

②在类定义外完成重载的两个构造函数CPosition()和CPosition(double dx, double dy),其中前者为不带参数的构造函数,使CPosition对象的默认值为x=0,y=0,后者为带参数的构造函数,把数据成员x和y分别初始化为参数dx和dy的值。

③完成函数double distance(double bx, double by)的定义,该函数返回*this和点(bx,by)的距离。

注意:除在指定的位置添加语句外,请不要改动程序中的其他语句。

源程序文件test5.cpp清单如下:

#include<iostream.h>

#include <math.h>

class CPosition

{

public:

CPosition();

CPosition(double dx, double dy);

double getx();

double gety();

(1)

double distance(double bx, double by);

private:

double x;

double y;

};

(2)

{

x=0; y=0;

}

CPosition::CPosition(double dx, double dy)

{

x=dx; y=dy;

}

double CPosition::getx()

{

return x;

}

double CPosition::gety()

{

return y;

}

double CPosition::distance(double bx, double by)

{

(3)

}

void main()

{

double a,b;

cout << "Input x, y position of a point: ";

cin >> a >> b;

CPosition psA(a, b);

cout << "Input x, y position of another point: ";

cin >> a >> b;

cout << "The distance is " << psA.distance(a,b) <<endl;

}

点击查看答案

第4题

阅读下列程序说明和C++代码,将应填入(n)处。【说明】 ①在类体中添加函数move(double ax,double ay)

阅读下列程序说明和C++代码,将应填入(n)处。

【说明】

①在类体中添加函数move(double ax,double ay)的定义,使得点的坐标x和y分别移动 ax和ay个单位。

②在类定义外完成重载的两个构造函数CPosition()和CPosition(double dx,double dy),其中前者为不带参数的构造函数,使CPosition对象的默认值为x=0,y=0,后者为带参数的构造函数,把数据成员x和y分别初始化为参数dx和dy的值。

③完成函数double distance(double bx,double by)的定义,该函数返回*this和点(bx, by)的距离。

注意:除在指定的位置添加语句外,请不要改动程序中的其他语句。

源程序文件test5.cpp清单如下:

include<iostream.h>

include<math.h>

class CPosition

{

public:

CPosition();

CPosition(double dx,double dy);

double getx();

double gety();

(1)

double distance(double bx,double by);

private:

double x;

double y;

};

(2)

{

x=0;y=0;

}

CPosition::CPosition(doub,e dx,doub,e dy)

{

x=dx; y=dy;

}

double CPosition::getx()

{

return x;

}

double CPosition::gety()

{

return y;

}

double CPosition::distance(double bx,double by)

{

(3)

}

vold main()

{

double a,b;

cout<<"|nput x,y position of a point:";

cin >> a >> b;

CPosition psA(a,b);

cout<<"Input x,y position of another point:";

cin >>a >> b;

cout <<"The distance is" <<psA.distance(a,b) <<end1;

}

点击查看答案

第5题

阅读以下说明和C++程序,将应填入(n)处的字句写在对应栏内。[说明] 本程序中预设了若干个用户名和

阅读以下说明和C++程序,将应填入(n)处的字句写在对应栏内。

[说明]

本程序中预设了若干个用户名和口令。用户输入正确的用户名后,可以查找对应的口令,一旦输入结束标记“end”,程序结束。

[C++程序]

include <iostream. h>

include <string. h>

class User

{ protected:

char user[10];

char pass[7];

public:

User(char[ ],char[]);

(1) {return user;}

(2) {return pass;}

};

User::User(char u[],char p[])

{ strcpy(user,u);

strcpy(pass,p); }

void main()

{ User ua[]={User("Li","123456"),User("wang","654321"),User("Song","666666")

char name[10];

while(1)

cout< < "输入用户名:";

cin> >name;

if((3)= =0) break;

for(int i=0;i<3;i+ +)

if(strcmp(name,ua[i].getuser()) = =0){

cout< <"密码:" < < ua[i].getpass() < <endl;

(4);

if((5))cout< <"该用户不存在!" < <endl;

}

}

点击查看答案

第6题

阅读以下说明和C++程序,将应填入(n)处的字句写在对应栏内。【说明】以下程序实现了二叉树的结点删除

阅读以下说明和C++程序,将应填入(n)处的字句写在对应栏内。

【说明】以下程序实现了二叉树的结点删除算法,若树中存在要删除的结点,则删除它,否则返回。 FindNode ()函数能够在二叉树中找到给定值的结点,并返回其地址和父结点。

【C++程序】

template < class T >

void BinSTree < T >: :Delete(const T& item)

{

TreeNode < T > * DelNodePtr, * ParNodePtr, * RepNodePtr;

if((DelNodePtr = FindNode (item,ParNodePtr)) = = NULL)

(1)

if(DelNodePtr→right = = NULL) //被删除结点只有一个子结点的情况

RepNodePtr = DelNodePtr→left;

else if(DelNodePtr→left = = NULL)

(2);

else // 被删除结点有两个子结点的情况

{

TreeNode < T >* PofRNodePtr = DelNodePtr;

RepNodePtr = DelNodePtr→left;

while(RepNodePtr→right ! = NULL)

{ //定位左子树的最右结点

PofRNodePtr =RepNodePtr;

RepNodePtr = RepNodePtr→right;

}

if(PofRNodePtr = = DelNodePtr) //左子树没有右子结点

(3);

else //用左子顷的最右结点替换删除的结点

{

(4)

RepNodePtr→left = DelNodePtr→left;

RepNodePtr→right = DelNodePtr→right;

}

}

if (5)//要删除结点是要结点的情况

root = RepNodePtr;

else if (DelNodePtr→data < ParNodePtr→Data)

ParNodePtr→left = RepNodePtr;

else

ParNodePtr→right =RepNodePtr;

FirstTreeNode (DelNodePtr ) ;//释放内存资源

size→;

}

点击查看答案

第7题

阅读以下说明C++代码,将应填入(n)处的字句写在对应栏内。[说明] 本程序实现了雇员信息管理功能,其

阅读以下说明C++代码,将应填入(n)处的字句写在对应栏内。

[说明]

本程序实现了雇员信息管理功能,其中封装了雇员信息及其设置、修改、删除操作。已知当输入为“Smith 31 2960.0”时,程序的输出是:

姓名:Smith 年龄:31 工资:2960

姓名:Smith 年龄:31 工资:3500

姓名:Mary 年龄:23 工资:2500

[C++程序]

include <iostream.h>

include <string.h>

class employee{

char *name; //雇员姓名

short age; //年龄

float salary;//工资

public:

employee();

void set_name(char *);

void set_age(short a) {age=a;}

void set_salary(float s) {salary=s;}

(1);

~ employee(){delete[] name;}

};

employee::employee() { name="";

age=0;

salary=0.0;

void employee::set_name(char *n)

{ name=new char[strlen(n)+1];

(2) (name,n);

}

void employee::print()

{ cout<<"姓名":"<<name<<" 年龄:"<<agc<<" 工资:" <<salary<<endl;

}

void main()

{ char *na;

short ag=0;

float sa=0;

(3);

na=new char[10];

cin>>na>>ag>>sa;

emp.set_name(na);

emp.set_age(ag);

emp.set_salary(sa);

emp.print();

(4) (3500.0);

emp.print();

(5);

emp.set_name("Mary");

emp.set_age(23);

emp.set_salary(2500.0);

emp.print();

}

点击查看答案

第8题

阅读以下说明和C++程序,将应填入(n)处的字句写在对应栏内。 [说明] 下面程序实现十进制向其它进

阅读以下说明和C++程序,将应填入(n)处的字句写在对应栏内。

[说明]

下面程序实现十进制向其它进制的转换。

[C++程序]

include"ioStream.h"

include"math.h"

include

typedef struct node {

int data;

node*next;

}Node;

Class Transform.

{

DUDlic:

void Trans(int d,int i); //d为数字;i为进制

void print();

private:

Node*top;

};

void Transform.:Trans(int d,int i)

{

int m,n=0;

Node*P;

while(d>0)

{

(1);

d=d/i;

p=new Node;

if(!n){

p->data=m;

(2);

(3);

n++;

}

else{

p->data=m;

(4);

(5);

}

}

}

void Transform.:print()

{

Node*P;

while(top!=NULL)

{

p=top;

if(p->data>9)

cout<<data+55;

else

cout<<data;

top=p->next;

delete p;

}

}

点击查看答案

第9题

阅读以下说明和C++程序,将应填入(n)处的字句写在答题纸的对应栏内。 【说明】 本程序用于评选优秀教

阅读以下说明和C++程序,将应填入(n)处的字句写在答题纸的对应栏内。

【说明】

本程序用于评选优秀教师和学生。当输入一系列教师或学生的记录后,将优秀学生及教师的姓名列出来。其类结构如下图所示:

阅读以下说明和C++程序,将应填入(n)处的字句写在答题纸的对应栏内。 【说明】 本程序用于评选优秀

【程序】

include <iostream.h>

include <stdio. h>

class base

{

protected:

char name[8];

public:

void getname(){cout<<"name:"; cin>>name;}

void printname(){cout<<"name:"<<name<<endl;}

(1)

};

class student: (2)

{

int num;

public:

void getnum()

{cout<<"score:"; cin>>num;}

bool isgood()

{return (3) }

};

class teacher: (2)

{

int num;

public:

void getnum()

{cout<<"paper:"; cin>>num;}

bool isgood()

{return (num>3)?true:false;}

void main()

{

base *p[50];

student *pstud;

teacher *ptech;

char ch;

int count=0;

do{

cout<<"input teacher(t) or student(s):";

cin>>ch;

if(ch=='s')

{

pstud=new student;

pstud->getname();

pstud->getnum();

p[count++]=pstud;

}

else if(ch=='t')

{

(4)

ptech->getname();

ptech->getnum();

p[count++]=ptech;

}

else

cout<<"input is wrong"<<endl;

cout<<"continue to iput(y/n)?";

cin>>ch;

}while(ch=='y');

for(int i=0;i<count;i++)

if((5))

p[i]->printname();

}

点击查看答案

第10题

阅读以下说明和C++代码,将应填入(n)处的字句写在对应栏内。 【说明】 C++标准模板库中提供了vector

阅读以下说明和C++代码,将应填入(n)处的字句写在对应栏内。

【说明】

C++标准模板库中提供了vector模板类,可作为动态数组使用,并可容纳任意数据类型,其所属的命名空间为std。vector模板类的部分方法说明如下表所示:

阅读以下说明和C++代码,将应填入(n)处的字句写在对应栏内。 【说明】 C++标准模板库中提供了v

【C++代码】

include <iostream>

include <vector>

using namespace (1);

typedef vector< (2) > INTVECTOR;

const int ARRAY_SIZE = 6;

void ShowVector (INTVECTOR &theVector);

int main() {

INTVECTOR theVector;

// 初始化 theVector, 将theVector的元素依次设置为0至5

for (int cEachItem = 0; cEachItem < ARRAY_SIZE; cEachItem++}

theVector.push_back((3));

ShowVector(theVector); // 依次输出theVector中的元素

theVector.erase (theVector.begin () + 3};

ShowVector(theVector);

}

void ShowVector (INTVECTOR &theVector) {

if (theVector.empty ()) {

cout << "theVector is empty." << endl; return;

}

INTVECTOR::iterator (4);

for (theIterator=theVector.begin(); theIterator !=theVector.end(); theIterator++) {

cout << *theIterator;

if (theIterator != theVector.end()-1) cout << ", ";

}

cout << end1;

}

该程序运行后的输出结果为:

0,1,2,3,4,5

(5)

点击查看答案
发送账号至手机
密码将被重置
获取验证码
发送
温馨提示
该问题答案仅针对搜题卡用户开放,请点击购买搜题卡。
马上购买搜题卡
我已购买搜题卡, 登录账号 继续查看答案
重置密码
确认修改
温馨提示
每个试题只能免费做一次,如需多次做题,请购买搜题卡
立即购买
稍后再说
警告:系统检测到您的账号存在安全风险

为了保护您的账号安全,请在“赏学吧”公众号进行验证,点击“官网服务”-“账号验证”后输入验证码“”完成验证,验证成功后方可继续查看答案!

微信搜一搜
赏学吧
点击打开微信
警告:系统检测到您的账号存在安全风险
抱歉,您的账号因涉嫌违反赏学吧购买须知被冻结。您可在“赏学吧”微信公众号中的“官网服务”-“账号解封申请”申请解封,或联系客服
微信搜一搜
赏学吧
点击打开微信