第一題:顯示姓名地址。
include<iostream>int main(void){ using namespace std; cout<<"姓名:杰尼西斯。/n"; cout<<"地址:陜西,西安,雁塔區。/n"; //cin.get(); cin.get(); return 0;}第二題:輸入距離,單位浪,轉換為碼。
#include<iostream>int main(void){ using namespace std; int a; cout << "請輸入浪數:"; cin >> a; cout << a<<"浪="<<a*220<<"碼/n/n"; cin.get(); return 0;}第三題:編寫程序,包含三個用戶自定義函數,滿足題目規定的輸出。
#include<iostream>#include<string>using namespace std;string str1(void);void str2(void);int main(void){ using namespace std; cout << str1() <<endl; cout << str1() << endl; str2(); cout << endl; str2(); cin.get(); return 0;}string str1(void){ using namespace std; string a; a="Three blind mice"; return a;}void str2(void){ cout << "See how they run";}第四題:編寫程序,調用一個自定義函數,進行溫度轉換。
#include<iostream>double trans(double);int main(void){ using namespace std; double a; cout << "Please enter a Celsius value:"; cin >> a; cout << a << " degrees Celsius is " << trans(a) << " degrees Fahrenheit./n"; getchar(); getchar(); return 0;}double trans(double a){ return 1.8*a + 32.0;}第五題:編寫程序,調用一個自定義函數,進行光年轉換。
#include<iostream>double trans(double);int main(void){ using namespace std; double a; cout << "Enter the number of liget years:"; cin >> a; cout << a << " liget years = " << trans(a) << " astronomical units./n"; cin.get(); getchar(); return 0;}double trans(double a){ return a*63240;}第六題:編寫程序,讓用戶輸入時間,調用一個自定義void函數,顯示時間。
#include<iostream>void trans(double a, double b);int main(void){ using namespace std; double a,b; cout << "Enter the number of hours:"; cin >> a; cout << "Enter the number of minutes:"; cin >> b; trans(a,b); cin.get(); getchar(); return 0;}void trans(double a, double b){ using namespace std; cout<<"Time: "<<a<<":"<<b<<endl;}第二章編程練習結束,都是基礎內容。^.^
新聞熱點
疑難解答
圖片精選