题目详情
当前位置:首页 > 计算机考试 > 中级软件设计师
题目详情:
发布时间:2024-05-17 01:23:24

[简答题]【程序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+=quo

更多"【程序6说明】 本程序实现两个多项式的乘积运算。多项式的每一项由类I"的相关试题:

[简答题]【程序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
[多项选择]【说明】
以下【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) ) //查找插入点

[简答题]【程序说明】 该程序定义了两个子函数strsort和strmerge。它们分别实现了将一个字符串按字母顺序排序和将两个字符串合并排序,并删去相同字符。在主函数里,先输入两个字符串s1和s2,然后调用strsort函数对它们分别排序,然后调用strmerge函数将s1和s2合并,将合并后的字符串赋给字符串s3,最后输出字符串s3。 【程序】 #include<stdio.h> void strmerge(char,a,char *b,char *c) //将字符串a,b合并到字符串c中 { char t,*w; w=c; while( (1) ) {//找到字符串a,b当前字符中较小的字符 if(*a< *b) { t= *a; (2) ; { else if (*a>*b) { t= *b; (3) ; } else //字符串a,b当前字符相等 { t= *a; a++; b++; } if( (4) ) //开始,可直接赋值 *w=t; else if(t!=*w) //如果a,b中较小的当前字符与c中当前字符不相等,才赋值 (5) ; } if(*a!=/’/0’) //如果字符串a还没有结束,则将a的剩余部分赋给C while(*a!=’/0’) if(*a!=*w) { *(++w)=*a; a++; } else (6) ; if(*6!=’/0’) //如果字符串b还没有结束,则将b的剩余部分赋给c while(*b!=’/0’) if(*b! = *w) { *(++w)=*b; b++; } else b++; (7) ; } void strsort(char*s) //将字符串S中的字符
[简答题]【程序说明】
该程序定义了两个子函数strsort和strmerge。它们分别实现了将一个字符串按字母顺序排序和将两个字符串合并排序,并删去相同字符。在主函数里,先输入两个字符串s1和s2,然后调用strsort函数对它们分别排序,然后调用strmerge函数将s1和s2合并,将合并后的字符串赋给字符串s3,最后输出字符串s3。
【程序】
#include<stdio.h>
void strmerge(char,a,char *b,char *c) //将字符串a,b合并到字符串c中

char t,*w;
w=c;
while( (1) )
//找到字符串a,b当前字符中较小的字符
if(*a< *b)

t= *a;
(2)

else if (*a>*b)

t= *b;
(3)

else //字符串a,b当前字符相等

t= *a;
a++;
b++;

if( (4) ) //开始,可直接赋值
*w=t;
else if(t!=*w)
//如果a,b中较小的当前字符与c中当前字符不相等,才赋值 (5)

if(*a!=/’/0’) //如果字符串a还没有结束,则将a的剩余部分赋给C
while(*a!=’/0’)
if(*a!=*w)

*(++w)=*a;
a++;

else
(6)
if(*6!=’/0’) //如果字符串b还没有结束,则将b的剩余部分赋给c
while(*b!=’/0’)
if(*b! = *w)
[简答题]【说明】本程序ExceptionTester实现功能:读入两个整数,第1个数除以第2个数,之后输出。若第2个数为0,则自动进行异常处理。
程序如下:
(1)
public class ExceptionTester
public static void main(String args[])
int result;
int number[]=new int[2];
boolean valid; for(int i=0;i<2;i++)
valid= (2)
while(!valid)
try
System.out.println("Enter number"+(i+1));
number[i]=Integer.valueOf(Keyboard.getString( )).intValue( );
valid=true;
catch(NumberFormatExceptione)
System.out.println("Invalid integer entered.Please try again.");


by
result=number[0]/number[1];
System.out.print(number[0]+"/"+number[1]+"="+result);
catch( (3) )
System.out.println("Second number is 0,cannot do division!");



其中,Keyboard类的声明为:
impon java.io.*;
public class Keyboard
static BufferedReader inputStream=new (4)
(new Inp
[简答题]【说明】
本程序的功能是实现任意两个大整数的乘法运算,例如:
输入整数1:8934793850094505800243958034985058
输入整数2:234584950989689084095803583095820923
二者之积:
209596817742739508050978890737675662366433464256830959194834854876 8534
【C++代码】
#include<iostream.h>
const int MAXINPUTBIT=100;
const int MAXRESULTBIT=500;
class LargeNumber
int i,j;
int temp;
int one[MAXINPUTBIT+1];
int onebit; //one的位数
int two[MAXINPUTBIT+1];
int twobit; //two的位数
int result[MAXRESULTBIT+1];
public:
LargeNumber( );
~LargeNumber( );
int inputone( ); //出错返叫0,否则返回1
int inputtwo( ); //同上
void multiplication( ); //乘
void clearresult( ); //清零
void showresult( ); //显示
;
LargeNumber∷LargeNumber( )

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

one[i]=0;
two[i]=0;

onebit=0;
twobit=0;
inputone( );
inputtwo( );

La
[简答题]【说明】 本程序的功能是实现任意两个大整数的乘法运算,例如: 输入整数1:8934793850094505800243958034985058 输入整数2:234584950989689084095803583095820923 二者之积: 209596817742739508050978890737675662366433464256830959194834854876 8534 【C++代码】 #include<iostream.h> const int MAXINPUTBIT=100; const int MAXRESULTBIT=500; class LargeNumber{ int i,j; int temp; int one[MAXINPUTBIT+1]; int onebit; //one的位数 int two[MAXINPUTBIT+1]; int twobit; //two的位数 int result[MAXRESULTBIT+1]; public: LargeNumber( ); ~LargeNumber( ); int inputone( ); //出错返叫0,否则返回1 int inputtwo( ); //同上 void multiplication( ); //乘 void clearresult( ); //清零 void showresult( ); //显示 }; LargeNumber∷LargeNumber( ) { for(i=0;i<=MAXINPUTBIT;i++) { one[i]=0; two[i]=0; } onebit=0; twobit=0; inputone( ); inputtwo( ); } LargeNumber∷~LargeNumber( ) { } int LargeNumber∷inputone( ) { char Number[MAXINPUTBIT+1]; cout<<"
[简答题]【说明】本程序实现功能:读入两个整数,第1个数除以第2个数,声明当除数为零时抛出异常类DivideByZeroException。
public class DivideByZeroException (1)
public DivideByZeroException ( )
super("Attcmpted to divide by zero");


import java.io. *;
public class Example
private static int quotient(int numerator, in)/”t denominator) throws
DivideByZeroException
if (denominator==0)
throw (2) ;
return(numerator / denominator);

public static void main(String args[])
int number1=0, number2=0, result0;
try
System.out.print1n("Enter the first number:");
number1 = Integer. valueOf(Keyboard.getString( )).intValue( );
System.out.print1n("Enter the second number:");
number2 = Integer. Va1ueOf(Keyboard.getString( )).intValue( );
result = quotient(number1,number2);

catch (NumberFormatException e)
System.out.print1n("Invalid integer entered!");
Syst
[简答题]
阅读下列程序说明和C++程序,把应填入其中(n)处的字句,写对应栏内。
【说明】
下面的程序实现了类String的构造函数、析构函数和赋值函数。
已知类String的原型为:
class String
{
public:
String(coust char * str = NULL); //普通构造函数
String( const String &other); //拷贝构造函数
~String(void); //析构函数
String & operate =(const String &other); //赋值函数
private:
char * m_data; // 用于保存字符串
};
//String 的析构函数
String:: ~String (void)
{
(1) ;
}
//String 的普通构造函数
String: :String( const char * str)
{
if (2)
{
m_data = new char[1];
*m_data = ’/0’;
}
else
{
int length = strlen(str);
m_data = new ehar[ length + 1 ];
strepy(m_data, str);
}
}
//拷贝的构造函数
String:: String( const String &other)
{ int length = strlen(other. m_data);
m_data = new char[ length + 1 ];
strepy(m_data, other, m_data); //赋值函数
String & String::operate = (eonst Stri
[填空题]阅读以下函数说明和Java代码,
[说明]
现要编写一个画矩形的程序,目前有两个画图程序:DP1和DP2,DP1用函数draw_a_line(x1,y1,x2,y2)画一条直线,DP2则用drawline(x1,x2,y1,y2)画一条直线。当实例化矩形时,确定使用DPI还是DP2。
为了适应变化,包括“不同类型的形状”和“不同类型的画图程序”,将抽象部分与实现部分分离,使它们可以独立地变化。这里,“抽象部分”对应“形状”,“实现部分”对应“画图”,与一般的接口(抽象方法)与具体实现不同。这种应用称为Bridge(桥接)模式。图7-1显示了各个类间的关系。
[图7-1]
[*]
这样,系统始终只处理3个对象:Shape对象、Drawing对象、DP1或DP2对象。以下是JAvA语言实现,能够正确编译通过。
[Java代码]
//DP1.Java文件
public class DPI
static public void draw_a_line(double x1,double y1,
double x2,double y2)
//省略具体实现


//DP2.java文件
public class DP2
static public void drawline(double x1,double y1,
double x2,double y2)
//省略具体实现


//Drawing.java文件
(1) public class Drawing
abstract public void drawLine(double x1,double y1,double x2,double y2);

//V1Drawing.java文件
public class V1Drawing extends Drawing
public void drawLine(double x1,double y1,double x2,double y2) <

我来回答:

购买搜题卡查看答案
[会员特权] 开通VIP, 查看 全部题目答案
[会员特权] 享免全部广告特权
推荐91天
¥36.8
¥80元
31天
¥20.8
¥40元
365天
¥88.8
¥188元
请选择支付方式
  • 微信支付
  • 支付宝支付
点击支付即表示同意并接受了《购买须知》
立即支付 系统将自动为您注册账号
请使用微信扫码支付

订单号:

请不要关闭本页面,支付完成后请点击【支付完成】按钮
恭喜您,购买搜题卡成功
重要提示:请拍照或截图保存账号密码!
我要搜题网官网:https://www.woyaosouti.com
我已记住账号密码