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

试题五(共15分)阅读以下说明和C++代码,填补C++代码中的空缺(1)~(6),将解答写在答题纸的对应栏内。

试题五(共15分)

阅读以下说明和C++代码,填补C++代码中的空缺(1)~(6),将解答写在答题纸的对应栏内。

【说明】

已知某公司按周给员工发放工资,其工资系统需记录每名员工的员工号、姓名、工资等信息。其中一些员工是正式的,按年薪分周发放(每年按52周计算);另一些员工是计时工,以小时工资为基准,按每周工作小时数核算发放。

下面是实现该工资系统的C++代码,其中定义了四个类:工资系统类PayRoll,员工类Employee,正式工类Salaried和计时工类Hourly,Salaried和Hourly是Employee的子类。

【C++代码】

//头文件和域名空间略

const int EMPLOYEE_NUM=5;

class Employee{

protected:

int empCode; ∥员工号

string name; ∥员工姓名

double salary; ∥周发放工资

public:

Employee(const int empCode, const string &name){

this->empCode= empCode; this->name= name;

}

virtual~Employee(){}

virtual void pay()=0;

double getSalary(){ return this->salary; }

};

class Salaried (1){

private: double payRate; //年薪

public:

Salaried(const int empCode,const string &name,double payRate)

:Employee(empCode,name){

this->payRate= payRate;

}

void pay(){

this->salary=(2) ;//计算正式员工的周发放工资数

cout<<this->name<<":"<<this->salary<<endl;

}

};

class Hourly (3) {

private:

double payRate; //小时工资数

int hours; //周工作小时数

public:

Hourly(const int empCode, const string &name, int hours, double payRate)

:Employee(empCode,name){

this->payRate= payRate; this->hours= hours,

}

void pay(){

this->salary= (4) ;//计算计时工的周发放工资数

cout<<this->name<<":"<<this->salary<<endl;

}

};

class PayRoll{

public:

void pay(Employee* e[]){

for (int i=0;i<EMPLOYEE_ NUM; i++){

e[i]->pay();

}

}

};

int main(){

PayRoll* payRoll= new PayRoll;

(5)employees[EMPLOYEE_ NUM]={

new Salaried(l00l,"Zhang San", 58000.00),

//此处省略对其他职工对象的生成

new Hourly(1005,"L1", 12, 50.00),

};

payRoll->pay ((6) );

double total= 0.0;

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

{ total+=employees[il->getSalary(); } //统计周发放工资总额

cout<<"总发放额="<<total<<endl;

delete payRoll; retum 0;

}

查看答案
答案
收藏
如果结果不匹配,请 联系老师 获取答案
您可能会需要:
您的账号:,可能还需要:
您的账号:
发送账号密码至手机
发送
安装优题宝APP,拍照搜题省时又省心!
更多“试题五(共15分)阅读以下说明和C++代码,填补C++代码中…”相关的问题
第1题
试题五(共 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. 组合)

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

}

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

试题五(共15分)

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

【说明】

某发票(lnvoice)由抬头(Head)部分、正文部分和脚注(Foot)部分构成。现采用装饰(Decorator)模式实现打印发票的功能,得到如图5-1所示的类图。

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

【C++代码】

include <iostream>

using namespace std;

class invoice{

public:

(1) {

cout《 "This is the content of the invoice!"《 endl;

}

};

class Decorator : public invoice {

Invoice *ticket;

public:

Decorator(lnvoice *t) { ticket = t; }

void printinvoice(){

if(ticket != NULL)

(2);

}

};

class HeadDecorator : public Decorator{

public:

HeadDecorator(lnvoice*t): Decorator(t) { }

void printinvoice0 {

cout《 "This is the header of the invoice! "<< endl;

(3) ;

}

};

class FootDecorator : public Decorator{

public:

FootDecorator(invoice *t): Decorator(t) { }

void printlnvoice() {

(4) ;

cout《 "This is the footnote of the invoice!"《 endl;

}

};

int main(void) {

Invoice t;

FootDecorator f(&t);

HeadDecorator h(&f);

H.printlnvoice();

cout< < “_____”< < endl;

FootDecorator a(NULL);

HeadDecorator b((5) );

B.printinvoice();

return 0;

}

程序的输出结果为:

This is the header of the invoice!

This is the content of the invoice!

This is the footnote of the invoice!

----------------------------

This is the header of the invoice!

This is the footnote of the invoice!

点击查看答案
第4题
试题五(共15分) 阅读以下说明,回答问题1至问题3,将解答填入答题纸的对应栏内。 【说明】 小明在一家

试题五(共15分)

阅读以下说明,回答问题1至问题3,将解答填入答题纸的对应栏内。

【说明】

小明在一家超市工作,该超市将进行整体改造,小明负责信息系统软硬件升级,他制定的工作计划如表5.1所示。

试题五(共15分) 阅读以下说明,回答问题1至问题3,将解答填入答题纸的对应栏内。 【说明】 小明在

每项任务的逻辑关系和部分时间信息如图5-1所示。

试题五(共15分) 阅读以下说明,回答问题1至问题3,将解答填入答题纸的对应栏内。 【说明】 小明在

【问题1】 (10分)

请根据表5-1和图5-1,计算各项任务的最迟开始时间和最迟结束时间,填充图5-1中的空(1)~(10)。

点击查看答案
第5题
阅读以下说明和C++码,将应填入(n)处的字名写在对应栏内。 从下列的3道试题(试题五至试题七)中任选

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

从下列的3道试题(试题五至试题七)中任选1道解答。

如果解答的试题数超过1道,则题号小的1道解答有效。

[说明] 编写程序,把从键盘上输入的一批整数(以-1作为终止输入的标志)保存到文本文件“a: xxk1. dat”中。

(1)

include <fstream. h >

include < stdlib. h >

void main () {

(2)

if (! four) {

cerr < <“文件没有找开!” < <end1;

exit (1);

}

int x;

cin > >x;

while((3)){

(4)

cin> >x;

}

(5)

}

点击查看答案
第6题
试题五(共15分) 阅读下列说明,回答问题1至问题4,将解答填入答题纸的对应栏内。 【说明】 当

试题五(共15分)

阅读下列说明,回答问题1至问题4,将解答填入答题纸的对应栏内。

【说明】

当前,无论是政府、企业、学校、医院,还是每个人的生活,无不受信息化广泛而深远的影响。

信息化有助于推进四个规代化,同时也有赖于广泛应用现代信息技术。信息化既涉及国家信息化、国民经济信息化、社会信息化,也涉及企业信息化、学校信息化、医院信息化等。

国家信息化就是在国家统一规划和组织下,在农业、工业、科学技术、国防和社会生活各个方面应用现代信息技术,深入开展、广泛利用信息资源,发展信息产业,加速实现国家现代化的过程。

而企业信息化是挖掘企业先进的管理理念,应用先进的计算机网络技术整合企业现有的生产、经营、设计、制造、管理,及时地为企业的“三层决策”系统提供准确而有效的数据信息附程。

【问题1】(5分)

本题说明中关于国家信息化的定义包含了哪四个方面的含义?

【问题2】(3分)

企业的“三层决策”系统指的是哪三个层次?

【问题3】(3分)

企业的信息化有不同的分类方式,可按企业所处行业分类,或按企业的运营模式分类。下列企业信息化的类型,哪些是按照所处的行业划分的?哪些是按照企业的运营模式划分的?

A. 离散型企业的信息化

B. 流趟企蝉信息化

C. 制造业的信息化

D. 商业的信息化

E. 金融业的信息化

F. 服务业的信息化

【问题4】(4分)

在企业信息化建设中,目前比较常用的企业信息化建设的应用软件主要有ERP,CRM,SCM和ABC,请分别写出它们的中文名称。

点击查看答案
第7题
试题五(共15分)阅读以下说明和C 函数,将应填入(n) 处的字句写在答题纸的对应栏内。[说明]某班级有

试题五(共15分)

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

[说明]

某班级有N 名学生,他们可根据自己的情况选修名称和数量不尽相同的课程。设N,如图5-1 所示。

试题五(共15分)阅读以下说明和C 函数,将应填入(n) 处的字句写在答题纸的对应栏内。[说明]某班

程序中相应的类型定义如下:

define N 6

struct node{

char cname[5]; /*课程名*/

int grade; /*成绩*/

struct node *next; /*指针,指示某学生选修的下一门课程及成绩*/

};

struct student{

char xh[5]; /*学号*/

char name[20]; /*姓名*/

struct node *link; /*指针,指示出选修的课程及成绩链表*/

}stud_info[N];

stud_info[]为一个全局数组。

函数func (char kc[],int *num)的功能是统计选修了课程名为kc 的学生的人数,

并返回该课程的平均成绩(若无人选修该课程,则平均成绩为0),参数num 带回选修课程kc 的学生人数。

[C函数]

double func (char kc[],int *num)

{

int i,count = 0,sum = 0; /*count用于记录选修课程名为kc 的学生的人数*/

double avg = 0.0;

struct node *p;

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

p = (1) ; /*取第i 个学生所修课程链表的头指针*/

while (p) {

if ((2) ) {

sum = (3) ;

count++;

break;;

}/*if*/

p = p->next;

}/*while*/

}

(4) ;

if ((5) )

avg = (double)sum / count; /* 计算平均成绩 */

return avg;

}/*func*/

点击查看答案
第8题
试题五(共 15 分) 阅读下列说明、图和C++代码,回答问题1 至问题3,将解答写在答题纸的对应栏内。 [

试题五(共 15 分)

阅读下列说明、图和C++代码,回答问题1 至问题3,将解答写在答题纸的对应栏内。

[说明]

已知四个类之间的关系如图 5-1 所示,分别对每个类的方法进行编号,例如 Shape的 perimeter()方法为 1 号,表示为“1:perimeter()” ,Rectangle 类的 perimeter()为2号,表示为“2:perimeter()” ,依此类推,其中,每个类的 perimeter方法都为虚函数且方法签名相同。

试题五(共 15 分) 阅读下列说明、图和C++代码,回答问题1 至问题3,将解答写在答题纸的对应栏

[C++代码]

Triangle *tr = new Triangle();

Square *sq = new Square();

Shape *sh = tr;

[问题 1] 关于上述 C++代码中 sh 和 tr 的以下叙述中,哪两个是正确的(写出编号) 。

① sh 和 tr 分别引用同一个对象;

② sh 和 tr 分别引用同一类型的不同的对象;

③ sh 和 tr 分别引用不同类型的不同对象;

④ sh 和 tr 分别引用同一个对象的不同拷贝;

⑤ sh 和 tr 所引用的内存空间是相同的。

[问题 2] 写出下面消息对应的方法编号(如果该消息错误或者没有对应的方法调用,请

填写“无” ) 。

tr->height() (1)

sh->perimeter() (2)

sq->height() (3)

sq->perimeter() (4)

sh->height() (5)

tr->perimeter() (6)

[问题 3] 不考虑内存释放问题,下列赋值语句中哪两个是合法的(写出合法赋值语句的

编号) 。

① sq = sh; ② sh = tr; ③ tr = sq; ④ sq = tr; ⑤ sh = sq;

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

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