#include
using namespace std;
int main()
{
cout<<"姓名:Thomas"<<endl;
cout<<"地址:重庆市"<<endl;
return 0;
}
2.7.2
#include
using namespace std;
int main()
{
int dis_long;
int dis_yard;
cout<<"please input the int distance value as long:"<>dis_long;
dis_yard=dis_long*220;
cout<<"you has input the distance: "<<dis_long<<" long,"<<" equal to "<<dis_yard<<" yard."<<endl;
return 0;
}
2.7.3
#include
using namespace std;
void fun_1();
void fun_2();
int main()
{
fun_1();
fun_1();
fun_2();
fun_2();
return 0;
}
void fun_1()
{
cout<<"Three blind mice"<<endl;
}
void fun_2()
{
cout<<"See how they run"<<endl;
}
2.7.4
#include
using namespace std;
int main()
{
int age;
cout<<"Please input your age:"<>age; //据cin>>a 中a的变量类型读取数据,遇到结束符(Space、Tab、Enter)就结束
//cin.get();//cin.get() 与 cin.get(char ch)用于读取字符,他们的使用是相似的,即:ch=cin.get() 与 cin.get(ch)是等价的
cout<<"Your age contains "<<age*12<<" months.";
return 0;
}
2.7.5
#include
using namespace std;
double cel_to_Fah(double Celsius)
{
double Fahrenheit;
Fahrenheit=1.8*Celsius+32.0;
return Fahrenheit;
}
int main()
{
double temp_Celsius;
cout<<"Please enter a Celsius value:"<>temp_Celsius;
cout<<temp_Celsius<<" degrees Celsius is "<<cel_to_Fah(temp_Celsius)<<" degrees Fahrenheit"<<endl;
return 0;
}
2.7.6
#include
using namespace std;
double lig_to_ast(double light_years)
{
double astronomical;
astronomical=63240*light_years;
return astronomical;
}
int main()
{
double light_years;
cout<<"Please enter the number of light years:"<>light_years;
cout<<light_years<<" light_years = "<<lig_to_ast(light_years)<<" astronomical units"<<endl;
return 0;
}
2.7.7
#include
using namespace std;
void print_time(int hour, int min)
{
cout<<"Time "<<hour<<":"<<min<<endl;
}
int main()
{
int ent_hour;
int temp_hour;
int ent_min;
int temp_min;
cout<<"Please enter the number of hours:"<>temp_hour;
while (temp_hour>24||temp_hour<0)
{
cout<<"Wrong hours, please enter the number of hours again:"<>temp_hour;
}
ent_hour=temp_hour;
cout<<"Please enter the number of minutes:"<>temp_min;
while (temp_min>60||temp_min<0)
{
cout<<"Wrong minutes, please enter the number of minutes again:"<>temp_min;
}
ent_min=temp_min;
print_time(ent_hour, ent_min);
return 0;
}
HuJiaming11
原创文章 2获赞 2访问量 34
关注
私信
展开阅读全文