搜题
网友您好,请在下方输入框内输入要搜索的题目:
搜题
题目内容 (请给出正确答案)
提问人:网友guocomputer 发布时间:2022-01-06
[主观题]

阅读下列C++程序和程序说明,将应填入(n)处的字句写在对应栏内。 【说明】设单链表的结点类和链表类

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

【说明】设单链表的结点类和链表类的定义如下,链表不带有表头结点。请填空:

include<iostream.h>

include<assert.h>

template<class T>class List;

template<class T>class ListNOde{

friend (1);

private:

T data;

ListNode<T> *link;

public:

ListNode():link(NULL)()

ListNOde(const T& item,ListNOde<T>*next=NULL)

:data(item),link(next){}

};

template<class T>class List{

private:

ListNode<T>*first;

void createList(T A[],int n,int i,ListNOde<T>*&p);

void printList(ListNOde<T>*p);

public:

List();

~List();

friend ostream& operator<<(ostream& ost,List<T>&L);

friend istream& operator>>(istream& ist,List<T>&L);

};

template<class T>

istream& operator>>(istream& ist,List<T>&1){

int i,n; ist>>n;

T A[n];

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

createList(A,n,0,first);

}

template<class T>

void List<T>::createList(TA[],int n,int i,ListNOde<T>*& p){

//私有函数:递归调用建立单链表

if(i==n)p=NULL;

else{

p=new ListNode<T>(A[i]);

assert(p !=NULL);

createList((3));

}

}

template<class T>

ostream& operator<<(ostream& ost,List<T>& L){

(4);

}

template<class T>

void List<T>::printList(ostream& ost,ListNode<T>*p){

if(p!=NULL){

ost<<p->data;

(5);

}

}

简答题官方参考答案 (由简答题聘请的专业题库老师提供的解答)
查看官方参考答案
更多“阅读下列C++程序和程序说明,将应填入(n)处的字句写在对应栏内。 【说明】设单链表的结点类和链表类”相关的问题
第1题
阅读下列程序说明和C++程序,把应填入其中(n)处的字句,写在对应栏内。【说明】阅读下面几段C++程序回

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

【说明】

阅读下面几段C++程序回答相应问题。

比较下面两段程序的优缺点。

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

{

if (condition)

//DoSomething

else

//DoOtherthing

}

②if (condition) {

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

//DoSomething

}else {

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

//DoOtherthing

}

点击查看答案
第2题
阅读以下说明和C++代码,将应填入____处的语句或语句成分写在答题纸的对应栏内。

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

阅读以下说明和C++代码,将应填入____处的语句或语句成分写在答题纸的对应栏内。	某数据文件stu

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

}

}

点击查看答案
第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)处的字句写在答题纸的对应栏内。

【说明】

设计一个类模板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;

}

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

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

[说明]

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

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

[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->ib;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)->getarea()<<endl;

}

}

};

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

}

}

点击查看答案
第9题
●试题六 阅读下列程序说明和C++代码,将应填入(n)处的字句写在答卷的对应栏内。 【说明】 ①为类Ci

●试题六

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

【说明】

①为类Circle增加一个构造函数,该函数有一个参数,并在构造时将该参数值赋给成员radius。将该函数实现为一个非内联函数,并且使用参数列表的方式将类成员赋值。

②为类Circle增加一个成员函数print(),使得可以输出有关圆的信息,比如下列程序

Circle c;

C.SetRadius (5) ;

C.Print();

将输出:The circle has radius of 5!

③完成友元函数void CompareR(Circle *c1,Circle *c2)的定义,在屏幕中输出c1与c2比较radius大小结果,要求使用if-else结构完成。

输出结果如下:

The circle has radus of 5!

The circle has radius of 10!

c1<c2

源程序文件test7_3.cpp清单如下:

#include<iostream.h>

class Circle{

public:

Circle():radius (5) {}

(1)

void SetRadius(int r) { radius=r; }

int GetRadius() { return radius; }

(2)

friend void CompareR(Circle *c1,Circle *c2);

private:

int radius;

};

void CompareR(Circle *c1,Circle *c2)

{

(3)

cout<<"c1>c2"<<endl;

else

if ((c1->GetRadius())==(c2->GetRadius()))

cout<<"c1=c2"<<endl;

else

if ((c1->GetRadius())<(c2->GetRadius()))

cout<<"c1<c2"<<endl;

}

void main()

{

Circle c1;

c1.SetRadius (5) ;

c1.Print();

Circle c2 (10) ;

c2.Print();

CompareR(&c1,&c2);

}

点击查看答案
重要提示: 请勿将账号共享给其他人使用,违者账号将被封禁!
查看《购买须知》>>>
重置密码
账号:
旧密码:
新密码:
确认密码:
确认修改
购买搜题卡查看答案
购买前请仔细阅读《购买须知》
请选择支付方式
微信支付
支付宝支付
点击支付即表示你同意并接受《服务协议》《购买须知》
立即支付
搜题卡使用说明

1. 搜题次数扣减规则:

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

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

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

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

请使用微信扫码支付(元)

订单号:

遇到问题请联系在线客服

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

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

- 微信扫码关注简答题 -
警告:系统检测到您的账号存在安全风险
抱歉,您的账号因涉嫌违反简答题购买须知被冻结。您可在“简答题”微信公众号中的“官网服务”-“账号解封申请”申请解封,或联系客服
- 微信扫码关注简答题 -
请用微信扫码测试
欢迎分享答案

为鼓励登录用户提交答案,简答题每个月将会抽取一批参与作答的用户给予奖励,具体奖励活动请关注官方微信公众号:简答题

简答题官方微信公众号

简答题
下载APP
关注公众号
TOP