C++ Primer plus第六版编程答案第二章

本文展示了多个C++编程示例,涉及基本输入输出、变量使用、函数定义、数值转换(如温度和距离单位)、以及时间表示,提供初学者入门学习参考。
摘要由CSDN通过智能技术生成

1.cpp

#include<iostream>
using namespace std;
int main()
{
    cout<<"zjl "<<"anhui";
    return 0;
}

2.cpp

#include<iostream>
using namespace std;
int main()
{
    long dis;
    cout << "请输入一个距离:" << endl;
    cin >> dis;
    cout << dis*220 << "码" <<endl;
    return 0;
}

3.cpp

#include<iostream>
using namespace std;
void show_1();
void show_2();

int main()
{
    show_1();
    show_1();
    show_2();
    show_2();
    return 0;
}

void show_1()
{
    cout<<"Three blind mice"<<endl;
}
void show_2()
{
    cout<<"See how they tun"<<endl;
}

4.cpp

#include<iostream>
using namespace std;
int main()
{
    int age;
    cout << "Enter your age:" <<endl;
    cin>> age;
    cout<< age*12 <<"个月"<<endl;
    return 0;
}

5.cpp

#include<iostream>
using namespace std;
double tem(double t);

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

double tem(double t)
{
    return 1.8*t+32.0;
}

6.cpp

#include<iostream>
using namespace std;
double tran_dis(double t);
int main()
{
    double year;
    cout<<"Enter the number of light years:";
    cin>> year;
    cout<< year <<" light years = "<<tran_dis(year)<<" astronomical units."<<endl;
    return 0;
}

double tran_dis(double t)
{
    return t*63240;
}

7.cpp

#include<iostream>
using namespace std;
void show(int hours,int minutes);

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;
}

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

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值