zoukankan      html  css  js  c++  java
  • c++primer 第二章编程练习答案

    2.7.1

    #include<iostream>
    int main() {
        using namespace std;
        char name[20];
        char address[20];
        cout << "input name :";
        cin >> name;
        cout << "input address:";
        cin >> address;
        cin.get();
        cout << "name is " << name;
        cout << endl;
        cout << "address is " << address;
        cin.get();
    }

    2.7.2

    #include<iostream>
    int main() {
        using namespace std;
        int distance;
        cout << "input distance:";
        cin >> distance;
        cin.get();
        cout << "long_distance is ";
        cout << distance * 220;
        cin.get();
    }

    2.7.3

    #include<iostream>
    using namespace std;
    void func_1();
    void func_2();
    int main() {
        //cin.get();
        func_1();
        func_1();
        func_2();
        func_2();
        cin.get();
    }
    void func_1() {
        cout << "Three blind mice" << endl;
    }
    void func_2() {
        cout << "See how they run" << endl;
    }

    2.7.4

    #include<iostream>
    int main() {
        using namespace std;
        int age;
        cout << "Enter your age:";
        cin >> age;
        cin.get();
        cout << age * 12;
        cin.get();
    }

    2.7.5

    #include<iostream>
    double convert(double);
    int main() {
        using namespace std;
        double degrees;
        cout << "Please enter a Celsius value: ";
        cin >> degrees;
        cin.get();
        cout << degrees << " Celsius is " << convert(degrees) << " degrees Fahrenheit";
        cin.get();
    }
    double convert(double degrees) {
        double Fahrenheit = degrees*1.8 + 32.0;
        return Fahrenheit;
    }

    2.7.6

    #include<iostream>
    double convert(double);
    int main() {
        using namespace std;
        double light_years;
        cout << "Enter the number of light years: ";
        cin >> light_years;
        cin.get();
        cout << light_years << " light years = " << convert(light_years) << " astronomical units";
        cin.get();
    }
    double convert(double light_years) {
        double units = light_years * 63240;
        return units;
    }

    2.7.7

    #include<iostream>
    void timer(int, int);
    int main() {
        using namespace std;
        int hours, minutes;
        cout << "Enter the number of hours: ";
        cin >> hours;
        cout << "Enter the number of minutes: ";
        cin >> minutes;
        cin.get();
        timer(hours, minutes);
        cin.get();
    }
    void timer(int hours, int minutes) {
        std::cout << "Timer: " << hours << ":" << minutes;
    }
  • 相关阅读:
    Leetcode中级算法-二分查找01
    二叉查找树01(c++代码实现)
    Leetcode中级算法-动态规划03(最长上升子序列)
    Leetcode中级算法-动态规划02
    Leetcode中级算法-动态规划01
    Leetcode中级算法-全排列
    使用git获取Linux内核
    Kali 使用proxychains接管全局代理
    kali2020.1安装问题解决【选择并安装软件】
    unzip最常用使用方法
  • 原文地址:https://www.cnblogs.com/zhang293/p/7354438.html
Copyright © 2011-2022 走看看