#include <iostream>
using namespace std;
class Stu{
private:
int age;
string sex;
double height;
public:
double score;
void set_info(int age1,string sex1,double height1);
int get_age();
string get_sex();
double get_height();
void get_info();
};
void Stu::set_info(int age1, string sex1, double height1){
age = age1;
sex = sex1;
height = height1;
}
int Stu::get_age(){
return age;
}
string Stu::get_sex(){
return sex;
}
double Stu::get_height(){
return height;
}
int main()
{
Stu s1;
s1.score = 200;
s1.set_info(30,"男",172.2);
//cout << " score= " << s1.score << endl;
cout << "age = " << s1.get_age() << " sex = " << s1.get_sex() << " heigth = "
<< s1.get_height() << " score= " << s1.score << endl;
//cout << sizeof(string) << endl;
return 0;
}
2.?写一个有默认参数的函数,把声明和定义分开,并在主函数内成功调用
#include <iostream>
using namespace std;
//定义一个有默认参数的函数
struct Stu{
public:
int sum_score(int a,int b=10);
};
int Stu::sum_score(int a,int b){
return a + b;
}
int main()
{
Stu stu;
cout << "sum_score = " << stu.sum_score(80) << endl;
return 0;
}
3. 字节对齐
35 不是 4 的? 倍数
40 字节
4. 思维导图