题目详情
当前位置:首页 > 计算机考试 > 初级程序员
题目详情:
发布时间:2023-12-20 21:57:30

[简答题]【说明】
以下程序的功能是设计一个栈类stack<T>,并建立一个整数栈。
【程序】
#include < iostream. h >
#include < stdlib. h >
const int Max =20; //栈大小
template < class T >
class stack //栈元素数组
T s[Max]; //栈顶下标
int top;
public:
stack( )

top =-1; //栈顶初始化为-1

void push( const T &item); //item入栈
T pop( ); //出栈
int stackempty( ) const; //判断栈是否为
;
template < class T >
void stack <T >::push(const T &item)

if(top== (1) )

cout <<"栈满溢出" <<endl;
exit(1);

top ++
s[top] = item;

template < class T >
T stack<T> ::pop( )

T temp;
if(top== (2) )

cout <<"栈为空,不能出栈操作" < < endl;
exit(1);

temp =s[top];
top --;
return temp;

template < class T >
int stack < T >:: stackempty( )

更多"【说明】 以下程序的功能是设计一个栈类stack<T>,并建立一个整"的相关试题:

[简答题]【说明】 以下程序的功能是设计一个栈类stack<T>,并建立一个整数栈。 【程序】 #include < iostream. h > #include < stdlib. h > const int Max =20; //栈大小 template < class T > class stack{ //栈元素数组 T s[Max]; //栈顶下标 int top; public: stack( ) { top =-1; //栈顶初始化为-1 } void push( const T &item); //item入栈 T pop( ); //出栈 int stackempty( ) const; //判断栈是否为 }; template < class T > void stack <T >::push(const T &item) { if(top== (1) ) { cout <<"栈满溢出" <<endl; exit(1); } top ++ s[top] = item; } template < class T > T stack<T> ::pop( ) { T temp; if(top== (2) ) { cout <<"栈为空,不能出栈操作" < < endl; exit(1); } temp =s[top]; top --; return temp; } template < class T > int stack < T >:: stackempty( ) const { return top == -1; { void main( ) { stack <int> st; int a[] ={1,2,3,4,5}; cout <<"整数栈" <<e
[填空题]阅读以下说明和Java程序,将应填入 (n) 处的字句写在对应栏内
[说明]
以下程序的功能时三角形、矩形和正方形的面积输出。
程序由5个类组成:areatest是主类,类Triangle,Rectangle和Square分别表示三角形、矩形和正方形,抽象类Figure提供了一个计算面积的抽象方法。
[Java程序]
public class areatest {
public static viod main(string args[]){
Figure[]Figures={
New triangle(2,3,3),new rectangle(5,8),new square(5)
};
for(int i=0; i<Figures.length;i++){
system.out.println(Figures+"area="+Figures.getarea( ));
}
}
}
public abstract class figure {
public abstract double getarea( );
}
public class rectangle extends (1) {
double height;
double width;
public rectangle (double height,double width){
this.height=height;
this.width=width;
}
public string tostring( ){
return"rectangle:height="+height+",width="+width+":";
}
public double getarea( ){
return (2)
}
}
public class square exends (3)
{
public square(double width
[填空题]阅读以下说明和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)
[简答题]
阅读以下说明和C++程序,将应填入(n)处的字句写在对应栏内。
【说明】
以下程序的功能是计算三角形、矩形和正方形的周长并输出。
程序由4个类组成:类Triangle、Rectangle和Square分别表示三角形、矩形和正方形;抽象类 Figure提供了一个纯虚拟函数getGirth( ),作为计算上述3种图形周长的通用接口。
【C++程序】
# include < iostream. h >
# include < math. h >
class Figure {
public:
virtual double getGirth( ) =0; //纯虚拟函数 };
class Rectangle: (1) {
protected:
double height;
double width;
public:
Rectangle( ){};
Rectangle( double height, double width) {
this→height = height;
this→width = width;
}
double getGirth ( ) {
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 ge
[单项选择]仅根据规格说明书描述的程序功能来设计测试用例的方法称为
A. 白盒测试法
B. 黑盒测试法
C. 静态分析法
D. 人工分析法
[填空题][说明]
以下程序的功能是计算三角形、矩形和正方形的面积并输出,程序由5个类组成:AreaTest是主类,类Trianlge、Rectangle和Square分别表示三角形、矩形和正方形,抽象类Figure提供了一个计算面积的抽象方法。
[程序]
public class AreaTest
public static void main(String args [])
Figure [] figures= new Triangle (2,3,3) ,new Rectangle (5,8) ,new Square (5) ;
for (int i=0; 1< figures .length; i++)
System. out .println (figures [i] +"area=" +figures [i]. getArea ( ));



public abstract class Figure
public abstract double getArea( ) ;

public class Rectangle extends (1)
double height;
double width;
public Rectangle(double height, double width)
this .height=height;
this.width=width;

public String toString ( )
return "Rectangle: height= "+height+" , width= "+width+":";

public double getArea ( )
return (2) ;

class Square extends (3)
public Square(double width)
(4) ;

p
[填空题]【说明】 以下程序的功能是计算三角形、矩形和正方形的面积并输出。 程序由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
[填空题]【说明】
以下程序的功能是计算三角形、矩形和正方形的面积并输出。
程序由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;

[填空题]以下程序的功能是从名为filea.dat的文本文件中逐个读入字符并显示在屏幕上。请填空。
#include<stdio.h>
main( )
FILE *fp;char ch;
fp=fopen(______);
ch=fgetc(fp);
whlie(!feof(fp))putchar(eh);ch=fgetc(fp);
putehar("/n");fclose(fp);

[填空题]以下程序的功能是:将输入的正整数按逆序输出。例如:若输入135,则输出531,请填空。 #include<stdio.h> main( ) {int n,s; printf("Enter a number:");scanf("%d",&n); printf("Output:"); do {s=n%10;printf("%d",s);______;} while(n!=0); printf("/n"); }
[填空题]【说明】 以下程序的功能是计算正方体、球体和圆柱体的表面积和体积并输出。 程序由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; }

我来回答:

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

订单号:

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