C++day2作业

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

#include <iostream>

using namespace std;
class Stu
{
private:
    int age;
    string sex;
    int hign;
public:
    int soce;
    void get_information();
    void set_information();
};
void Stu::set_information()
{
    static Stu s1;
    cout << "请输入年龄:" << endl;
    cin >> s1.age;
    age = s1.age;
    cout << "请输入性别:" << endl;
    cin >> s1.sex;
    sex = s1.sex;
    cout << "请输入身高:" << endl;
    cin >> s1.hign;
    hign = s1.hign;
    cout << "请输入分数:" << endl;
    cin >> s1.soce;
    soce = s1.soce;
}
void Stu::get_information()
{
    cout << "年龄:" << "";
    cout << age << endl;
    cout << "性别:" << "";
    cout << sex << endl;
    cout << "身高:" << "";
    cout << hign << endl;
    cout << "分数:" << "";
    cout << soce << endl;
}
int main()
{
    Stu s2;
    s2.set_information();
    s2.get_information();
    return 0;
}

 效果图:

写一个有默认参数的函数,把声明和定义分开,并在主函数内成功调用

#include <iostream>

using namespace std;
int add(int a,int b=20,int c=30);
int main()
{
    cout << add(10) <<endl;
    return 0;
}

int add(int a,int b,int c)
{
    return a+b+c;
}

效果图:

 

 

 

相关推荐

  1. 作业2.2

    2023-12-28 21:38:01       26 阅读
  2. <span style='color:red;'>2</span>.<span style='color:red;'>2</span><span style='color:red;'>作业</span>

    2.2作业

    2023-12-28 21:38:01      33 阅读
  3. 2.2作业

    2023-12-28 21:38:01       28 阅读
  4. 假期作业 2.2

    2023-12-28 21:38:01       33 阅读
  5. 作业2024/2/2

    2023-12-28 21:38:01       33 阅读
  6. QT<span style='color:red;'>作业</span><span style='color:red;'>2</span>

    QT作业2

    2023-12-28 21:38:01      40 阅读
  7. 1.<span style='color:red;'>2</span><span style='color:red;'>作业</span>

    1.2作业

    2023-12-28 21:38:01      35 阅读

最近更新

  1. TCP协议是安全的吗?

    2023-12-28 21:38:01       18 阅读
  2. 阿里云服务器执行yum,一直下载docker-ce-stable失败

    2023-12-28 21:38:01       19 阅读
  3. 【Python教程】压缩PDF文件大小

    2023-12-28 21:38:01       18 阅读
  4. 通过文章id递归查询所有评论(xml)

    2023-12-28 21:38:01       20 阅读

热门阅读

  1. odoo17核心概念view4——view.js

    2023-12-28 21:38:01       40 阅读
  2. vue大屏-列表自动滚动vue-seamless-scroll

    2023-12-28 21:38:01       39 阅读
  3. redis开启密码验证

    2023-12-28 21:38:01       31 阅读
  4. 在next13当中使用centrifuge5.0.1进行websocket请求

    2023-12-28 21:38:01       35 阅读
  5. Linux 命令

    2023-12-28 21:38:01       29 阅读
  6. 常见的hooks

    2023-12-28 21:38:01       34 阅读