2021年5月程序员模拟题下午(二)之七
作者:wx62e89cc5e381d2023-12-06 01:00:15
备考咨询 刷题指导
添加专属学姐
2024上半年软考备考资料+考试大纲
下载
摘要:对于【程序员】软考考试而言,试题无疑是最重要的学习资料之一。在软考备考过程中,吃透试题、掌握试题所考知识点、熟悉试题的出题思路,对我们提升分数的效果是最明显的,通过对试题的反复练习,还可以查漏补缺。今天,给大家带来【2021年5月程序员模拟题下午(二)】部分试题的详解,一起来看看吧~1、试题五(15分)阅读下列说明和C++代码,回答问题,将答案填入相应横线处。【说明】某
摘要:对于【程序员】软考考试而言,试题无疑是最重要的学习资料之一。在软考备考过程中,吃透试题、掌握试题所考知识点、熟悉试题的出题思路,对我们提升分数的效果是最明显的,通过对试题的反复练习,还可以查漏补缺。今天,给大家带来【2021年5月程序员模拟题下午(二)】部分试题的详解,一起来看看吧~
1、试题五(15分)阅读下列说明和C++代码,回答问题,将答案填入相应横线处。【说明】某实验室欲建立一个实验室环境监测系统,能够显示实验室的温度、湿度以及洁净度等环境数据。当获取到最新的环境测量数据时,显示的环境数据能够更新现在采用观察者(observer)模式来开发该系统,观察者模式的类图如下图所示。【C++代码】#include <iostream>#include <vector>using namespace std;class Observer {public: virtual void update(float temp, float humidity, float cleanness)=0;};class Subject {public: virtual void registerObserver(Observer* o) = 0; //注册对主题感兴趣的观察者 virtual void removeObserver(Observer* o) = 0; //删除观察者 (1) ;//当主题发生变化时通知观察者};class EnvironmentData : public Subject {private:vector<Observer*> observers;float temperature, humidity, cleanness;public: void registerObserver(Observer* o) { observers.push_back(o); } void removeObserver(Observer* o) { /* 代码省略 */ } void notifyObservers() {for(vector<Observer*>::const_iterator it = observers.begin(); it != observers.end(); it++){(*it)->update(temperature,humidity,cleanness); }}Void measurementsChanged() {notifyObservers(); }void setMeasurements(float temperature, float humidity, float cleanness) { (2)this->temperature = temperature; (3) this->humidity = humidity; (4) this->cleanness = cleanness; measurementsChanged(); }};class CurrentConditionsDisplay : public Observer() {private: float temperature, humidity, cleanness; Subject* envData;public: CurrentConditionsDisplay(Subject* envData) { this->envData = envData; (5) ; }void update(float temperature, float humidity, float cleanness) {this->temperature = temperature; this->humidity = humidity; this->cleanness = cleanness; display();}void display() { /* 代码省略 */ }};int main() { EnvironmentData* envData = new EnvironmentData(); CurrentConditionsDisplay* currentDisplay = new CurrentConditionsDisplay(envData); envData->setMeasurements(80, 65, 30.4f); return 0;}
答案:
答题解析:无
1、试题五(15分)阅读下列说明和C++代码,回答问题,将答案填入相应横线处。【说明】某实验室欲建立一个实验室环境监测系统,能够显示实验室的温度、湿度以及洁净度等环境数据。当获取到最新的环境测量数据时,显示的环境数据能够更新现在采用观察者(observer)模式来开发该系统,观察者模式的类图如下图所示。【C++代码】#include <iostream>#include <vector>using namespace std;class Observer {public: virtual void update(float temp, float humidity, float cleanness)=0;};class Subject {public: virtual void registerObserver(Observer* o) = 0; //注册对主题感兴趣的观察者 virtual void removeObserver(Observer* o) = 0; //删除观察者 (1) ;//当主题发生变化时通知观察者};class EnvironmentData : public Subject {private:vector<Observer*> observers;float temperature, humidity, cleanness;public: void registerObserver(Observer* o) { observers.push_back(o); } void removeObserver(Observer* o) { /* 代码省略 */ } void notifyObservers() {for(vector<Observer*>::const_iterator it = observers.begin(); it != observers.end(); it++){(*it)->update(temperature,humidity,cleanness); }}Void measurementsChanged() {notifyObservers(); }void setMeasurements(float temperature, float humidity, float cleanness) { (2)this->temperature = temperature; (3) this->humidity = humidity; (4) this->cleanness = cleanness; measurementsChanged(); }};class CurrentConditionsDisplay : public Observer() {private: float temperature, humidity, cleanness; Subject* envData;public: CurrentConditionsDisplay(Subject* envData) { this->envData = envData; (5) ; }void update(float temperature, float humidity, float cleanness) {this->temperature = temperature; this->humidity = humidity; this->cleanness = cleanness; display();}void display() { /* 代码省略 */ }};int main() { EnvironmentData* envData = new EnvironmentData(); CurrentConditionsDisplay* currentDisplay = new CurrentConditionsDisplay(envData); envData->setMeasurements(80, 65, 30.4f); return 0;}
答案:
(1)virtual void notifyObservers() = 0
(2)this->temperature = temperature
(3)this->humidity = humidity
(4)this->cleanness = cleanness
(5)this->envData->registerObserver(this)
答题解析:无
查看完整试题>>>
软考资料: 2024年软考论文范文> 软考考试核心重点难点汇总> 查看更多>
备考刷题:章节练习+每日一练> 软考历年试题+模拟题>查看更多>