如何显示一个类的值?

我几乎是C ++的新手。我开设了一个学生班。首先,当我返回标记的媒体时,它不是浮点值。例如:如果我输入5和10,它将返回7而不是7.5。

其次,当我想用​​函数disp()显示名称和媒体时,它不起作用。

有人可以帮忙吗?

谢谢

#include <iostream>
using namespace std;

class student{
    public:
        string name;
        int mark1, mark2;

        float calc_media(){ 
            float media = (mark1 + mark2)/2; 

            return media; 

        }
        void disp(){
            cout << "Student:" << name << endl;
            cout << "media:"<< calc_media() << endl;
        }

};



int main (){
    student peter;

    cout <<"name:" ;
    cin>>peter.name;
    cout <<"mark1:" ;
    cin>>peter.mark1;
    cout <<"mark2:" ;
    cin>>peter.mark2;
    cout <<"ALL:" << peter.disp();




    return 0;
}


编辑: 我也知道我可以做这样的事情:

我已经删除了该函数的功能,并且已经将该类写出了,但是它不起作用。

#include <iostream>
using namespace std;

class student{
    public:
        string name;
        int mark1, mark2;

        float calc_media(int, int);

        void disp(){
            cout << "Student:" << name << endl;
            cout << "Media:"<< calc_media(int, int) << endl;
        }


};

student::float calc_media(int x, int y){
    float media = (x + y)/2.0; 

    return media; 
}


int main (){
    student peter;

    cout <<"name:" ;
    cin>>peter.name;
    cout <<"mark1:" ;
    cin>>peter.mark1;
    cout <<"mark2:" ;
    cin>>peter.mark2;
    cout <<"media:" << peter.calc_media(peter.mark1, peter.mark2) << endl << endl;

    peter.disp();

    return 0;
}