C++ Primer第二章课后编程题

来源:互联网 发布:淘宝店卖什么好 编辑:程序博客网 时间:2024/05/14 02:07


1、
代码:
#include<iostream>int main(){    using namespace std;    cout << "My name : guugle" << endl;    cout << "My address : China Shenzhen" << endl;    return 0;}
运行结果:


2、
代码:
#include<iostream>int main(){    using namespace std;    cout << "请输入尺寸:";    int lang;    cin >> lang;    lang = 220 * lang;    cout << "转换成码为:" << lang <<endl;    return 0;}
运行结果:

3、
代码:
#include<iostream>using namespace std;void functionA();void functionB();int main(){    functionA();    functionA();    functionB();    functionB();    return 0;}void functionA(){   cout << "Three blind misc";   cout << endl;}void functionB(){   cout << "See how they Run";   cout << endl;}
运行结果:


4、
代码:
#include<iostream>using namespace std;void hua(int);int main(){    cout << "Please enter a Celsius value:";    int wendu;    cin >> wendu;    hua(wendu);    return 0;}void hua(int wendu){    double huadu = 1.8 * wendu + 32.0;    cout << wendu << "degrees Velsius is " << huadu << "degrees Fahrenheit" << endl;}
运行结果:


5、
代码:
#include<iostream>using namespace std;double lightyear(double);int main(){    cout << "Enter the number of light years:";    double years;    cin >> years;    double lyear = lightyear(years);    cout << years <<"light years = " << lyear << "astronomical units.";    cout << endl;    return 0;}double lightyear(double years){    return years * 63240;}
运行结果:


6、
代码:
#include<iostream>using namespace std;void showTime(int, int);int main(){    cout << "请输入小时:";    int hours;    cin >> hours;    cout << "请输入分钟数:";    int minutes;    cin >> minutes;    showTime(hours, minutes);    return 0;}void showTime(int hours, int minutes){    cout << "Time:" << hours <<":" << minutes << endl;}
运行结果:


0 0