重要提示: 请勿将账号共享给其他人使用,违者账号将被封禁!
查看《购买须知》>>>
当前位置: 首页 > 计算机类考试 > 软考初级
网友您好, 请在下方输入框内输入要搜索的题目:
搜题

题目

[主观题]

阅读以下说明和C++程序,将应填入(n)处的字句写在对应栏内。 【说明】 设计一个评选优秀教师和学生的

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

【说明】

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

阅读以下说明和C++程序,将应填入(n)处的字句写在对应栏内。 【说明】 设计一个评选优秀教师和学生

【程序】

include<iostream.h>

include<stdio.h>

enum boolean {False,True}

class base

{

protected:

char name[8];

public:

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

void printname() {cout<<"姓名:"<<name<<endU3

virtual boolean isgood() =0;

}

class student:(1)

{

int num;

public:

void getnum()

cout<<"考试成绩:" cin>>num;

boolean isgood() {return (2);{

};

class teacher:(3) public base

int num;

public:

void getnum()

cout<<"每年发表论文数:" ;cin>>num;

boolean isgood() {return (4);}

};

void main()

base* p[50];

student * pstud;

teacher * ptech;

char ch;

int count =0;

do

cout<<"输入教师(t)或学生(s):"

cin>>ch;

if(ch =='s')

{

pstud = new student;

pstud ->getname();

pstud ->getnum();

p[count ++ ] = pstud;

}

else if(ch == 't')

{

ptech = newteacher;

ptech - >getname()

ptech ->getnum();

p[count++]=ptech;

}

else

cout<<"输入错误<<endl;

cout<<"继续输入码(Y/n)";

cin>>ch;

} while(ch == 'y')

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

{

if((5)) //若为优秀,则输出

p[i]->printname();

}

}

查看参考答案
更多“阅读以下说明和C++程序,将应填入(n)处的字句写在对应栏内。 【说明】 设计一个评选优秀教师和学生的”相关的问题

第1题

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

}

}

点击查看答案

第2题

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

}

}

点击查看答案

第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)处的字句写在对应栏内。

[说明]

下面程序输出一个矩形面积,以及矩形区域上的假想的作物产量。

[C++程序]

include <iostream.h>

class crop_assessment

{

int actual_crop;

int ideal_crop;

public:

void set(int in_actual,int in_ideal)

{

actual crop=in_actual;

ideal_crop=in_ideal;

}

int get_actual_crop(void){ (1) ;}

int get_ideal_crop(void){ (2) ;)

};

Class lot_size

{

int length;

int width;

(3) crop;

public:

void set(int 1,int w,int a,int i)

{

length=1;

width=w;

crop.set(a,i);

}

int get_area(void){return length*width;}

int get_data(void){return (4) ;}

int get_data2(void)freturn (5) ;}

}

int main()

{

Los_size small,medium;

small.set(5,5,5,25);

medium.set(10,10,10,50);

cout<<"For a small lot of area"<<smallget_area()<<“\n”;

cout<<"the actual crops are$"<<small.get_data2()<<"\n";

cout<<"and ideal crops are$”<<small.get_data()<<"\n";

cout<<"For a medium Lot of area"<<medium.get area()<<:\n”;

cout<<"the actual crops are$"<<medium.get_data2()<<"\n";

cout<<"and ideal crops are$"<<medium.get_data()<<"\n";

return 0;

}

点击查看答案

第5题

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

}

点击查看答案

第6题

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

}

点击查看答案

第7题

●试题六 阅读以下说明和C++程序,将应填入(n)处的字句写在答题纸的对应栏内。 【说明】 设计一个

●试题六

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

【说明】

设计一个类模板Sample用于对一个有序数组采用二分法查找元素下标。

【C++程序】

#include<iostream.h>

#define Max 100∥最多元素个数

template<class T>

class Sample

{

T A[Max]:∥存放有序数序

int n:∥实际元素个数

public

Sample(){}∥默认构造函数

Sample(T a[],int i);∥初始化构造函数

int seek(T c);

void disp()

{

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

cout<<A[i]<<"";

cout<<end1:

}

};

template<class T>

Sample<T>::Sample(T a[],int i)

{

n=i;

for(intj=0;j<i;j++)

(1) ;

}

template<class T>

int Sample<T>::seek(T c)

{

int low=0,high=n-1,mid;

while((2) )

{

mid=(low+high)/2;

if((3) )

return mid;

else if((4) )

low=mid+l;

else

(5) ;

}

return-1;

}

void main()

{

char a[]="acegkmpwxz";

Sample<char>s(a,1。);

cout<<"元素序列:";s.disp();

cout<<"元素′g′的下标:"<<s.seek(′g′)<<endl;

}

点击查看答案

第8题

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

点击查看答案

第9题

阅读下列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;

}

}

点击查看答案

第10题

阅读以下说明和C++程序,将应填入(n)处的字句写在对应栏内。【说明】 设计一个类模板SamPle用于对一

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

【说明】

设计一个类模板SamPle用于对一个有序数组采用二分法查找元素下标。

【C++程序】

include < iostream. h >

define Max 100 //最多元素个数

template < class T >

class Sample

{

T A[Max]: //存放有序数序

int n: //实际元素个数

public

Sample() { } //默认构造函数

Sample(T a[] ,int i); //初始化构造函数

int seek(T c);

void disp()

{

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

cout<<A[i] <<" ";

cout<<endl:

} } template < class T >

Sample <T>: :Sample(T a[ ],int i)

{

n=i:

for(intj =0;j < i;j ++ )

(1);

}

template < class T >

int Sample < T >:: seek(T c)

{

int low =0,high = n-1 ,mid;

while((2))

{

mid = (low + high)/2;

if((3))

return mid;

else if((4) )

low=mid+|;

else

(5);

}

return-1;

}

void main()

{

char a[ ] ="acegkmpwxz";

Sample < char > s(a, 1);

cout<<"元素序列:" ;s. disp();

cout<<"元素'g'的下标:"<<s. seek('g') <<endl;

}

点击查看答案

第11题

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

}

}

点击查看答案
赏学吧APP
TOP
重置密码
账号:
旧密码:
新密码:
确认密码:
确认修改
购买搜题卡查看答案
购买前请仔细阅读《购买须知》
请选择支付方式
微信支付
支付宝支付
点击支付即表示你同意并接受《服务协议》《购买须知》
立即支付
搜题卡使用说明

1. 搜题次数扣减规则:

功能 扣减规则
基础费
(查看答案)
加收费
(AI功能)
文字搜题、查看答案 1/每题 0/每次
语音搜题、查看答案 1/每题 2/每次
单题拍照识别、查看答案 1/每题 2/每次
整页拍照识别、查看答案 1/每题 5/每次

备注:网站、APP、小程序均支持文字搜题、查看答案;语音搜题、单题拍照识别、整页拍照识别仅APP、小程序支持。

2. 使用语音搜索、拍照搜索等AI功能需安装APP(或打开微信小程序)。

3. 搜题卡过期将作废,不支持退款,请在有效期内使用完毕。

请使用微信扫码支付(元)
订单号:
遇到问题请联系在线客服
请不要关闭本页面,支付完成后请点击【支付完成】按钮
遇到问题请联系在线客服
恭喜您,购买搜题卡成功 系统为您生成的账号密码如下:
重要提示: 请勿将账号共享给其他人使用,违者账号将被封禁。
发送账号到微信 保存账号查看答案
怕账号密码记不住?建议关注微信公众号绑定微信,开通微信扫码登录功能
警告:系统检测到您的账号存在安全风险

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

- 微信扫码关注赏学吧 -
警告:系统检测到您的账号存在安全风险
抱歉,您的账号因涉嫌违反赏学吧购买须知被冻结。您可在“赏学吧”微信公众号中的“官网服务”-“账号解封申请”申请解封,或联系客服
- 微信扫码关注赏学吧 -
请用微信扫码测试
温馨提示
每个试题只能免费做一次,如需多次做题,请购买搜题卡
立即购买
稍后再说
赏学吧