1.名前と住所を表示するためのC ++プログラムを書きます
#include<iostream>
int main(void)
{
using namespace std;
cout << "name";
cout << endl;
cout << "address";
cout << endl;
return 0;
}
2. C ++プログラムを書いて、それは長い距離単位を入力するようにユーザに要求し、コード(220でロングコード)に変換して
#include<iostream>
int main(void)
{
using namespace std;
int distance1,distance2;
cout << "请输入以long为单位的距离" << endl;
cin >> distance1;
distance2 = 220 * distance1;
cout << distance1 << "long=" << distance2 << "码" << endl;
return 0;
}
(ミアン()を含む)は、3つのユーザ定義関数を使用し、次の出力を生成するC ++プログラムの調製:
ブラインドMICEスリー
スリーブラインドMICE
を参照してくださいどのように彼らRUN
は、実行方法を参照してください
関数が二度呼ばれるように前記第一、ファンクション・ジェネレータの2行、また別の関数が2回呼び出されを、残りの出力を生成します。
#include<iostream>
using namespace std;
void mice(void);
void run(void);
int main(void)
{
mice();
mice();
run();
run();
return 0;
}
void mice(void)
{
cout << "Three blind mice" << endl;
}
void run(void)
{
cout << "See how they run" << endl;
}
4.入力するユーザーが自分の年齢を可能にして、年齢の月の数が含まれている表示するプログラムを書きます。
#include<iostream>
int main()
{
using namespace std;
int year,month;
cout << "Enter your age:";
cin >> year;
month=12*year;
cout << "该年龄包含" << month << "个月";
return 0;
}
(ここで、メインプログラムの作成)は、ユーザ定義関数を呼び出し(基準値として摂氏で、対応する値華氏を返します)。
第四の質問に似ていますが、知識の機能を使用する必要があります。
#include<iostream>
float change(float celsius);
int main()
{
using namespace std;
float celsius,fahrenheit;
cout << "Please enter a Celsius value: ";
cin >> celsius;
fahrenheit = change(celsius);
cout << celsius << " degrees Celsius is " << fahrenheit <<" degrees Fahrenheit." << endl;
return 0;
}
float change(float celsius)
{
float fahrenheit;
fahrenheit = 1.8 * celsius + 32.0;
return fahrenheit;
}
6)(主に(対応する値AU光年値戻る)、ユーザ定義関数を呼び出し、そのプログラムを開発
第五の質問は似ていますが、より大きなデータは、ストアに二重の変数を使用しています。
#include<iostream>
double change(double years);
int main()
{
using namespace std;
double years,units;
cout << "Enter the number of light years: ";
cin >> years;
units = change(years);
cout << years << " light years = " << units <<" astronomical units." << endl;
return 0;
}
double change(double years)
{
double units;
units = 63240 * years;
return units;
}
7.プログラムの作成は、時間と分の数を入力する必要があります。main()関数では、これら2つの値は、2つの値は、次の形態をとる示すボイド関数に渡されます。
#include<iostream>
using namespace std;
void print(int hour,int minute);
int main()
{
int hour,minute;
cout << "Enter the number of hours: ";
cin >> hour;
cout << "Enter the number of minutes: ";
cin >> minute;
print(hour,minute);
return 0;
}
void print(int hour,int minute)
{
cout <<"Time: " << hour << ":" << minute << endl;
}