注册 登录
编程论坛 C++教室

有关类的问题

yangxiaochao 发布于 2010-02-24 15:47, 484 次点击
#include<iostream.h>
class tstudentscore
{
public:
    tstudentscore()
    {
        no=1000;
        chinese=100;
        math=99;
        english=99.5;
        sum=chinese+math+english;
    }
    tstudentscore(int a)
    {
        no=1000;
        chinese=100;
        math=99;
        english=99.5;
        avg=(chinese+math+english)/3;
    }
    void coutprivatevalue();
    void coutsumresultvalue();
    void coutavgresultvalue();
private:
    int no;
    float chinese,math,english,sum,avg;
};
void tstudentscore::coutprivatevalue()
{
    cout<<"no="<<no<<endl;
    cout<<"chinese="<<chinese<<endl;
    cout<<"math="<<math<<endl;
    cout<<"english="<<english<<endl;
}
void tstudentscore::coutsumresultvalue()
{
    cout<<"sum="<<sum<<endl;
}
void tstudentscore::coutavgresultvalue()
{
    cout<<"avg="<<avg<<endl;
}
main()
{
    cout<<"******************************************"<<endl;
    cout<<"**       定义构造函数          **********"<<endl;
    cout<<"******************************************"<<endl;
    tstudentscore score1();
    tstudentscore score2(1);
    score1.coutprivatevalue();
    score1.coutsumresultvalue();
    score2.coutavgresultvalue();
    cout<<"******************************************"<<endl;
}
    红色的提示有错,但是不知道错在哪里。帮我看看啊!
2 回复
#2
pangding2010-02-24 22:06
把错误提示也发上来看一眼呀~~
#3
shiyuehai2010-02-24 23:10
tstudentscore score1();把后面的括号去了就行了,加个括号变成声明函数score1(),返回值为tstudentscore了。。。。。
1