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

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

//2.7 -1
#include 
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 
using namespace std;

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

    return 0;
}

//2.7 -3
#include 
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 
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 
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 
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 
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;
}

欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/langs/2889411.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-09-14
下一篇 2022-09-14

发表评论

登录后才能评论

评论列表(0条)

保存