网友您好, 请在下方输入框内输入要搜索的题目:

题目内容 (请给出正确答案)

阅读下列程序说明和C++代码,将应填入(n)处。

【程序6说明】

本程序实现两个多项式的乘积运算。多项式的每一项由类Item描述,而多项式由类List描述。类List的成员函数有:

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

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

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

【程序6】

include<iostream.h>

class List;

class |tem{

friend class List;

private:

double quot;

int exp;

|tem * next;

public:

|tem(double_quot,int_exp)

{ (1) ;}

};

class List {

private:

|tem * list;

public:

List(){list=NULL;}

void reverseList();

void multiplyList(List L1,List L2);

void createList();

};

void List::createList()

{ |tem * p,* u,*pre;

int exp;

doubte 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()

{ |tem*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)

{|tem*pLI,*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.list;

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 |tem(quot,k);

u->next=list;list=u;}

}

reverseList(:);L2.reverseList():

}

void main()

{ ListL1,L2,L;

cout<<"创建第一个多项式链表\n";L1.createList();

cout<<"创建第二个多项式链表\n";L2.createList();

L.multiplyList(L1,L2);

}


参考答案

更多 “ 阅读下列程序说明和C++代码,将应填入(n)处。【程序6说明】本程序实现两个多项式的乘积运算。多项式的每一项由类Item描述,而多项式由类List描述。类List的成员函数有:createList():创建按指数降序链接的多项式链表,以表示多项式。reverseList():将多项式链表的表元链接顺序颠倒。multiplyList(List L1,List L2):计算多项式L1和多项式L2的乘积多项式。【程序6】include<iostream.h>class List;class |tem{friend class List;private:double quot;int exp;|tem * next;public:|tem(double_quot,int_exp){ (1) ;}};class List {private:|tem * list;public:List(){list=NULL;}void reverseList();void multiplyList(List L1,List L2);void createList();};void List::createList(){ |tem * p,* u,*pre;int exp;doubte 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!=NULLexp==p->exp) {p->quot+=quot;continue;}u=(3);if(p==list) list=u;else pre->next=u;u->next=p;}}void List::reverseList(){ |tem*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){|tem*pLI,*pL2,*u;int k,maxExp;double quot;maxExp=(4);L2.reverseList();list=NULL;for(k=maxExp;k>=0;k--){pL1=L1.list;while(pL1!=NULLpL1->exp>k)pL1=pL1->next;pL2=L2.list;while(pL2!=NULL(5) pL2=pL2->next;quot=0.0;while(pL1!=NULLpL2!=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 |tem(quot,k);u->next=list;list=u;}}reverseList(:);L2.reverseList():}void main(){ ListL1,L2,L;cout<<"创建第一个多项式链表\n";L1.createList();cout<<"创建第二个多项式链表\n";L2.createList();L.multiplyList(L1,L2);} ” 相关考题
考题 ●试题六阅读下列程序说明和C++代码,将应填入(n)处的字句写在答卷的对应栏内。【程序6说明】本程序实现两个多项式的乘积运算。多项式的每一项由类Item描述,而多项式由类List描述。类List的成员函数有:createList():创建按指数降序链接的多项式链表,以表示多项式。reverseList():将多项式链表的表元链接顺序颠倒。multiplyList(List L1,List L2):计算多项式L1和多项式L2的乘积多项式。【程序6】#includeiostream.hclass List;class ltem{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;cinquotexp:if(exp0)break;//指数小于零,结束输入if(quot==0)continue;p=list;while( (2) ){//查找插入点pre=p;p=p-next;}if(p!=NULLexp==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*pLl,*pL2,*u;int k,maxExp;double quot;maxExp= (4) ;L2.reverseList();list=NULL;for(k=maxExp;k=0;k--){pL1=L1.list;while(pL1!=NULLpL1-expk)pL1=pL1-next;pL2=L2.list;while(pL2!=NULL (5) pL2=pL2-next;quot=0.0;while(pL1!=NULLpL2!=NULL){if(pL1-exp+pL2-exp==k){(6) ;pL1=pL1-next;pL2=pL2-next;}else if(pL1-exp+pL2-expk)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(){ListL1,L2,L;cout"创建第一个多项式链表\n";L1.createList();cout"创建第二个多项式链表\n";L2.createList();L.multiplyList(L1,L2);}

考题 阅读以下说明和C++程序,将应填入(n)处的字句写在对应栏内。【C++程序】include include 阅读以下说明和C++程序,将应填入(n)处的字句写在对应栏内。【C++程序】include < stdio. h >include < string. h >define Max 1000class Bank{int index;char date [Max] [10]; // 记录交易日iht amount[Max]; // 记录每次交易金额,以符号区分存钱和取钱int rest[ Max]; // 记录每次交易后余额static iht sum; // 账户累计余额public:Bank( ) {index =0;}void deposit( char d[ ] , int m) //存入交易{strcpy ( date [ index ], d);amount[ index] = m;(1);rest[ index] = sum;index++;}void withdraw (char d[ ], int m) //取出交易{strcpy( date[ index] ,d);(2);(3);rest[ index] = sum;index++;}void display( );};int Bank:: sum = 0;void Bank:: display ( ) //输出流水{int i;printf("日期 存入 取出 余额\n");for (4){printf(" %8s" ,date[i] );if (5)printf(" %6d" , -amount[i] );elseprintf( "%6d ",amount[i] );printf( "% 6d\n" ,rest[i] );} }void main( ){Bank object;object. deposit ( "2006.2.5", 1 00 );object. deposit( "2006.3.2" , 200);object. withdraw( "2006.4.1", 50);object. withdraw( "2006.4.5", 80);object. display ( );}本程序的执行结果如下:日期 存入 取出 余额 2006.2.5 100 1002006.3.2 200 3002006.4.1 50 2502006.4.5 80 170

考题 阅读以下说明及Visual Basic程序代码,将应填入(n)处的字句写在对应栏内。【说明】以下程序为求行列式X(5,5)的值S。【Visual Basic代码】Private Function col ( byval x ( 5,5 ) as integer ) as longdim fesult as longdim temp as longdim I as integerdim j as integerdim k as imegerresult = 0for I = to 5(1)for j = 1 to 5if I+j>6 thenk= ( 1+j ) mod 5elsek=1endiftemp=temp*x ( k,j )(2)result=(3)(4)(5)End function

考题 阅读以下说明和程序流程图,将应填入(n)处的字句写在对应栏内。[说明]当一元多项式中有许多系数为零时,可用一个单链表来存储,每个节点存储一个非零项的指受和对应系数。为了便于进行运算,用带头节点的单链表存储,头节点中存储多项式中的非零项数,且各节点按指数递减顺序存储。例如:多项式8x5-2x2+7的存储结构为:流程图图3-1用于将pC(Node结构体指针)节点按指数降序插入到多项式C(多项式POLY指针)中。流程图中使用的符号说明如下:(1)数据结构定义如下:define EPSI 1e-6struct Node{ /*多项式中的一项*/double c; /*系数*/int e; /*指数*/Struct Node *next;};typedef struct{ /*多项式头节点*/int n; /*多项式不为零的项数*/struct Node *head;}POLY;(2)Del(POLY *C,struct Node *p)函数,若p是空指针则删除头节点,否则删除p节点的后继。(3)fabs(double c)函数返回实数C的绝对值。[图3-1](1)

考题 阅读下列程序说明和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…}

考题 ●试题二阅读下列函数说明和C代码,将应填入(n)处的字句写在答题纸的对应栏内。【说明】该程序运行后,输出下面的数字金字塔【程序】includestdio.hmain (){char max,next;int i;for(max=′1′;max=′9′;max++){for(i=1;i=20- (1) ;++i)printf(" ");for(next= (2) ;next= (3) ;next++)printf("%c",next);for(next= (4) ;next= (5) ;next--)printf("%c",next);printf("\n");}}

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

考题 阅读下列说明和C++-代码,将应填入(n)处的字句写在答题纸的对应栏内。 【说明】 某发票(lnvoice)由抬头(Head)部分、正文部分和脚注(Foot)部分构成。现采用装饰(Decorator)模式实现打印发票的功能,得到如图5-1所示的类图。 【C++代码】 #include using namespace std; class invoice{ public: (1){ cout

考题 阅读下列说明和?C++代码,将应填入(n)处的字句写在答题纸的对应栏内。 【说明】 阅读下列说明和?Java代码,将应填入?(n)?处的字句写在答题纸的对应栏内。 【说明】 某快餐厅主要制作并出售儿童套餐,一般包括主餐(各类比萨)、饮料和玩具,其餐品种 类可能不同,但其制作过程相同。前台服务员?(Waiter)?调度厨师制作套餐。现采用生成器?(Builder)?模式实现制作过程,得到如图?6-1?所示的类图。