C++ DAY2作业

2023-12-27 22:13:16

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.思维导图

文章来源:https://blog.csdn.net/qq_44121517/article/details/135253219
本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。