题目内容 (请给出正确答案)
[主观题]

阅读以下应用说明、图和C++程序,将C++程序中(1)~(6)空缺处的语句填写完整。【说明】 以下【C++程序】用

阅读以下应用说明、图和C++程序,将C++程序中(1)~(6)空缺处的语句填写完整。

【说明】

以下【C++程序】用于实现两个多项式的乘积运算。多项式的每一项由类Item描述,而多项式由类List描述。类List的成员函数主要有:

createList():创建按指数降序链接的多项式链表,以表示多项式:

reverseList():将多项式链表的表元链接顺序颠倒:

multiplyList(ListL1,ListL2)计算多项式L1和多项式L2的乘积多项式。

【C++程序】

include <iostream.h>

class List;

class Item {

friend class List;

private:

double quot ;

int exp ;

Item *next;

Public:

Item(double_quot,int_exp)

{ (1) ;}

};

class List{

private:

Item *list;

Public:

List(){

list=NULL:

}

void reverseList();

void multiplyList(List L1,List L2);

void createList();

};

void List::createList()

{ Item *p,*U,*pre;

int exp;

double quot;

list = NULL;

while (1) {

cout << "输入多项式中的一项(系数、指数) :" << endl;

cin >> quot >> exp:

if (exp<0 )

break ; //指数小于零,结束输入

if (quot=0 )

continue;

p = list;

while ((2) ) { //查找插入点

pre = p;

p = p->next;

}

if (p != NULL && exp = p->exp ) {

p->quot += quot;

continue ;

}

u =(3);

if (p == list)

list = u;

else

pre->next = u;

u ->next = p;

}

}

void List::reverseList()

{ Item *p, *u;

if (list==NULL )

return;

p = list ->next;

list -> next = NULL;

while (p != NULL) {

u = p -> next;

p ->next = list;

list = p;

p = u;

}

}

void List::multiplyList (List L1, List L2 )

{ Item *pL1,*pL2,*u;

int k, maxExp;

double quot;

maxExp =(4):

L2.reverseList();

list=NULL;

for (k = maxExp;k >= 0;k-- ){

pL1 = L1.list;

while (pL1 != NULL && pL1 -> exp > k )

pL1 = pL1 ->next;

pL2 = L2.1ist;

while (pL2 NULL &&(5))

pL2 = pL2 -> next;

quot = 0.0;

while (pL1 != NULL && pL2 != NULL){

if(pL1->exp+pL2->exp==k) {

(6)

pL1 = pL1 -> next;

pL2 = pL2 -> next;

} else if (pL1 -> exp + pL2 -> exp > k )

pL1 = pL1 -> next;

else

pL2 = pL2 -> next;

}

if (quot !=0.0 ) {

u = new item(quot, k );

u -> next = list;

list = u;

}

}

reverseList ();

L2. reverseList ():

}

void main()

{ List L1,L2,L;

提问人:网友chenhaihui 发布时间:2022-01-06
参考答案
查看官方参考答案
如搜索结果不匹配,请 联系老师 获取答案
更多“阅读以下应用说明、图和C++程序,将C++程序中(1)~(6…”相关的问题
第1题
阅读以下应用说明、图和C++代码,根据要求回答问题1至问题3。 [说明] 已知以下C++程序运行时的输出

阅读以下应用说明、图和C++代码,根据要求回答问题1至问题3。

[说明]

已知以下C++程序运行时的输出结果如下。

1:1

1:1

1:1

[C++程序]

01 include <iostream>

02 using namespace std;

03 class Stock{

04 protect:

05 (1) { };

06 Stock(int n, int pr=1) {

07 shares = n; share_val=pr;

08 };

09 void ~Stock() { };

10 public:

11 //成员函数

12 void output() {

13 (2)<< shares << ":" << share_val << endl;

14 }

15 private:

16 //成员变量

17 int shares;

18 int share_val;

19 };

20

21 void main() {

22 Stock a(1); a.output

23 Stock b; b.output

24 Stock c = Stock (); c.output

25 }

请根据C++程序运行时的输出结果,将代码中(1)、(2)空缺处的内容补充完整。

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

【说明】

下面程序的功能是计算并输出某年某月的天数,函数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) ();

}

点击查看答案
第5题
阅读以下说明和C++程序,将应填(n)处的字句写在对应栏内。[说明] 设计一程序,输入10个整数到一个数

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

[说明]

设计一程序,输入10个整数到一个数组中,调整这10个数在数组中的位置,使得其中最小的一个数成为数组的首元素,最大的一个数成为数组的末元素。

[C++程序]

include <iostream.h>

define SIZE 10

void main ()

{

int data [SIZE];

int m;

cout<<"请输入"<<SIZE<<"个整数:";

for (m=0;m<SIZE; m++ ) (1);

int j=0,k=0;

for (int i=1;i<SIZE; i++ )

if ((2)) j=i;

else if (data[i]<data[k] ) (3);

if (j>0 ) {

int d=data[0];

(4);

data[k]=d;

}

if (k<SIZE-1 )

{

int d=data [SIZE- 1 ];

data[SIZE- 1 ]=data[j];

(5);

}

cout<<end1<<" 排序后: ";

for (m=0;m<SIZE; m++ ) cout<<data[m]<<" " ;

}

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

}

}

};

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

}

}

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

}

点击查看答案
账号:
你好,尊敬的用户
复制账号
发送账号至手机
密码将被重置
获取验证码
发送
温馨提示
该问题答案仅针对搜题卡用户开放,请点击购买搜题卡。
马上购买搜题卡
我已购买搜题卡, 登录账号 继续查看答案
重置密码
确认修改
欢迎分享答案

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

简答题官方微信公众号

警告:系统检测到您的账号存在安全风险

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

微信搜一搜
简答题
点击打开微信
警告:系统检测到您的账号存在安全风险
抱歉,您的账号因涉嫌违反简答题购买须知被冻结。您可在“简答题”微信公众号中的“官网服务”-“账号解封申请”申请解封,或联系客服
微信搜一搜
简答题
点击打开微信