C++ Prime Plus 第六版 第二章 开始学习C++ 编程练习 参考答案 详细版

本篇博客提供了C++ Prime Plus第六版第二章的编程练习详细答案,所有代码已在Linux环境下使用VSCode进行测试,确保编译通过并能完美运行,包括2.1至2.7的所有练习。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

以下答案本人在linux vscode中均已亲自测试编译通过,完美运行.

2.1

#include<iostream>
using namespace std;
int main(void)
{
    char name[20]="某某某";
    char address[50]="山西省吕梁市孝义市";
    cout<<"姓名:"<<name<<endl<<"地址:"<<address<<endl;
}

2.2

#include<iostream>
using namespace std;
int main(void)
{
    double x;
    cout<<"请输入一个距离x (码):";
    cin>>x;
    x=x/220;
    cout<<"\n转换单位(long):"<<x<<endl;
}

2.3

#include<iostream>
using namespace std;
void print1(void);
void print2(void);
void print3(void);
int main(void)
{
    cout<<"Three blind mice"<<endl;
    print1();
    print2();
    print3();
}
void print1(void)
{
    cout<<"Three blind mice"<<endl;
}
void print2(void)
{
    cout<<"See how they run"<<endl;
}
void print3(void)
{
    cout<<"See how they run"<<endl;
}

2.4

#include<iostream>
using namespace std;
int main(void)
{
    int age,yue;
    cout << "Enter your age:";
    cin >> age;
    yue = age * 12;
    cout << "\n月份有:" << yue <<endl;
}

2.5

#include<iostream>
using namespace std;
int main(void)
{
    int Cel,Fah;
    cout << "Please enter a Celsius value:";
    cin >> Cel;
    Fah = 1.8 * Cel + 32.0;
    cout << Cel <<" degree Celsius is " << Fah << " degree Fahrenheit"<<endl;
}

2.6

#include<iostream>
using namespace std;
int main(void)
{
    double number,ast;
    cout << "Enter the number of light years:";
    cin >> number;
    ast = 63240 * number;
    cout << number <<" light years = " << ast << " astronmical units"<<endl;
}

2.7

#include<iostream>
using namespace std;
int main(void)
{
    int hour,minute;
    cout << "Enter the number of hours:";
    cin >> hour;
    cout << "Enter the number of minutes:";
    cin >> minute;
    cout << "time:" << hour << ":" << minute << endl;
}

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值