• 2021.4.12


    1.

    /*在主函数中输入一个一维数组,调用函数maxAndMin得到数组元素中的最大值与最小值
    * 信1905-2聂旭东20194006
    */
    #include <iostream>
    using namespace std;
    #define SIZE 10

    void maxAndMin(int a[], int& maximum, int& minimum) {
    maximum = a[0];
    minimum = a[0];
    for (int i = 1; i < SIZE; i++) {
    if (a[i] > maximum)
    maximum = a[i];
    if (a[i] < minimum)
    minimum = a[i];
    }
    }
    int main(){
    int numbers[SIZE], maxValue, minValue, i;
    cout << "Please input " << SIZE << " numbers:";
    for (i = 0; i < SIZE; i++)
    cin >> numbers[i];

    maxAndMin(numbers, maxValue, minValue);

    cout << "The maximum is: " << maxValue << endl;
    cout << "The minimum is: " << minValue << endl;

    return 0;
    }

    2.

    /*用C++语言编写函数,使用函数重载,能求两个整数的最大数、三个整数的最大数、四个整数的最大数
    * 信1905-2聂旭东20194006
    */

    #include<iostream>
    using namespace std;

    int max(int a, int b){
    if (a > b)
    return a;
    else return b;
    }
    int max(int a, int b, int c){
    if (a > b) {
    if (a > c)
    return a;
    else return c;
    }
    else {
    if (b > c)
    return b;
    else return c;
    }
    }
    int max(int a[4])
    {
    int i, max = a[0];
    for (i = 0; i < 3; i++) {
    if (max < a[i]) max = a[i];
    }
    return max;
    }
    void main()
    {
    int i, n, x, a[4];
    cout << "请输入你想要的数字:";
    cin >> n;
    for (i = 0; i < n; i++)
    {
    cin >> a[i];
    }
    if (n == 2)
    x = max(a[0], a[1]);
    else if (n == 3)
    x = max(a[0], a[1], a[2]);
    else if (n == 4)
    x = max(a);
    cout << "最大值是:" << x << endl;
    }

    3.

    /*定义一个学生类
    *在主函数中定义一个有3个元素的对象数组并分别输入,然后输出对象数组的信息
    * 信1905-2聂旭东20194006
    */
    #include<iostream>
    using namespace std;
    class Student
    {
    public:
    Student();
    void Input(int a, string str);
    void Output();
    private:
    int age;
    string name;
    };
    Student::Student()
    {
    }
    void Student::Input(int a, string str)
    {
    age = a;
    name = str;
    }
    void Student::Output()
    {
    cout << "age:" << age << "," << "name:" << name << endl;
    }
    int main()
    {
    int i, age;
    string name;
    Student stus[3];
    for (i = 0; i < 3; i++) {
    cout << "请输入学生年龄:";
    cin >> age;
    cout << "请输入学生姓名:";
    cin >> name;
    stus[i].Input(age, name);
    }
    for (i = 0; i < 3; i++) {
    stus[i].Output();
    }
    return 0;
    }

  • 相关阅读:
    leetcode -- Multiply Strings
    leetcode -- Merge Sorted Array
    leetcode -- Partition List
    leetcode -- Maximal Rectangle
    leetcode -- Largest Rectangle in Histogram TODO O(N)
    FFMPEG学习----分离视音频里的PCM数据
    FFMPEG 实现 YUV,RGB各种图像原始数据之间的转换(swscale)
    cmd 重定向
    使用FFMPEG类库分离出多媒体文件中的H.264码流
    FFMPEG学习----使用SDL构建视频播放器
  • 原文地址:https://www.cnblogs.com/SirNie/p/14650552.html
Copyright © 2020-2023  润新知