首页 > 软考
题目内容 (请给出正确答案)
[主观题]

阅读以下说明和C++程序,将应填入(n)处的字句写在对应栏内。【说明】 字符串在程序设计中扮演着重要

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

【说明】

字符串在程序设计中扮演着重要角色。现需要设计字符串基类string,包含设置字 符串、返回字符串长度及内容等功能。另有一个具有编辑功能的串类edlt_string,派生于string,在其中设置一个光标,使其能支持在光标处的插入、删除操作。

【程序】

include <iostream.h>

include <stdio.h>

include <string.h>

class string

{

int length;

char *data;

public:

int get_length() {return length;}

char *get_data() {return data;}

~string() {delete data;}

int set data(int in_length, char *in_data);

int set_data(char *data);

void print() {cout<<data<<endl;}

};

class edit_string: public string

{

int cursor;

public:

int get_cursor() {return cursor;}

void move_cursor(int dis) {cursor=dis;}

int add_data(string *new_data);

void delete_data(int num);

};

int string::set_data(int in_length,char *in_data)

{

length=in_length;

if(!data)

delete data;

(1)

strcpy(data,in_data);

return length;

}

int string::set data(char *in_data)

{

(2)

if(!data)

delete data;

(1)

strcpy(data,in_data);

return length;

}

int edit_string::add_data(string *new_data)

{

int n,k,m;

char *cp,*pt;

n=new_data->get_length();

pt=new_data->get_data();

cp=this->get_data();

m=this->get_length();

char *news=new char[n+m+1];

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

news[i]=cp[i];

k=i;

for(int j=0; j<n; i++,j++)

news[i]=pt[j];

cursor=i;

for(j=k; j<m; j++,i++)

(3)

news[i]='\0';

(4)

delete news;

return cursor;

}

void edit string::delete_data(int num)

{

int m;

char *cp;

cp=this->get_data();

m=this->get_length();

for(int i=cursor; i<m; i++)

(5)

cp[i]='\0';

}

查看答案
答案
收藏
如果结果不匹配,请 联系老师 获取答案
您可能会需要:
您的账号:,可能还需要:
您的账号:
发送账号密码至手机
发送
安装优题宝APP,拍照搜题省时又省心!
更多“阅读以下说明和C++程序,将应填入(n)处的字句写在对应栏内…”相关的问题
第1题
阅读以下说明和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;

}

}

点击查看答案
第2题
阅读以下说明和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;

}

}

点击查看答案
第3题
阅读以下说明和C++ 程序,将应填入(n)处的字句写在对应栏内。 [说明] 试从含有n个int 型数的数组中

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

[说明]

试从含有n个int 型数的数组中删去若干个成分,使剩下的全部成分构成一个不减的子序列。设计算法和编写程序求出数组的不减子序列的长。

[C++ 程序]

include<stdio.h>

define N 100

int b[]={9,8,5,4,3,2,7,6,8,7,5,3,4,5,9,1};

int a [N];

define n sizeofb/sizeofb[0]

void main ()

{

kit k,i,j;

(1)

(2)

for (i=1;i<n; i++ )

{

for (j=k;(3); j--);

(4); /*长为 j+1 的子序列的终元素存储在 a[j+1]*/

if ((5)k++; /*最长不减子序列长 k 增1*/

}

printf ("K = %d\n ",k );

}

点击查看答案
第4题
阅读以下说明和C++程序,将应填入(n)处的字句写在对应栏内。【说明】下面程序的功能是计算并输出某年

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

【说明】

下面程序的功能是计算并输出某年某月的天数,函数IsLeap Year()能够判断是否是闰年。

【C++程序】

include < iostream >

using namespace std;

(1) Month {Jan, Feb, Mar, Apr, May, Jun, Jul, Aug, Sep, Oct, Nov, Dec };

class Date {

public:

Date(int year, Month m_ month) {

this→year = year;

if((2) ) month: Jan;

else month = m_ month;

};

~Date(){};

bool IsLeap Year() {

return ((year%4= =0 &&year% 100 ! =0)|| year%400= =0);

};

int CaculateDays() {

switch(m_month ) {

case (3) ;{

if (4) return 29;

else return 28;

}

case Jan: case Mar: case May: case Jul: case Aug: case Oct: case Dec: return 31;

case Apr: case Jun: case Sop: case Nov: return 30;

}

}

private:

int year;

Month month;

};

void main() {

Date day(2000,Feb);

cout < <day. (5) ();

}

点击查看答案
第5题
阅读以下说明和C++抖程序,将应填入(n)处的字句写在答题纸的对应栏内。【说明】 下面程序的功能是计

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

【说明】

下面程序的功能是计算并输出某年某月的天数。

【C++程序】

include<iostream>

using namespace std;

(1) Month{Jan,Feb,Mar,Art,May,Jun,Jul,Aug,Sep,Oct,Nov,Dec};

class Date{

public:

Date(int year,Month m_month){

(2) =year;

if (m_month<Jan‖m_month>Dec) month=Jan;

else month=m_month;

};

~Date(){};

bool IsLeapYear(){

return ((year%4==0 && year%1001!=0)‖year%400==0);

};

int CaculateDays(){

switch((3) ){

case Feb:{

if((4) )return29;

e1Se return 28;

}

case Jan:case Mar:case May:case Jul:case AUg:case Oct:

case Dec:retllrn 31;

case Apr:case Jun:Case Sep:case Nov:roturu30;

}

};

private:

int year;

Month month;

};

void main(){

Date day(2000,Feb);

tout<<day. (5) ();

}

点击查看答案
第6题
阅读以下说明和C++程序,将应填入(n)处的语句写在的对应栏内。 【说明】 以下程序的功能是计算三角形

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

【说明】

以下程序的功能是计算三角形、矩形和正方形的面积并输出。

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

【C++程序】

include<iostream.h>

include<math.h>

class Figure {

public:

virtual double getArea()=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=lb; this->lc=lc;

}

double getArea() {

double s = (la+lb+±c)/2.0;

return sqrt(s,(s-la)*(s-lb)*(s-Ic));

}

};

void 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;

}

}

点击查看答案
第7题
●试题六 阅读以下说明和C++程序,将应填入(n)处的语句写在答题纸的对应栏内。 【说明】 以下程序

●试题六

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

【说明】

以下程序的功能是计算三角形、矩形和正方形的面积并输出。

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

【C++程序】

#include<iostream.h>

#include<math.h>

class Figure{

public:

virtual double getArea()=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 Ib;

double lc;

public:

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

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

}

double getArea(){

double s=(la+lb+±c)/2.0;

return sqrt(s*(s-1a)*(s-1b)*(s-1c));

}

};

void 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;

}

}

点击查看答案
第8题
试题六(共 15 分) 阅读以下说明和 C++代码,将应填入 (n) 处的字句写在答题纸的对应栏内。 [说明]

试题六(共 15 分)

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

[说明]

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

试题六(共 15 分) 阅读以下说明和 C++代码,将应填入 (n) 处的字句写在答题纸的对应栏内。

[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 << endl;

}

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

0, 1, 2, 3, 4, 5

(5)

点击查看答案
第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++程序,将应填入(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→;

}

点击查看答案
退出 登录/注册
发送账号至手机
密码将被重置
获取验证码
发送
温馨提示
该问题答案仅针对搜题卡用户开放,请点击购买搜题卡。
马上购买搜题卡
我已购买搜题卡, 登录账号 继续查看答案
重置密码
确认修改