C++ Primer Plus 第六版编程练习解答:第2章

在这里插入图片描述

//2.7 -1
#include <iostream>
using namespace std;

int main()
{
    string myName = "penenz";
    string myAdress = "CSDN";
    cout << "my name is : " << myName << endl;
    cout << "myAdress is : " << myAdress << endl;

    return 0;
}

在这里插入图片描述

//2.7 -2
#include <iostream>
using namespace std;

int main()
{
    long distance;
    cout << "Enter the distance (in long ):"<<endl;
    cin >> distance;
    long ma = distance * 220;
    cout << ma;

    return 0;
}

3.

//2.7 -3
#include <iostream>
using namespace std;

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

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

int main()
{
    show_first();
    show_first();

    show_second();
    show_second();

    return 0;
}

在这里插入图片描述

//2.7 -4
#include <iostream>
using namespace std;

int main()
{
    int age;
    cout << "Enter your age:";
    cin >> age;
    cout << "your age in moinths is " << age * 12 << endl;

    return 0;
}

在这里插入图片描述
在这里插入图片描述

//2.7 -5
#include <iostream>
using namespace std;

double CelsiusToFahrenheit(double value)
{
    return value * 1.8 + 32;
}

int main()
{
    double value;
    cout << "Please enter a Celsius value: ";
    cin >> value;
    cout << value << " degrees Celsius is " << CelsiusToFahrenheit(value) << " degrees Fahrenheit" << endl;
    return 0;
}

在这里插入图片描述

//2.7 -6
#include <iostream>
using namespace std;

double LY2AU(const double ly)
{
    return ly * 63240;
}

int main()
{
    double ly;
    cout << "Enter the number of light years:";
    cin >> ly;
    cout << ly << " light years = " << LY2AU(ly) << " astronomical units" << endl;

    return 0;
}

在这里插入图片描述

//2.7 -7
#include <iostream>
using namespace std;

void show(const int hours, const int minutes)
{
    cout << "Time :  " << hours << ":" << minutes << endl;
}

int main()
{
    int hours;
    int minutes;
    cout << "Enter the number of hours:";
    cin >> hours;
    cout << "Enter the number of minutes:";
    cin >> minutes;
    show(hours, minutes);
    return 0;
}
  • 2
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值