C++ Primer Plus第六版 编程练习第二章

1.

#include<iostream>

int main()
{
    using namespace std;
    cout << "您的姓名 地址";
    return 0;
}

2.

#include<iostream>

const int Long_to_yard = 220;
int main()
{
    using namespace std;
    cout << "输入一个距离: ";
    int n;
    cin >> n;
    int m = n* Long_to_yard;
    cout << n << " long = ";
    cout << m << " 码" << endl;
    return 0;
}

3.

#include<iostream>
void userdefinitionA();
void userdefinitionB();
using namespace std;
int main()
{
    userdefinitionA();
    userdefinitionA();
    userdefinitionB();
    userdefinitionB();
    return 0;
}

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

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

4.

#include<iostream>

int main()
{
    using namespace std;
    int age, month;
    cout << "输入你的年龄: ";
    cin >> age;
    month = age * 12;
    cout << "你已经过完了你人生中的" << month<<"个月";
    return 0;
}

5.

#include<iostream>

double ctemperature_to_ftemperature(double);

int main()
{
    using namespace std;
    double n, m;
    cout << "输入一个华氏温度 ";
    cin >> n;
    m = ctemperature_to_ftemperature(n);
    cout << n << " 摄氏温度等于 "
        << m << " 华氏温度";
    return 0;
}

double ctemperature_to_ftemperature(double ctemperature)
{

    double ftemperature = 1.8 * ctemperature + 32.0;
    return ftemperature;
}

6.

#include<iostream>
long double distance(double);
int main()
{
    using namespace std;
    double n;
    long double m;
    cout << "Enter the number of light years: ";
    cin >> n;
    m = distance(n);
    cout << n << " light years = "
        << m << " astronomical units.";
    return 0;
}

long double distance(double n)
{
    long double m;
    m = n * 63240;
    return m;
}

7.

#include<iostream>
void showtime(int, int);
using namespace std;
int main()
{
    int h, m;
    cout << "Enter the number of hours: ";
    cin >> h;
    cout << "Enter the number of minutes: ";
    cin >> m;
    showtime(h, m);
    return 0;
}
void showtime(int h, int m)
{
    cout << "Time: " << h << ":" << m;
}
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值