填空题【说明】
下面的程序中定义了两个方法求自然数1~100的和。具体如下:int suml(int n);利用循环求1~n的和,int sum2(int n);利用递归方法求和1~n的和;在main()方法中调用这两个方法求1~100的和并显示。在程序的每条横线处填写一个适当的语句,使程序的功能完整。
public class Sum {
public static void main{{U}} (1) {{/U}}
{
//1. 调用sum1(int n),求1~100的和
//标准输出
{{U}} (2) {{/U}}("1~100的和:" +sum1(100));
//2. 调用sum2(int n),求1~100的和
//标准输出
{{U}} (2) {{/U}}("1~100的和:"+sum2(100));
}
static iht sum1( int n)
{
int result=0;
for(int i=1;i<=n;i++)
{{U}} (3) {{/U}}
retrun result;
}
static int sum2(int n)
{
if{{U}} (4) {{/U}}
return 1
else
{{U}} (5) {{/U}}
}
}
填空题[说明] 下而程序实现十进制向其他进制的转换。 [C++程序] #include"ioStream.h" #include"math.h" #include <conio.h> typedef struct node int data; node *next; Node; class Transform public: 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) j (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;
填空题【说明】
以下程序实现了利用鼠标任意移动该圆形的位置,仔细阅读代码和相关注释,将程序补充完整。
【代码6】
import java.awt.*;
import java.awt.event.*;
public class CIUSAMPLE extends Frame implements MouseMotionListener, MouseListener
{
static CIUSAMPLE frm=new CIUSAMPLE ();
int x=70,y=60,posX=70,posY=60,dx,dy;
public static void main ( String args[])
{
frm.setTitle ("Dragging a circle");
frm.setSize ( 200,150 );
{{U}} (1) {{/U}}
frm.addMouseMotionListener ( frm );
frm. setVisible ( true );
}
public void mousePressed ( MouseEvent e )
{
{{U}} (2) {{/U}}
dy=e.getY () -posY;
}
public void mouseDragged ( MouseEvent e )
{
{{U}} (3) {{/U}}
y=e.getY () -dy;
if ( dx>0
{{U}} (4) {{/U}}
}
}
public void paint ( Graphics g )
{
g.setColor ( Color. pink ); // 设置绘图颜色为粉红
g.fillOval ( x,y,50,50 ); //以基准点为图形的左上角绘出圆形
{{U}} (5) {{/U}}
posY=y;
}
public void mouseMoved ( MouseEvent e ) { }
public void mouseReleased ( MouseEvent e ) { }
public void mouseEntered ( MouseEvent e ) { }
public void mouseExited ( MouseEvent e ) { }
public void mouseClicked ( MouseEvent e ) { }
}
填空题阅读以下函数说明和C语言函数,将应填入{{U}} (n) {{/U}}处的字句写在对应栏内。 [说明] 某银行共发出M张储蓄卡,每张储蓄卡拥有唯一的卡号,每天每张储蓄卡至多支持储蓄卡持有者的N笔“存款”或“取款”业务。程序中用数组card[M][N+3]中的每一行存放一张储蓄卡的有关信息,其中: card[i][0]存放第i张卡的卡号; card[i][1]存放第i张卡的余额; card[i][2]存放第i张卡的当日业务实际发生笔数; card[i][3]~card[i][N+2]存放第i张卡的当日存取款金额,正值代表存款,负值代表取款。 当持卡者输入正确的卡号、存款或取款金额后,程序进行相应的处理;若输入不正确的数据,程序会提示持卡者重新输入;若输入的卡号为负数时,银行终止该卡的当日业务。 [C程序] #include<stdio.H> #define M 6 #define N 5 long card[M][N+3]={{9801,2000,0,},{9812,2000,2,},{9753,3000,1,}, {8750,500,0,},{9604,2800,3,),(8901,5000,5,}}; int locate(long card[][N+3],int m,long no) { int i; for(i=0;i<m;i++) if( {{U}}(1) {{/U}}==no) return i; {{U}} (2) {{/U}}; } main() {long cardNo,money; int k; while(1){ printf("请输入卡号:/n"); scanf("%1d", if(cardNo<0) break; k=locate(card,M,cardNo); if(k==-1){ printf("不存在%id号的储蓄卡/n",cardNo); continue; } printf("请输入金额(正值代表存款,负值代表取款):/n"); scanf("%id", if(card[k][1]+money<0){ printf("存款余额不足,不能完成本次的取款业务/n"); continue; } if(card[k][2]==N){ printf("已完成本卡的当日业务/n"); continue; } /*处理一笔业务的数据*/ card[k]{{U}} (3) {{/U}}=money; {{U}} (4) {{/U}}; {{U}} (5) {{/U}}; } }
填空题阅读以下说明和C++程序,将应填入{{U}} (n) {{/U}}处的字句写在对应栏内。 [说明] 下面程序输出一个矩形面积,以及矩形区域上的假想的作物产量。 [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){{{U}} (1) {{/U}};} int get_ideal_crop(void){{{U}} (2) {{/U}};) }; Class lot_size { int length; int width; {{U}} (3) {{/U}} 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{{U}} (4) {{/U}};} int get_data2(void)freturn{{U}} (5) {{/U}};} } 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; }