C++ Primer Plus第二章练习

2.7.1

#include <iostream>
using namespace std;
int main(void)
{
    cout << "姓名:XXX" << endl;
    cout << "地址:XXX" << endl;
    return 0;
}

2.7.2

#include <iostream>
using namespace std;
int main(void)
{
    cout << "请输入以long为单位的距离:";
    int temp;
    cin >> temp;
    cout << "转换为码后: " << temp * 220 << endl;
    return 0;
}

2.7.3

#include <iostream>
using namespace std;
void One(void);
void Two(void);
int main(void)
{
    One();
    One();
    Two();
    Two();
    return 0;
}
void One(void)
{
    cout << "Three blind mice" << endl;
}
void Two(void)
{
    cout << "See how they run" << endl;
}

2.7.4

#include <iostream>
using namespace std;
int main(void)
{
    cout << "请输入您的年龄:";
    int year;
    cin >> year;
    cout << year << "年有" << year * 12 << "个月" << endl;
    return 0;
}

2.7.5

#include <iostream>
using namespace std;
int Fahrenheit(int);
int main(void)
{
    cout << "Please enter a Celsius value: ";
    int Fah;
    cin >> Fah;
    cout << Fah << " degrees Celsius is " << Fahrenheit(Fah) << " degrees Fahrenheit." << endl;
    return 0;
}
int Fahrenheit(int num)
{
    return num * 1.8 + 32;
}

2.7.6

#include <iostream>
using namespace std;
double Astronomy(double);
int main(void)
{
    cout << "Enter the number of light years:";
    double Ast;
    cin >> Ast;
    cout << Ast << " light years = " << Astronomy(Ast) << " astronomical units." << endl;
    return 0;
}
double Astronomy(double num)
{
    return num * 63240;
}

2.7.7

#include <iostream>
using namespace std;
void ShowTime(int, int);
int main(void)
{
    int hour, min;
    cout << "Enter the number of hours: ";
    cin >> hour;
    cout << "Enter the number of minutes: ";
    cin >> min;
    ShowTime(hour, min);
    return 0;
}
void ShowTime(int hour, int min)
{
    cout << "Time: " << hour << ':' << min << endl;
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值