C++ Primer Plus 课后习题 第二章
2015-10-01 10:57
676 查看
//2-1 #include <iostream> using namespace std; int main(){ cout<<"Name:Kimiszc"<<endl; cout<<"Address: Hangzhou Dianzi Univers,Hangzhou,Zhejiang "; return 0; }
//2-2 #include <iostream> using namespace std; double change(double x); int main(){ double _long,_ma; cout<<"请输入以long为单位的值"<<endl ; cin>>_long; _ma=change(_long); cout<<"换算后的结果为"<<_ma<<"码"; } double change(double x){ double y; y=220*x; return y; }
//2-3 #include <iostream> using namespace std; void mFunction1(); void mFunction2(); int main(){ mFunction1(); mFunction2(); return 0; } void mFunction1(){ cout<<"Three blind mice"<<endl; cout<<"Three blind mice"<<endl; } void mFunction2(){ cout<<"See how they run"<<endl; cout<<"See how they run"<<endl; }
//2-4 #include <iostream> using namespace std; int main(){ int age; cout<<"请输入你的年龄"<<endl; cin>>age; cout<<"你的年龄是:"<<age<<"岁,包含"<<age*12<<"个月"<<endl; return 0; }
//2-5 #include <iostream> using namespace std; double change(double n); int main() { cout<<"please enter a Celsius valus:"; double n; cin>>n; cout<<n<<" degrees Celsius is "<<change(n)<<" degrees Fahrenheix"<<endl; return 0; } double change(double n) { return (n*1.8+32.0); }
//2-6 #include <iostream> using namespace std; double change(double y); int main(){ double num; cout<<"Enter the number of light years:"; cin>>num; cout<<num<<" light years = "<<change(num)<<"astronomical units"<<endl; } double change(double y) { return y*62340; }
//2-7 #include <iostream> using namespace std; void show(int hours,int minutes); int main(){ int hours,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; }