m0_64509442 2022-04-26 02:00 采纳率: 83.3%
浏览 24
已结题

c加加小问题 哪里出错了

#include
using namespace std;
class Student
{public:
Student(int n , float s):num(n),score(s){}
void change (int n,float s){num=n;score=s;}
void display(){cout<<num<<""<<score<<endl;}
private:
int num;
float score;
};
int main()
{Student stud(101,78.5);
stu.display();
stu.change(101,80.5);
stu.display();
return 0;
}

img

  • 写回答

2条回答 默认 最新

  • a5156520 2022-04-26 02:11
    关注

    在main函数调用时,实例stu改为stud就可以了,名字写错了。

    #include <iostream> 
    using namespace std;
    class Student
    {
        public:
        Student(int n , float s):num(n),score(s){}
        void change (int n,float s){num=n;score=s;}
        void display(){cout<<num<<" "<<score<<endl;}
        private:
        int num;
        float score;
    };
    
        int main()
        {
            Student stud(101,78.5);
            stud.display();
            stud.change(101,80.5);
            stud.display();
            return 0;
        }
    
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)
编辑
预览

报告相同问题?

问题事件

  • 系统已结题 5月3日
  • 已采纳回答 4月26日
  • 创建了问题 4月26日