题目详情
当前位置:首页 > 计算机考试 > 初级程序员
题目详情:
发布时间:2024-03-07 18:45:01

[简答题]【说明】 以下程序的功能是设计一个栈类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

更多"【说明】 以下程序的功能是设计一个栈类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( )
[填空题]阅读以下说明和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
[填空题]
阅读以下说明和C程序代码,将程序补充完整。
[说明]
下面C程序代码的功能是:对于输入的一个正整数n(100≤n<1000),先判断其是否是回文数(正读反读都一样的数)。若不是,则将n与其反序数相加,再判断得到的和数是否为回文数,若还不是,再将该和数与其反序数相加并进行判断,依此类推,直到得到一个回文数为止。例如,278不是回文数,其反序数为872,相加后得到的1150还不是回文数,再将1150与其反序数511相加,得到的1661是回文数。
函数int isPalm(long m)的功能是:将正整数m的各位数字取出存入数组中,然后判断其是否为回文数。若m是回文数则返回1,否则返回0。
[C程序代码]
#include<stdio.h>
#include<stdlib.h>
int isPalm(long m)
{
int i=0, k=0;
char str[32];
while(m>0) {
str[k++]= (1) +’0’;
m=m/10;
}
for(i=0; i<k/2; i++)
if(str[i]!=str[ (2) ])return 0;
return 1;
}
int main( )
{
long n, a, t;
printf("input a positive integer: "); scanf("%ld", &n);
if(n<100||n>=1000)return -1;
while( (3) ) {
printf("%id->", n);
for(a=0, t=n; t>0; ){
a= (4) *10+t%10; t=t/10;
n= (5) ;
printf("%id/n", n);
system("pause"); return 0;


[单项选择]仅根据规格说明书描述的程序功能来设计测试用例的方法称为
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

我来回答:

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

订单号:

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