1.编写c++程序,它显示你的姓名和地址
#include <iostream>
using namespace std;
int main()
{
cout << "liu bin" << endl;
cout << "guang zhou" << endl;
system("pause");
return 0;
}
2.编写一个c++程序,他要求用户输入一个以long为单位的距离,然后将它转化为码(一码等于220long)
#include <iostream>
using namespace std;
int onelong(int n)
{
return n * 220;
}
int main()
{
int k;
cout << "please enter your number" ;
cin >> k;
int resurt_ = onelong(k);
system("pause");
return 0;
}
3.编写一个c++程序。他使用3个用户定义的函数,并生成下面输出。
three blind mice
three blind mice
see how they run
see how they run
#include <iostream>
using namespace std;
void one()
{
cout << "three blind mice" << endl;
}
void two()
{
cout << "see how they run" << endl;
}
int main()
{
one();
one();
two();
two();
system("pause");
return 0;
}
4.编写一个程序,让用户输入年龄,然后显示改年龄包含多少个月。
#include <iostream>
using namespace std;
int year_mouth(int year)
{
return year * 12;
}
int main()
{
int year;
cout << "please enter your year" ;
cin >> year;
cout << "your mouth" << year_mouth(year) << endl;
system("pause");
return 0;
}
5.编写一个程序,其中main(调用一个用户定义的函数)(以摄氏度为参数,并返回华氏温度)
#include <iostream>
using namespace std;
double temperature(double k)
{
return 1.8*k + 32.0;
}
int main()
{
double k;
cout << "please enter your number ";
cin >> k;
cout << "Celsius to Fahrenheit is" << temperature(k);
system("pause");
return 0;
}
6.编写一个程序,其main()调用一个用户定义的函数(以光年值为参数,并返回对应的天文单位的值)。
#include <iostream>
using namespace std;
double year_long(double k)
{
return k * 63240;
}
int main()
{
double j;
cout << "please enter your number";
cin >> j;
cout << j << "linght years =" << year_long(j) << "astronomical unite" << endl;
system("pause");
return 0;
}
7.编写一个程序,要求用户输入小时数和分钟数。在main()函数中,将这2个值传递给一个void函数。
#include <iostream>
using namespace std;
void show_this(int hour,int fen)
{
cout << "Time:" << hour << ":" << fen << endl;
}
int main()
{
int hour, fen;
cout << "enter the number of hour :";
cin >> hour;
cout << "enter the number of minutes :";
cin >> fen;
show_this(hour, fen);
system("pause");
return 0;
}