c++帮帮忙printfstudentinto那里该怎么传参 - 爱问答

(爱问答)

c++帮帮忙printfstudentinto那里该怎么传参

#include<iostream>

#include<string>

using namespace std;

class Student

{

  public:

  Student(string id="NULL",double score=0);

  static double sum();

  static double average();

  string getid();

  double getscore();

  void setid(string s);

  void setscore(double s);

  void printfstudentinto();

  private:

  string id;

  double score;

  static double total_score;

  static double count;

};

 

string Student::getid()

{

return id;

}

 

double Student::getscore()

{

return score;

}

 

void Student::printfstudentinto()

{

cout<<"学生信息: ";

cout<<"id: "<<getid()<<"score: "<<getscore();

}

 

void Student::setid(string s)

{

id=s;

}

 

void Student::setscore(double s)

{

score=s;

++count;

total_score=total_score+score;

}

 

double Student::sum()

{

return total_score;

}

 

double Student::average()

{

double average=0.0;

    average=total_score/count;

return average;

}

double Student::total_score=0.0;

double Student::count=0.0;

 

int main()

{

Student stu[10];

int n;

double s;

string id;

cout<<"请输入学生的·人数(1~10):";

cin>>n;

for(int i=0;i<n;i++)

{

cout<<"请输入第 "<<i+1<<" 位学生的id、score: ";

cin>>id;

cin>>s;

stu[i].setid(id);

stu[i].setscore(s);

}

printfstudentinto(stu,n);

cout<<"total_score:"<<Student::sum()<<endl;

cout<<"average:"<<Student::average()<<endl;

return 0;

}


你的

printfstudentinto(stu,n);

调用完全不正确,它是Student成员函数,不能直接调用,且它没有参数

正确的方法,改为

    for(int i=0; i<n; i++)

        stu[i].printfstudentinto( );

另外,你的

  Student(string id="NULL",double score=0);

虽然有缺省参数,但没有实现,所以要改为

  Student(string id="NULL",double score=0) {} 

这样程序可以运行,其它小问题你自己再看下

下一篇:电脑就打这一个字卡。打别的字都不卡

上一篇:vb软件提示这个如何解决,谢谢!

热门标签:
excel 网盘 破解 word dll
最新更新:
微软重新评估新的Outlook的使用时机 联想推出搭载联发科Helio G80芯片组的Tab M9平板 英特尔创新大赛时间确定! 微软Edge浏览器在稳定渠道中推出Workspaces功能 英伟达RTX4060TiGPU推出MaxSun动漫主题! 谷歌地图为用户提供了街景服务! GameSir 在T4 Kaleid中推出了一款出色的控制器! 微软开始在Windows 11 中测试其画图应用程序的新深色模式! LG电子推出全球首款无线OLED电视 英伟达人工智能芯片崭露头角! Steam Deck可以玩什么游戏-Steam Deck价格限时优惠 雷蛇推出CobraPro鼠标 Kindle电子阅读器可以访问谷歌商店吗 Windows10如何加入组策略 window10图片查看器怎么没有了?