更多"[说明]
以下程序的功能是统计学生成绩,包括输入学生的姓名和成绩,"的相关试题:
[填空题]阅读以下说明和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的次数,然后输出,请在填空[9]处填入适当的程序完成功能。
[简答题]【说明】
以下【C程序】的功能是从文件text_01.ini中读入一篇英文短文,统计该短文中不同单词和它的出现次数,并按词典编辑顺序将单词及它的出现次数输出到文件word_xml.out中。
该C程序采用一棵有序二叉树存储这些单词及其出现的次数,一边读入一边建立。然后中序遍历该二叉树,将遍历经过的二叉树上节点的内容输出。
程序中的外部函数
int getword(FILE *fpt,char *word)
从与fpt所对应的文件中读取单词置入word,并返回1;若已无单词可读,即到文件尾部时,则函数返回0。
【C程序】
#include <stdio.h>
#include <malloc.h>
#include <ctype.h>
#include <string.h>
#define INF "TEXT_01.INI"
#define OUTF "WORD_XML.OUT"
typedef struct treenode
char *word;
int count;
struct treenode *left, *right;
BNODE;
int getword(FILE *fpt,char *word);void binary tree(BNODE **t,char *word)
BNODE *ptr, *p;
int cmpres;
p = NULL;
(1) ;
while (ptr) /*寻找插入位置*/
cmpres = strcmp(word, (2) ); /* 保存当前比较结果*/
if (!cmpres)
(3)
return;
else
(4) ;
ptr = cmpres > 0 ptr->right : ptr->left;
ptr = (BNODE *)malloc(sizeo
[简答题]【说明】
以下程序的功能是设计一个栈类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
[填空题][说明]
以下程序的功能是计算三角形、矩形和正方形的面积并输出,程序由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
[简答题]【说明】
以下程序的功能是设计一个栈类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( )