C++ primer plus编程练习自制答案-第二章

所有代码均为自用练习回答,有误可评论指出,感谢

1.显示您的姓名与地址

#include<iostream>
using namespace std;
int main()
{
    cout<<"name:heqi"<<endl;
    cout<<"address:3663 north Zhongshan Avenue"<<endl;
    return 0;
} 

2.

#include<iostream>
using namespace std;
int main()
{
    cout<<"Please input a distance with a unit of long"<<endl;
    int dis=0;
    cin >> dis;
    cout<<"The distance is "<<dis*220<<" yard"<<endl;
    return 0;
} 

3.

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

4.

#include<iostream>
using namespace std;

int main()
{
    cout<<"Enter your age: ";
    int age=0;
    cin>>age;
    cout<<"You have lived for "<<age*12<<" months."<<endl;
    return 0;
} 

5.

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

(写了一个超级怪的函数调用……)

6.

#include<iostream>
using namespace std;
void convert(double ly)
{
    double au=ly*63240;
    cout<<ly<<" light years = ";
    printf("%f",au);
    cout<<" astronomical units."<<endl;
}
int main()
{
    cout<<"Enter the number of light years: ";
    double ly;
    cin>>ly;
    convert(ly);
    return 0;
} 

(不知道为什么用cout输出au的时候,不是浮点数/(ㄒoㄒ)/~~)

7.

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

未完待续……

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值