C++day2

作业:把课上strcut的练习,尝试着改成class

#include 

using namespace std;

class Stu
{
private:
    int age;
    string sex;
    float high;
    double score;

public:
    void set_sdt(int a,string b,float c, double d);
    int get_age();
    string get_sex();
    float get_high();
    double get_score();
};

void Stu::set_sdt(int a,string b,float c, double d)
{
    age = a;
    sex = b;
    high = c;
    score = d;

}

string Stu::get_sex()
{
    return sex;
}

float Stu::get_high()
{
    return high;
}

double Stu::get_score()
{
    return score;
}

int Stu::get_age()
{
    return age;
}


int main()
{
    Stu s1;
    s1.set_sdt(18, "沃尔玛购物袋", 1.88, 98);
    cout << s1.get_age() << endl;
    cout << s1.get_sex() << endl;
    cout << s1.get_high() << endl;
    cout << s1.get_score() << endl;
}

C++day2_第1张图片

你可能感兴趣的:(c++)