所有代码均为自用练习回答,有误可评论指出,感谢
1.显示您的姓名与地址
#include<iostream>
using namespace std;
int main()
{
cout<<"name:heqi"<<endl;
cout<<"address:3663 north Zhongshan Avenue"<<endl;
return 0;
}
2.
#include<iostream>
using namespace std;
int main()
{
cout<<"Please input a distance with a unit of long"<<endl;
int dis=0;
cin >> dis;
cout<<"The distance is "<<dis*220<<" yard"<<endl;
return 0;
}
3.
#include<iostream>
using namespace std;
void output1()
{
cout<<"Three blind mice"<<endl;
}
void output2()
{
cout<<"See how they run"<<endl;
}
int main()
{
output1();
output1();
output2();
output2();
return 0;
}
4.
#include<iostream>
using namespace std;
int main()
{
cout<<"Enter your age: ";
int age=0;
cin>>age;
cout<<"You have lived for "<<age*12<<" months."<<endl;
return 0;
}
5.
#include<iostream>
using namespace std;
void convert(float tempterature)
{
cout<<tempterature<<" degrees Celsius is "<<(tempterature*1.8+32.0)<<" degrees Fahrenheit."<<endl;
}
int main()
{
cout<<"Please enter a Celsius value: ";
float tempterature;
cin>>tempterature;
convert(tempterature);
return 0;
}
(写了一个超级怪的函数调用……)
6.
#include<iostream>
using namespace std;
void convert(double ly)
{
double au=ly*63240;
cout<<ly<<" light years = ";
printf("%f",au);
cout<<" astronomical units."<<endl;
}
int main()
{
cout<<"Enter the number of light years: ";
double ly;
cin>>ly;
convert(ly);
return 0;
}
(不知道为什么用cout输出au的时候,不是浮点数/(ㄒoㄒ)/~~)
7.
#include<iostream>
using namespace std;
void integrate(int hour, int minute)
{
cout<<"Time: "<<hour<<":"<<minute<<endl;
}
int main()
{
cout<<"Enter the number of hours: ";
int hour;
cin>>hour;
cout<<"Enter the number of minutes: ";
int minute;
cin>>minute;
integrate(hour,minute);
return 0;
}
未完待续……