更多"下列过程的功能是:用来计算并输出S=1+1/2+1/3+…+1/100"的相关试题:
[填空题]下列过程的功能是:用来计算并输出S = 1+1/2+1/3+…+1/100的值。请完善程序。
Function SumF(n As Integer)As Single
s = 0
For i = 1 To n
s = ______
Next i
SumF = s
End Function
Private Sub Form_Click( )
Sum1 = SumF(100)
Print
Print "sum1 = "; sum1
End Sub
[填空题]下列过程的功能是:用来计算并输出S=1+1/2+1/3+…+1/100的值,请完善下列程序。
Furiction SumD (n As Integer)As Single
s = 1
i = 1
Do
i = i + 1
s = s + 1 / i
Loop Until 【12】
SumD = s
End Function
Private Sub Form Click( )
sum1=SumD(100)
Print "sum1="; sum1
End Sub
[填空题]下列过程的功能是用来计算并输出S=1+1/2+1/3+……+1/100的值,请完善程序。
Function SumF(n As Integer)As Single
s = 0
For i=1 To n
s= 【12】
Next i
SumF=s
End Function
Private Sub Form_Click( )
Sum1=SumF(100)
Print
Print"sum1="; sum1
End Sub
[填空题]下列过程的功能是:用来计算并输出S = 1+1/2+1/3+…+1/100的值。请完善下列程序。
Function SumD(n As Integer)As Single
s = 1
i = 1
Do
i = i + 1
s = s + 1 / i
Loop Until ______
SumD = s
End Function
Private Sub Form_Click( )
sum1 = SumD(100)
Print "sum1 = "; sum1
End Sub
[填空题]下列过程的功能是:用来计算并输出S=1+1/2+1/3+…+1/100的值。请完善程序。
Function SumF(n As Integer)As Single
s=0
For i=1 To n
s=______
Next i
SuraF=s
End Function
Private Sub Form_Click( )
Sum1=SumF(100)
Print
Print "sum1=" :sum1
End Sub
[填空题]下列过程的功能是:用来计算并输出S=1+1/2+1/3+…+1/100的值,请完善下列程序。
Furiction SumD (n As Integer)As Single
s = 1
i = 1
Do
i = i + 1
s = s + 1 / i
Loop Until 【12】
SumD = s
End Function
Private Sub Form Click( )
sum1=SumD(100)
Print "sum1="; sum1
End Sub
[简答题]下列给定程序中,函数fun( )的功能是计算并输出 high以内的素数之和。high由主函数传给fun( )函数。
例如:若high的值为100,则函数的解为1060。
请改正程序中的错误,使它能得到正确结果。
注意:不要改动main函数,不得增行或删行,也不得更改程序的结构。
[试题源程序]
#include<conio.h>
#include<stdio.h>
#include<math.h>
int fun(int high)
int sum=0,n=0,j,yes;
while(high>=2)
yes=1;
for(j=2;j<=high/2;j++)
/**********************found***********************/
ifhigh%j==0
yes=0;
break;
/***********************found***********************/
if(yes==0)
sum+=high;
n++;
high--;
return sum;
main( )
clrscr( );
printf("%d/n",fun(100));
[填空题]【说明】
以下程序的功能是计算三角形、矩形和正方形的面积并输出。
程序由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 lb;
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-la)*(s-lb)*(s-Ic));
}
};
void main( ) {
Figure*figures[3]={
ne
[简答题]【说明】
以下C++程序的功能是计算三角形、矩形和正方形的面积并输出。程序由4个类组成:类Triangle、Rectangle和Square分别表示三角形、矩形和正方形;抽象类Figure提供了一个纯虚拟函数getArea( ),作为计算上述3种图形面积的通用接口。
#include<iostream.b>
#include<math.h>
class Figure{
public:
virtual double getArea0=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->lb; 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), ne
[简答题]【说明】
以下C++程序的功能是计算三角形、矩形和正方形的面积并输出。程序由4个类组成:类Triangle、Rectangle和Square分别表示三角形、矩形和正方形;抽象类Figure提供了一个纯虚拟函数getArea( ),作为计算上述3种图形面积的通用接口。
#include<iostream.b>
#include<math.h>
class Figure
public:
virtual double getArea0=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->lb; this->lc;
double getArea( )
double s=(la+lb+lc)/2.0;
return sqrt(s*(s-l
[填空题]【说明】
以下程序的功能是计算正方体、球体和圆柱体的表面积和体积并输出。
程序由4个类组成:类cube、sphere和cylinder分别表示正方体、球体和圆柱体;抽象类 container为抽象类,提供了两个纯虚拟函数surface_area( )和volum( ),作为通用接口。
【C++程序】
#include<iostream.h>
#define pi 3.1416
class container{
protected:
double radius;
public:
container(double radius) {container::radius=radius;}
virtual double surface_area( )=0;
virtual double velum( )=0;
};
class cube: (1) { //定义正方体类
public:
cube(double radius):container(radius){};
double surface_area ( ) {return 6 * radius * radius;}
double volum( ) {return radius * radius * radius;}
};
class sphere: (2) { //定义球体类
public:
sphere(double radius): container(radius){};
double surface_area( ) { return (3) ;}
double volum( ) {return pi * radius * radius * radius * 4/3;}
};
class cylinder: (4) { //定义圆柱体类
double height;
public:
cylinder(double radius,double height):container(radius)
{
container::height=height;
}
[简答题]
阅读以下说明和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(
[判断题]BIOS芯片是用来存储基本输入输出程序的专用芯片。