题目详情
当前位置:首页 > 计算机考试 > 初级程序员
题目详情:
发布时间:2023-10-09 21:31:19

[简答题]【说明】
以下【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

更多"【说明】 以下【C程序】的功能是从文件text_01.ini中读入一"的相关试题:

[简答题]【说明】
本程序从正文文件text.in中读入一篇英文短文,统计该短文中不同单词及出现次数,并按词典编辑顺序将单词及出现次数输出到正文文件word.out中。
程序用一棵有序二叉树存储这些单词及其出现的次数,边读入边建立,然后中序遍历该二叉树,将遍历经过的二叉树上的结点内容输出。
【函数】
# include <stdio.h>
# include <malloc.h>
# include <ctype.h>
# include <string.h>
# define INF "text.in"
# define OUTF "word.our’
typedef struct treenode
char *word;
int count;
struct treenode *left, *right;
BNODE;
int getword(FILE *fpt, char *word)
char c;
c=fgetc(tpt);
if (c==EOF)
return 0;
while(!(tolower(c)>= ’a’ && tolower(c)<= ’z’))
c=fgetc(fpt);
if (c==EOF)
return 0;
/* 跳过单词间的所有非字母字符 */
while(tolower(c)>= ’a’ && tolower(c)<= ’z’)
*word++=c;
c=fgetc(fpt);
 
*word=’/0’;
return 1;

void binary_tree(BNODE **t, char *word)
BNODE *ptr, *p; int compres;
p=NULL;
(1) ;
while (ptr) /* 寻找
[简答题]【说明】本程序从正文文件text.in中读入一篇英文短文,统计该短文中不同单词及出现次数,并按词典编辑顺序将单词及出现次数输出到正文文件word.out中。
程序用一棵有序二叉树存储这些单词及其出现的次数,边读入边建立,然后中序遍历该二叉树,将遍历经过的二叉树上的结点的内容输出。
#include <stdio.h>
#include <malloc.h>
#include <ctype.h>
#include <string.h>
#define INF "text.in"
#define OUTF "wotd.out"
typedef struct treenode
char *word;
int count;
struct treenode *left,*right;
BNODE
int getword (FILE *fpt,char *word)
char c;
c=fgetc (fpt);
if ( c=EOF)
return 0;
while(!(tolower(c)>=’a’ && tolower(c)<=’z’))
c=fgetc (fpt);
if ( c==EOF)
return 0;
/*跳过单词间的所有非字母字符*/
while (tolower (c)>=’a’ && tolower (c)<=’z’)
*word++=c;
c=fgetc (fpt);

*word=’/0’;
return 1;

void binary_tree(BNODE **t,char *word)
BNODE *ptr,*p;int compres;
P=NULL; (1)
while (ptr) /*寻找插入位置*/
compres=strcmp (word, (2) <
[填空题]阅读以下说明和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
[填空题]以下程序的功能是:把程序文件smtextl.txt的内容全部读入内存,并在文本框Textl中显示出来。请填空。
Private Sub Command1_Click( )
Dim inData As String
Text1.Text=" "
Open"smtext1.txt"______As______
DO While______
Input # 2,inData
Text1.Text=Text1.Text&inData
Loop
Close # 2
End Sub
[简答题]【说明】 以下程序的功能是设计一个栈类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
[简答题][说明] 以下程序实现了在applet里移动图形文件,仔细阅读代码和相关注释,将程序补充完整。 [代码6-1] import j ava. awt. *; import j ava.awt.event.*; import java.applet. Applet; public class AppCIU extends Applet implements MouseMotionListener, MouseListener { Image IMG onClick=over(this) title=放大; // 声明 Image 类类型的变量 IMG onClick=over(this) title=放大 int x=70,y=60,posX=70,posY=60,dx,dy; public void init ( ) { IMG onClick=over(this) title=放大=getImage ( getCodeBase ( ) ,"mouse.gif" ); //载入影像 addMouseListener ( this ); addMouseMotionListener ( this );   } public void mousePressed ( MouseEvent e ) { dx=e.getX( )-posX; //取得按下之点与基准点X方向的距离 dy=e.getY( )-posY; //取得按下之点与基准点Y方向的距离 } public void mouseDragged ( MouseEvent e ) { (1) (2) if ( dx>0 && dx<120 && dy>0 && dy<60 ) //如果指针落在图形上方 { Graphics g=getGraphics ( ); (3) } } public void paint ( Graphics g ) { (4) (5
[填空题]【说明】 以下程序的功能是计算三角形、矩形和正方形的面积并输出。 程序由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( )

我来回答:

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

订单号:

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