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

阅读以下说明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();

}

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

阅读以下说明,以及用C++在开发过程中所编写的程序代码,将应填入(n)处的字句写在对应栏内。

【说明】

在下面函数横线处填上适当的字句,使其输出结果为:

构造函数.

构造函数.

1,2

5,6

析构函数

析构函数.

【C++代码】

include "iostream.h"

class AA

{ public;

AA(int i,int j)

{A=i; B=j;

cout<<"构造函数.\n";

}

~AA(){(1);}

void print();

private:

int A, B;

};

void AA∷print()

{cout<<A<<","<<B<<endl;}

void main()

{

AA *a1, *a2;

(2)=new AA(1, 2);

a2=new AA(5, 6);

(3);

a2->print();

(4) a1;

(5) a2;

}

点击查看答案
第2题
试题六(共 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)

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

试题五(共 15分)

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

【说明】

已知类 LinkedList 表示列表类,该类具有四个方法:addElement()、lastElement()、umberOfElement()以及removeLastElement()。四个方法的含义分别为:

void addElement(Object): 在列表尾部添加一个对象;

Object lastElement(): 返回列表尾部对象;

int numberOfElement(): 返回列表中对象个数;

void removeLastElement(): 删除列表尾部的对象。

现需要借助LinkedList来实现一个Stack栈类,C++代码1和C++代码2分别采用继承和组合的方式实现。

【C++代码 1】

class Stack :public LinkedList{

public:

void push(Object o){ addElement(o); }; //压栈

Object peek(){ return (1) ; }; //获取栈顶元素

bool isEmpty(){ //判断栈是否为空

return numberOfElement() == 0;

};

Object pop(){ //弹栈

Object o = lastElement();

(2) ;

return o;

};

};

【C++代码 2】

class Stack {

private:

(3) ;

public:

void push(Object o){ //压栈

list.addElement(o);

};

Object peek(){ //获取栈顶元素

return list. (4) ;

};

bool isEmpty(){ //判断栈是否为空

return list.numberOfElement() == 0;

};

Object pop(){//弹栈

Object o = list.lastElement();

list.removeLastElement();

return o;

};

};

【问题】

若类LinkedList新增加了一个公有的方法removeElement(int index),用于删除列表中第index个元素,则在用继承和组合两种实现栈类Stack的方式中,哪种方式下Stack对象可访问方法removeElement(int index)? (5) (A. 继承 B. 组合)

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

试题五(共15分)

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

【说明】

某数据文件students.txt的内容为100名学生的学号和成绩,下面的程序将文件中的数据全部读入对象数组,按分数从高到低进行排序后选出排名前 30%的学生。

【C++代码】

#include <iostream>

#include <fstream>

#include <string>

using namespace std;

class Student {

private:

string sNO; //学号

int credit; //分数

public:

Student(string a,int b) { sNO = a; credit = b;}

Student(){}

int getCredit();

void out();

};

(1) ::getCredit() {

return credit;

}

(2) ::out() {

cout << "SNO: " << sNO << ", Credit=" << credit << endl;

}

class SortStudent {

public:

void sort(Student *s, int n);

SortStudent(){}

};

void SortStudent::sort(Student *s,int n) {

for(int i = 0; i < n-1; i++) {

for(int j = i+1; j < n; j++) {

if(s[i]. (3) < s[j]. (4) ) {

Student temp = s[i]; s[i] = s[j]; s[j] = temp;

}

}

}

}

int main(int argc, char* argv[])

{

const int number = 100; //学生总数

ifstream students;

students.open("students.txt");

if(!students.is_open()) {

throw 0;

}

Student *testStudent = (5) [number];

int k = 0;

string s;

while (getline(students,s,'\n')) { //每次读取一个学生的学号和成绩

Student student(s.substr(0,s.find(',')), atoi(s.substr(s.find(',')+1).c_str()));

testStudent[k++] = student;

}

students.close();

(6) ;

ss.sort(testStudent,k);

cout <<"top 30%: "<<endl;

for(k = 0; k < number * 0.3; k++) {

testStudent[k].out();

}

delete []testStudent;

return 0;

}

点击查看答案
第5题
●试题一 阅读下列函数说明和C代码,把应填入其中n处的字句写在答卷的对应栏内。 【函数1.1说明】

●试题一

阅读下列函数说明和C代码,把应填入其中n处的字句写在答卷的对应栏内。

【函数1.1说明】

函数strcpy(char*to,char*from)将字符串from复制到字符串to。

【函数1.1】

void strcpy(char*to,char*from)

{while((1 ) );}

【函数1.2说明】

函数merge(int a[ ],int n,int b[ ],int m,int *c)是将两个从小到大有序数组a和b复制合并出一个有序整数序列c,其中形参n和m分别是数组a和b的元素个数。

【函数1.2】

void merge(int a[ ],int n,int b[ ],int m,int *c)

{ int i,j;

for(i=j=0;i<n && j<m;)

*c++=a[i]<b[j]? a[i++]:b[j++];

while((2) )*c++=a[i++];

while((3) )*c++=b[j++];

}

【函数1.3说明】

递归函数sum(int a[ ],int n)的返回值是数组a[ ]的前n个元素之和。

【函数1.3】

int sum(int a[ ],int n)

{ if(n>0)return (4) ;

else (5) ;

}

点击查看答案
第6题
阅读以下说明和c++代码,将应填入(n)处的字句写在答题纸的对应栏内。【说明】c++标准模板库中提供了m

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

【说明】

c++标准模板库中提供了map模板类,该模板类可以表示多个“键一值”对的集合,其中键的作用与普通数组中的索引相当,而值用作待存储和检索的数据。此外,c++模板库还提供了pair模板类,该类可以表示一个“键-值”对。pair对象包含两个属性:first和second,其中first表示“键-值”中的“键”,而Second表示“键-值”中的“值”。map类提供了insert方法和find方法,用于插入和查找信息。应用时,将一个pair。对象插入(insert)到map对象后,根据“键”在map对象中进行查找(find),即可获得一个指向pair对象的迭代器。下面的c++代码中使用了map和pair模板类,将编号为1001、1002、1003的员工信息插入到map对象中,然后输入一个指定的员工编号,通过员工编号来获取员工的基本信息。员工编号为整型编码,员工的基本信息定义为类employee。map对象与员工对象之间的关系及存储结构如图5—1所示。

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

【c++代码】

include

include

include

using namespace std;

class employee {(1) :

employee(string name,string phoneNumber,string address){

this->name=name;

this->phoneNumber=phoneNumber ;

this->address=address;

}

string name;

string phoneNumber;

string address;

);

int main()

{

mapemployeeMap;

typedef pair>employeeNo; //从标准输入获得员工编号

map::const_iterator it;

it= (5) .find(employeeNo); //根据员工编号查找员工信息

if(it==employeeMap.end()){

cout<first<second一>nafae(phoneNumber<second->address<

点击查看答案
第7题
阅读下列说明和c++代码,将应填入(n)处的字句写在答题纸的对应栏内。【说明】现欲构造一文件/目录树,

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

【说明】

现欲构造一文件/目录树,采用组合(Composite)设计模式来设计,得到的类图如6—7所示:

阅读下列说明和c++代码,将应填入(n)处的字句写在答题纸的对应栏内。【说明】现欲构造一文件/目录树

【c++代码】

include<1ist>

include

include

using namespace std;

class AbstractFile{

protected:

string name;//文件或目录名称

public:

void printName(){cout<*getChildren()=0; //获得一个目录的子目录或文件

};

class File:public AbstractFile{

public:

File(string name){ (1) =name;)

void addChild(AbstractFile*file){return ;)

void removeChiid(AbstractFile*file){return;}(2) getChildren(){return (3 ) ;}

};

class Folder:public AbstractFile{

private:

listchildList; //存储子目录或文件

public:

Folder(string name){ (4) =name;}

void addChild(AbstractFile*file){childList.push back(file);}

void removeChiid(AbstractFile*file)(chiidList.remove(file);}

list*getChildren(){return (5) ;)

};

voidmain(){

//构造一个树形的文件/目录结构

AbstractFile*rootFolder=new Folder(“C:\\”);

AbstractFile*compositeFolder=flew Folder(”composite”);

AbstractFile*windowsFolder=new Folder(”windows”);

AbstractFile*file=new File(”TestComposite.java”);

rootFolder->addChild(compositeFolder);

rootFolder->addChild (windowsFolder);

compositeFolder->addChiid(file);

)

点击查看答案
第8题
阅读下列说明和c++代码,将应填入(n)处的字句写在答题纸的对应栏内。【说明】某软件公司现欲开发一款

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

【说明】

某软件公司现欲开发一款飞机飞行模拟系统,该系统主要模拟不同种类飞机的飞行特征与起飞特征。需要模拟的飞机种类及其特征如表5-l所示。

阅读下列说明和c++代码,将应填入(n)处的字句写在答题纸的对应栏内。【说明】某软件公司现欲开发一款

为支持将来模拟更多种类的飞机,采用策略设计模式(Strategy)设计的类图如图5—1所示。

图5-l中,AirCraft为抽象类,描述了抽象的飞机,而类Helicopter、AirPlane、Fighter和Harrier分别描述具体的飞机种类,方法fly()和takeOff()分别表示不同飞机都具有飞行特征和起飞特征;类FlyBehavior与TakeOffBehavior为抽象类,分别用于表示抽象的飞行行为与起飞行为;类SubSonicFly与SuperSonicFly分别捕述亚音速飞行和超音速飞行的行为;类Verti calTakeOff与LongDistanceTakeoff分别描述垂直起飞与长距离起飞的行为。

阅读下列说明和c++代码,将应填入(n)处的字句写在答题纸的对应栏内。【说明】某软件公司现欲开发一款

【C++代码】

include

using namespace std;

class FlyBehavior{

public:virtual void fly()=0;

};

class SubSonicFly:public FlyBehavior{

public: void fly(){cout<<"亚音速飞行! "<

点击查看答案
第9题
阅读以下说明及C++程序代码,将应填入(n)处的语句写在对应栏内。【说明】 本程序的功能是根据矩形左

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

【说明】

本程序的功能是根据矩形左上角和右下角顶点坐标生成一个矩形对象,然后输出该矩形4个顶点的坐标,计算并输出该矩形的面积。

【C++代码】

include<iostream>

using namespace std;

class MyPoint(//表示平面坐标系中的点的类

double x;

double y;

public:

MyPoint (double x,double y){this->x=x;this->y=y;}

double getX()const{(1);}

double getY()const{ return y;}

void show()const{ cout<<'('<<x<<','<<y<<')';}

};

class MyRectangle{ //表示矩形的类

MyPoint upleft; //矩形的左上角顶点

MyPoint down right; //矩形的右下角顶点

public:

MyRectangle(MyPoint upleft,MyPoint downright);

MyPoint getUpLeft()const{return up_left;} //返回左上角坐标

MyPoint getDownRight()const{return down_right;} //返回右下角坐标

MyPoint getUpRight()const; //返回右上角坐标

MyPoint getDownLeft()const; //返回左下角坐标

double area()const; //返回矩形的面积

};

MyRectangle:: MyRectangle((2)):

up left(p1),down_right(p2){}

MyPoint MyRectangle::getUpRight()const

{

return MyPoint(down_right.getX(),up_left.getY());

}

MyPoint MyRectangle::getDownLeft()const

{

return MyPeint((3));

}

double (4) ::area()const

{

return (getUpLeft(),getX()-getDownRight().getX())*

(getDownRight().getY()-getUpLeft().getY());

}

int main()

{

MyRectangle r(MyPoint(0,2),MyPoint(2,0));

r.getUpLeft(),show();

r.getUpRight().show();

r.getDown Right().show();

(5);

cout<<r.area()<<end1;

return 0;

}

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