1.课堂struct练习,用class;
#include <iostream>
using namespace std;
class Stu
{
private:
int age;
char sex;
int high;
public:
double score;
void set_values(int a,char b,int c,double d);
int get_age();
char get_sex();
int get_high();
};
void Stu::set_values(int a,char b,int c,double d)
{
age = a;
sex = b;
high = c;
score = d;
}
int Stu::get_age()
{
return age;
}
char Stu::get_sex()
{
return sex;
}
int Stu::get_high()
{
return high;
}
int main()
{
Stu s1;
s1.set_values(18,'m',175,99);
cout << "age= " << s1.get_age() << endl;
cout << "sex= " << s1.get_sex() << endl;
cout << "high= " << s1.get_high() << endl;
cout << "score= " << s1.score << endl;
return 0;
}
2.写一个有默认参数的函数,把声明和定义分开,并在主函数内成功调用
#include <iostream>
using namespace std;
int add(int a,int b , int c=100);
int main()
{
cout << add(1,2)<< endl;
return 0;
}
int add(int a,int b , int c)
{
return a+b+c;
}
3.结构体字节大小计算
4.思维导图