请打开考生文件夹下的解决方案文件proj1,此工程中包含程序文件main.epp,其中有类Score(“成绩”)和主函数main的定义。程序中位于每个“//ERROR ****found****”之后的一行语句有错误,请加以改正。改正后程序的输出结果应为:

admin2020-04-07  17

问题 请打开考生文件夹下的解决方案文件proj1,此工程中包含程序文件main.epp,其中有类Score(“成绩”)和主函数main的定义。程序中位于每个“//ERROR ****found****”之后的一行语句有错误,请加以改正。改正后程序的输出结果应为:
    学号:12345678课程:英语总评成绩:85
    注意:只修改每个“//ERROR ****found****”下的一行,不要改动程序中的其他内容。
    #include<iostream>
    using namespace Std;
    class Score {
    public:
      Score(const  char * the_course,const char * the_id,int the_normal,int the midterm,int the_end of_term)
      :course(the_course),normal(the_normal),midteEm(the_midterm),end_of_term(the_end_of_term){
    //ERROR ******* found *******
        strcpy(the_id,student_id);
      }
      const char * get;Course()const{return course;}//返回课程名称
    //ERROR ******* found*******
      const char * getTD()const{return &student_id;}  //返回学号
      int getNormal()const{returnnormal;}  //返回平时成绩
      int getMidterm()const{  return midterm;}
    //返回期中考试成绩
      int getEndOfTerm()const{return end_of_term;}  //返回期末考试成绩
      int get;Final()const;  //返回总评成绩
    private:
      const char * course;  //课程名称
      char student_id[12];  //学号
      int;normal;  //平时戍绩
      int midterm;//期中考试成绩
      int end_of_term;  //期末考试成绩
    };
    //总评成绩中平时成绩占20%,期中考试占30%,期末考试占50%,最后结果四舍五入为一个整数
    //ERROR *******found*******
    int getFinal()const{
      return normal * 0.2+midterm* 0.3+end_of_term *0.5+0.5;
    }
    int main(){
      char English[]="英语";
      Score score(English,"12345678",68,83,92);
      cout<<"学号:"<<score.getTD()<<"";
      cout<<"课程:"<<score.getCouEse()<<"";
      cout<<"总评成绩:"<<score.getFinal()<<endl;
      return 0;
    }

选项

答案(1)strcpy(student_id,the_id); (2)coast char * getID()coast{return student_jd;} (3)int Score::getFinal()const{

解析 (1)主要考查考生对strcpy()函数的掌握情况,strcpy(参数一,参数二)函数的功能是将参数二的字符串复制给参数一,因此在这里student_id应该位于参数一的位置,即strcpy(student_id,the_id);。
    (2)主要考查考生对函数返回值的掌握情况,根据注释:返回学号可知学号应该由一个字符串组成。再看函数要返回的类型:const char * ,可知要返回一个char型指针,也就是一个char型数组,而&student_id是一个char型数组指针,因此直接写studentjd即可。
    (3)主要考查考生对类的成员函数的掌握情况,因为getFinal函数是Score类的成员函数,所以在定义时要加上类名和作用域符,即Score::。
转载请注明原文地址:https://kaotiyun.com/show/Gu8p777K
0

最新回复(0)