- 编程一个C++程序,它显示您的姓名和地址。
#include <iostream>
int stonetolb(int);
int main()
{
using namespace std;
cout << "zzz ";
cout << "闵行"<<endl;
return 0;
}
- 编写一个程序,要求用户输入一个以long为单位的距离,然后转换成码,(一long = 220码)
#include <iostream>
int distanctransform(int);
int main()
{
using namespace std;
int longs;
cout << "Enter the distance : ";
cin >> longs;
int yard = distanctransform(longs);
cout << longs << "longs = ";
cout << yard << "yard "<<endl;
return 0;
}
int distanctransform(int st)
{
return st*220;
}
![](https://i-blog.csdnimg.cn/blog_migrate/dc5606bde9483183dbd2a5fe153ef505.png)
- 编写一个C++程序,它使用3个用户定义的函数(包括main)。
Three blind mice
Three blind mice
See how they run
See how they run
其中一个函数要调用两次,该函数生成前两行,另一个函数也被调用两次,并生成剩余输出。
#include <iostream>
int send1();
int send2();
using namespace std;
int main()
{
send1();
send2();
return 0;
}
int send1()
{
cout << "Three blind mice" << endl;
cout << "Three blind mice" << endl;
return 0;
}
int send2()
{
cout << "See how they run" << endl;
cout << "See how they run" << endl;
return 0;
}
![](https://i-blog.csdnimg.cn/blog_migrate/ef6c46dc2af1fc84649fd79b6902d2dc.png)
- 编写一个程序,让用户输入年龄,显示该年龄包含几个月。
#include <iostream>
using namespace std;
int transforms(int);
int main()
{
int year;
cout << "Enter the your age:";
cin >> year ;
int month = transforms(year);
cout << "so your month = "<< month << endl;
return 0;
}
int transforms(int ss)
{
return ss*12;
}
![](https://i-blog.csdnimg.cn/blog_migrate/3790a58fee3ccf13ed9cb5548190b342.png)
- 编写一个程序,其中的main()调用一个用户自定义的函数(以摄氏度转华氏度),按以下格式用户输入摄氏温度值并显示结果。
please enter a Celsius value :20
20 degrees Cesius is 68 degrees Fahrenheit
华氏温度 = 1.8+摄氏度+32.0
#include <iostream>
using namespace std;
int transforms(int);
int main()
{
int year;
cout << "please enter a Celsius value :";
cin >> year ;
int month = transforms(year);
cout << year << " degrees Cesius is: "<< month << " degrees Fahrenheit" <<endl;
return 0;
}
int transforms(int ss)
{
return ss * 1.8+32;
}
![](https://i-blog.csdnimg.cn/blog_migrate/148d30127ca8988ddb91f05bc286a886.png)
- 编写一个程序,其main()调用一个用户定义的函数(以光年值为参数,并返回对应天文单位的值)。按下面的格式要求用户输入光年值,并显示结果。
Enter the number of light years:4.2
4.2 Enter the number of light years: = 26508 astronomical uints.
请使用double类型,转换公式:1光年 = 63240天文单位。
#include <iostream>
using namespace std;
int convert(double);
int main()
{
double year;
cout << "Enter the number of light years:";
cin >> year ;
double month = convert(year);
cout << year << " Enter the number of light years:"<< month << " astronomical uints " <<endl;
return 0;
}
int convert(double ss)
{
return ss * 63240;
}
![](https://i-blog.csdnimg.cn/blog_migrate/0e1ccfac33504ec9780b500a2424b3c7.png)
- 编写一个程序 ,要求用户输入小时和分钟数,在main()函数中,将这两个值传递给void函数,后者以下面格式显示这两个值。
Enter the number of hour:9
Enter the number of mintues:28
Time:9:28
#include <iostream>
using namespace std;
void display_time(int h,int m);
int main()
{
int hours;
int minutes;
cout << "Enter the number of hours:";
cin >> hours;
cout << "Enter the number of minutes:";
cin >> minutes;
display_time(hours,minutes);
return 0;
}
void display_time(int h, int m)
{
cout << "TIME:" << h<<":"<<m <<endl;
}
![](https://i-blog.csdnimg.cn/blog_migrate/9413f4fe9073c0429022a043daa006f0.png)