简答题

课程名称:程序员

题目:阅读下列说明和C++代码,填写程序中的空(1)~(6),将解答写入答题纸的对应栏内。  【说明】 以下C++代码实现一个简单绘图工具,绘制不同形状以及不同颜色的图形。部分类及其关系如图6-1所示。 【C++代码】 #include <iostream> #include <string> using namespace std; class DrawCircle {      //绘制圆形,抽象类          public:                   (1)  ;//定义参数为 int radius, int x, int y                 virtual~DrawCircle() { } };   class RedCircle:public DrawCircle {     //绘制红色圆形          public:                 void drawCircle(int radius, int x, int y) {                        cout << "Drawing Circle[red,radius: " <<radius;                       cout << ",x: " <<x<< ",y: "<<y<< "]" << end1;                 } };   class GreenCircle:public DrawCircle {    //绘制绿色圆形          public:                  void drawCircle(int radius, int x, int y) {                          cout <<"Drawing Circle[green,radius: " << radius;                          cout <<",x: " <<x<< ",y: " <<y<< "]" << end1;                 } };   class Shape {    //形状,抽象类          protected:                      (2)       ;          public:                 Shape(DrawCircle *drawCircle) {                          this -> drawCircle = drawCircle;                 }                 virtual~shape() { }          public:                 virtual void draw() = 0; };   class Circle:public Shape {    //圆形          private:                  int x,y,radius;          public:                  Circle(int x,int y,int radius,DrawCircle *drawCircle)      (3)     {                          this->x = x;                          this->y = y;                          this->radius = radius;                  }          public:                  void draw() {                          drawCircle ->       (4)      ;                  } };   int main() {         Shape *redCircle=new Circle(100,100,10,     (5)    );//绘制红色圆形         Shape *greenCircle=new Circle(100,100,10,     (6)  );//绘制绿色圆形         redCircle ->draw();         greenCircle ->draw();         return 0; }

简答题

课程名称:程序员

题目:阅读以下说明和Java程序,填写程序中的空(1)~(6),将解答写入答题纸的对应栏内。 【说明】 以下Java代码实现一个简单绘图工具,绘制不同形状以及不同颜色的图形。部分接口、类及其关系如图5-1所示。 【Java代码】 interface DrawCircle {     //绘制圆形       public     (1)    ; }   class RedCircle implements DrawCircle {    //绘制红色圆形        public void drawCircle(int radius,int x, int y)  {              System.out.println("Drawing Circle[red,radius:" + radius + ",x:" + x + ",y:" +y+ "]");        } }   class GreenCircle implements DrawCircle {    //绘制绿色圆形       public void drawCircle(int radius, int x, int y) {             System.out.println("Drawing Circle[green,radius:" +radius+ ",x: " +x+ ",y: " +y+ "]");       } } abstract class Shape {    //形状        protected      (2)   ;          public Shape(DrawCircle drawCircle) {              this.drawCircle = drawCircle;         }         public abstract void draw(); }   class Circle extends Shape {    //圆形        private int x,y,radius;          public Circle(int x,int y,int radius,DrawCircle drawCircle) {                    (3)   ;                   this.x = x;                   this.y = y;                   this.radius = radius;        }          public void draw() {               drawCircle.     (4)    ;        } }   public class DrawCircleMain {       public static void main(String[] args) {             Shape redCircle=new Circle( 100,100,10,      (5)      );//绘制红色圆形             Shape greenCircle=new Circle(200,200,10,      (6)     );//绘制绿色圆形               redCircle.draw();             greenCircle.draw();      } }

简答题

课程名称:程序员

题目:阅读以下说明和C代码,填写代码中的空(1)~(6),将解答写入答题纸的对应栏内。【说明】下面的C代码在输入的100个英文单词中找出最小单词和最大单词。约定每个单词是仅由英文字母构成的字符串,且都不超过20个字符。单词的大小按照字典序定义。例如,单词“entry”大于“enter”、“art”小于“ article”、“an”等于“An”。 【C代码】#include <stdio.h>#define NUMBER 100int isValid(const char *s1);                  //若字符串s1仅包含英文字母则返回1,否则返回0char toLower(char ch);                       //将大写字母转换为小写字母int usr_strcmp(char *s1, char *s2);    //比较字符串s1和s2,相等时返回0,                                                            //s1大则返回正整数,s1小则返回负整数void usr_strcpy(char *s1,const char *s2);     //字符串s2拷贝给s1 int main(){       char word[32];        char maxWord[32]="", minWord[32] ="";        int numWord=0;        while(num Word<NUMBER) {             scanf("%s",    (1)    );                                 / /输入一个单词存入word             if(is Valid(word))     {                   if (0==num Word) {usr_strcpy(min Word,word);usr_strcpy(max Word,word);}                   num Word++;                   if(         (2)       >0)                              / /调用usr_strcmp比较单词                              usr_strcpy(max Word, word);      / /用max Word记下最大单词                   else                              if(       (3)      <0)                     / /调用usr_strcmp比较单词                                    usr_strcpy(min Word,word); / /用min Word记下最小单词            }      }      printf("max Word=%s                min Word=%s\n",max Word,min Word);      return 0;}int is Valid(const char *s){     for(; *s ; s++)         if(!(*s>='a' && *s<='z') && !(*s>='A' && *s<='Z'))             return 0;     return 1; } char toLower(char ch){     //若ch为大写字母则返回其小写形式,否则直接返回原字符      if(ch>='A' && ch<='Z')                 ch=         (4)         +'a';      return ch;} int usr_strcmp(char *s1,char *s2){    //按字典序比较两个英文单词,若s1表示的单词大,则返回正整数,     //若s1表示的单词小,则返回负整数;否则返回0      for(;    (5)    ;) {              if(toLower(*s1)==toLower(*s2))    {s1++,s2++;}              else                    break;      }     return(toLower(*s1) - toLower(*s2));} void usr_strcpy(char *s1,const char *s2){    //将s2表示的字符串复制给s1       for(;       (6)       ;)            *s1++= *s2++;       *s1='\0';}

简答题

课程名称:程序员

题目:阅读以下C代码,回答问题1至问题3,将解答填入答题纸的对应栏内。【C代码1】 float adjustSalary(int service_year,int age,float salary) {      if( service_year <=5 ) {          if( age > 30 )              salary *= 1.2;      }      else              salary *= 2.0;      return salary;} 【C代码2】 void foo(int coin) {     switch (coin) {           case 1:   printf("Cent\n");           case 5:   printf("Nicke1\n");break;           case 10:  printf("Dime\n");           case 25:  printf("Quarter\n");     }} 【C代码3】 int getSum(int n){          int t, i = 0, sum = 0;          while ( i < n ) {                scanf("%d", &t);                 if( t<0 )                     continue;                 sum += t;                 i++;          }          return sum;}  问题:3.1   【问题1】(3分)对于【C代码1】,写出下面的函数调用后x1、x2和x3的值。x1 = adjustSalary(1,25,9000.0);x2 = adjustSalary(8,32,7000.0);x3 = adjustSalary(5,41,5000.0); 问题:3.2   【问题2】(6分)(1)写出函数调用为foo(1)的输出结果;(2)写出函数调用为foo(5)的输出结果;(3)写出函数调用为foo(10)的输出结果;(4)写出函数调用为foo(25)的输出结果。 问题:3.3   【问题3】(6分)(1)简要说明【C代码3】中的函数getSum()的功能;(2)程序员小王将函数getSum改写后得到下面的函数getSum_v2(即用for语句来描述循环)。请问,getSum_v2的功能是否与【C代码3】的getSum完全相同,若不同,请说明原因。int get Sum_v2(int n){int t,i=0,sum=0;for(i=0;1           scanf("%d",&t);if(t<0)continue;sum+=t;}return sum;}