标题:大神求助,下面程序错在哪里呀
只看楼主
童木不会飞
Rank: 1
等 级:新手上路
帖 子:9
专家分:0
注 册:2013-10-21
结帖率:50%
已结贴  问题点数:10 回复次数:3 
大神求助,下面程序错在哪里呀
#include<iostream>
using namespace std;
#include<string>
class Student
{
private:
int number;
string xingming;
float score;
public:
     friend Lesson;
    Student(int n,string x,float s ):number(n),xingming(x),score(s){}
    void display()
    {
        cout<<xingming<<endl;
       cout<<number<<endl;
       cout<<score<<endl;
    }
};
class Lesson
{
private:
int id, s;
string name,teacher;
public:
    Lesson(int i,string n,string t,int sd):id(i),name(n),teacher(t),s(sd){}
    void AddStudent(int i);
    float GetPassRate(int s);
    void ShowInfo();
};
void Lesson::AddStudent(int i)
{
    Student stud[3]={
      Student(1002,"wangfang",98),
      Student(1003,"lingping",72),
      Student(1004,"zhangmin",59.3f)};
      stud[i].display();
   
}
float Lesson::GetPassRate(int s)
{
    int n=0;
    Student stud[3]={
      Student(1002,"wangfang",98),
      Student(1003,"lingping",72),
      Student(1004,"zhangmin",59)};
      for(int m=0;m<3;m++)
        if(stud[m].score>=60.0)
         n++;
    return(n/s);
}
void Lesson::ShowInfo()
{
    cout<<id<<endl;
    cout<<name<<endl;
    cout<<teacher<<endl;
    cout<<s<<endl;
}
void main()
{
   
      Lesson less(1,"c++","chen",3);
      int i;
      for(i=0;i<3;i++)
      Lesson::AddStudent(i);
      Lesson::GetPassRate(3);
      less.ShowInfo();
}
搜索更多相关主题的帖子: teacher private display include public 
2013-11-25 22:49
yuccn
Rank: 16Rank: 16Rank: 16Rank: 16
来 自:何方
等 级:版主
威 望:167
帖 子:6809
专家分:42393
注 册:2010-12-16
得分:4 
#include<iostream>
using namespace std;
#include<string>
class Lesson; // 加上这个
class Student
{
private:
int number;
string xingming;
float score;
public:
     friend Lesson;
    Student(int n,string x,float s ):number(n),xingming(x),score(s){}
    void display()
    {
        cout<<xingming<<endl;
       cout<<number<<endl;
       cout<<score<<endl;
    }
};
class Lesson
{
private:
int id, s;
string name,teacher;
public:
    Lesson(int i,string n,string t,int sd):id(i),name(n),teacher(t),s(sd){}
    void AddStudent(int i);
    float GetPassRate(int s);
    void ShowInfo();
};
void Lesson::AddStudent(int i)
{
    Student stud[3]={
      Student(1002,"wangfang",98),
      Student(1003,"lingping",72),
      Student(1004,"zhangmin",59.3f)};
      stud[i].display();
   
}
float Lesson::GetPassRate(int s)
{
    int n=0;
    Student stud[3]={
      Student(1002,"wangfang",98),
      Student(1003,"lingping",72),
      Student(1004,"zhangmin",59)};
      for(int m=0;m<3;m++)
        if(stud[m].score>=60.0)
         n++;
    return(n/s);
}
void Lesson::ShowInfo()
{
    cout<<id<<endl;
    cout<<name<<endl;
    cout<<teacher<<endl;
    cout<<s<<endl;
}
void main()
{
   
      Lesson less(1,"c++","chen",3);
      int i;
      for(i=0;i<3;i++)
      less.AddStudent(i); // Lesson::AddStudent(i);
      less.GetPassRate(3); // Lesson::GetPassRate(i);

      less.ShowInfo();
}

我行我乐
我的博客:
http://blog.yuccn. net
2013-11-26 08:10
z773698151
Rank: 1
等 级:新手上路
帖 子:1
专家分:4
注 册:2013-11-26
得分:4 
student类前应有前向引用声明,
2013-11-26 20:52
童木不会飞
Rank: 1
等 级:新手上路
帖 子:9
专家分:0
注 册:2013-10-21
得分:0 
回复 2楼 yuccn
可是我想把那个求及格率的结果输出,在那个函数里面我后来加了cout,但是为啥最后的结果没有呢?
2013-11-27 20:58



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-424202-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.753871 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved