C++ Prime Plus 第六版 第二章 開始學習C++ 編程練習 參考答案 詳細版

以下答案本人在linux vscode中均已親自測試編譯通過,完美運行.

2.1

#include<iostream>
using namespace std;
int main(void)
{
    char name[20]="某某某";
    char address[50]="山西省呂梁市孝義市";
    cout<<"姓名:"<<name<<endl<<"地址:"<<address<<endl;
}

2.2

#include<iostream>
using namespace std;
int main(void)
{
    double x;
    cout<<"請輸入一個距離x (碼):";
    cin>>x;
    x=x/220;
    cout<<"\n轉換單位(long):"<<x<<endl;
}

2.3

#include<iostream>
using namespace std;
void print1(void);
void print2(void);
void print3(void);
int main(void)
{
    cout<<"Three blind mice"<<endl;
    print1();
    print2();
    print3();
}
void print1(void)
{
    cout<<"Three blind mice"<<endl;
}
void print2(void)
{
    cout<<"See how they run"<<endl;
}
void print3(void)
{
    cout<<"See how they run"<<endl;
}

2.4

#include<iostream>
using namespace std;
int main(void)
{
    int age,yue;
    cout << "Enter your age:";
    cin >> age;
    yue = age * 12;
    cout << "\n月份有:" << yue <<endl;
}

2.5

#include<iostream>
using namespace std;
int main(void)
{
    int Cel,Fah;
    cout << "Please enter a Celsius value:";
    cin >> Cel;
    Fah = 1.8 * Cel + 32.0;
    cout << Cel <<" degree Celsius is " << Fah << " degree Fahrenheit"<<endl;
}

2.6

#include<iostream>
using namespace std;
int main(void)
{
    double number,ast;
    cout << "Enter the number of light years:";
    cin >> number;
    ast = 63240 * number;
    cout << number <<" light years = " << ast << " astronmical units"<<endl;
}

2.7

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

 

發佈了15 篇原創文章 · 獲贊 1 · 訪問量 649
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章