《C++ Primer Plus(第6版)》编程练习代码 Chapter 2

Chapter 2

2.1

#include <iostream>
int main()
{
    using namespace std ;
    cout << "XWG\n" << "HZAU";
    cin.get();
    return 0;
}

2.2

#include <iostream>
int main()
{
    using namespace std;
    double lon;
    cin >> lon;
    cout << lon << "long = " << lon * 220 << "m";
    cin.get();
    cin.get();
    return 0;
}

2.3

#include <iostream>

using namespace std;
void s();
void t();
int main()
{
    t();
    t();
    s();
    s();
    cin.get();
}

void t()
{
    cout << "Three blind mice\n";
}

void s()
{
    cout << "See how they run\n";
}

2.4

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

2.5

#include <iostream>

double C2F(double);

int main()
{
    using namespace std;
    double Celsius, Fahrenheit;
    cout << "Please enter a Celsius value: ";
    cin >> Celsius;
    Fahrenheit = C2F(Celsius);
    cout << Celsius << " degrees Celsius is " << Fahrenheit << " degrees Fahrenheit.";
    cin.get();
    cin.get();
}

double C2F(double Celsius)
{
    return 1.8 * Celsius + 32;
}

2.7

#include <iostream>

using namespace std;

void out(int, int);

int main()
{
    int minutes, hours;
    cout << "Enter the number of hours: ";
    cin >> hours;
    cout << "Enter the number of minutes: ";
    cin >> minutes;
    out(hours, minutes);
    cin.get();
    cin.get();
}

void out(int hours, int minutes)
{
    cout << "Time: " << hours << ":" << minutes;
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值