C++ Primer Plus 第6版 编程题参考答案(1)

来源:互联网 发布:手机电影网php源码 编辑:程序博客网 时间:2024/05/19 19:12

事先声明,博客中的全部程序由博主自行编写,全部在Code Blocks 16.01下编译通过,部分程序使用了C++11标准。绝非标准答案,仅供参考!


第二章

2.1

#include<iostream>int main(){    using namespace std;    cout<<"K";    cout<<"\n";    cout<<"Address? Fuck you!!!";    return 0;}


2.2

#include<iostream>int transforming(int);int main(){    using namespace std;    int longlong;    cout<<"Please enter long:\n";    cin >> longlong;    int yard=transforming(longlong);    cout<<"The yard is "<<yard;    return 0;}int transforming(int longlong){    int yard;    yard=220*longlong;    return yard;}

2.3

#include<iostream>void three();void see();int main(){    three();    three();    see();    see();    return 0;}void three(){    using namespace std;    cout<<"Three blind mice\n";}void see(){    using namespace std;    cout<<"See how they run\n";}

2.4

#include<iostream>int enter();int month(int);int main(){    using namespace std;    int age=enter();    int month1=month(age);    cout<<"Month is "<<month1;}int enter(){    using namespace std;    cout<<"Enter your age:";    int age1;    cin>>age1;    cout<<"\n";    return age1;}int month(int age){    int month;    month=age*12;    return month;}

2.5

#include<iostream>int transforming(int);int main(){    using namespace std;    cout<<"Please enter a Celsius value: ";    int celsius;    cin>>celsius;    int fah;    fah=transforming(celsius);    cout<<celsius<<" degress Celsius is "<<fah<<" degress Fahrenheit";    return 0;}int transforming(int celsius){    int fah=1.8*celsius+32;    return fah;}

2.6

#include<iostream>double transforming(double);int main(){    using namespace std;    cout<<"Enter the number of light years: ";    double lightyears;    cin>>lightyears;    double unit;    unit=transforming(lightyears);    cout<<lightyears<<" light years = "<<unit<<" astronomical units";}double transforming(double lightyears){    double unit=63240*lightyears;    return unit;}


2.7

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




阅读全文
0 0
原创粉丝点击