C++ primer plus 课后练习题

第二章:开始学习C++

        一、复习题

        1. C++程序的模块叫 函数

        2. 用来包含头文件

        3. 编译指令 用来确定对象的命名空间

        4. cout << "Hello, world" << endl;

        5. int cheeses;

        6. cheeses = 32;

        7. cin >> cheeses;

        8. cout << "We have " << cheeses << " varieties of cheeses,";

        9. 返回类型 函数名 函数参数

        10. 返回类型为void时

        11.可能未包含头文件;可能未使用编译指令;可能未声明对象的空间(std::)

        二、编程练习

        1.

#include <iostream>
using namespace std;

int main()
{

    cout << "David" << endl;
    cout << "FZU" << endl;

    return 0;
}

        2.

#include <iostream>
using namespace std;

int main()
{
    cout << "plz enter the long" << endl;

    int _long;

    cin >> _long;

    cout << "res = " << _long*220 << endl;

    return 0;
}

        3.

#include <iostream>
using namespace std;

void func1()
{
    cout << "Three blind mice" << endl;
}

void func2()
{
    cout << "See how they run" << endl;
    cout << "See how they run" << endl;
}

int main()
{
    func1();
    func1();
    func2();
    return 0;
}

        4.

#include <iostream>
using namespace std;

int main()
{
    cout << "enter your age: " << endl;

    int age;

    cin >> age;

    cout << age*12 << endl;

    return 0;
}

        5.

#include <iostream>
using namespace std;

int main()
{
    cout << "plz enter a Celsius value : " << endl;
    int t;
    cin >> t;
    cout << (1.8*t + 32) << endl;
    return 0;
}

        6.

#include <iostream>
using namespace std;

int main()
{
    cout << "plz enter light years : " << endl;
    double t;
    cin >> t;
    cout << t*63240 << endl;
    return 0;
}

        7.

#include <iostream>
using namespace std;

int main()
{
    cout << "plz enter hours : " << endl;
    int h;
    cin >> h;
    cout << "plz enter mins : " << endl;
    int mins;
    cin >> mins;
    cout << h << ":" << mins << endl;
}

  • 5
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值