从今天开始每天做一些C++里面的题。
1.编写一个C++程序,它显示您的名称和地址
#include <iostream>
using namespace std;
int main()
{
string name,addr;
cout<<"请输入您的名字:"<<endl;
cin>>name;
cout<<"请输入您的地址:"<<endl;
cin>>addr;
return 0;
}
运行结果:
2.编写一个C++程序,要求用户输入一个以long为单位的距离,然后将它转换为码 (一long等于220码)
#include <iostream>
using namespace std;
int main()
{
double distance,ma;
cout<<"请输入一个以long为单位的距离:"<<endl;
cin>>distance;
ma = distance * 220;
cout<<distance<<"="<<ma<<"码"<<endl;
return 0;
}
运行结果:
3. 编写一个程序,使用3个用户自定义的函数,生成所需输出
#include <iostream>
using namespace std;
void display1()
{
cout<<"Three blind mice"<<endl;
}
void display2()
{
cout<<"See how they run"<<endl;
}
int main()
{
display1();
display1();
display2();
display2();
}
运行结果:
4. 编写一个程序,输入年龄可以显示该年龄包含几个月
#include <iostream>
using namespace std;
int main()
{
int age;
cout<<"Enter your age:"<<endl;
cin>>age;
cout<<"total months"<<12 * age <<endl;
return 0;
}
运行结果:
5.编写一个程序按照书中结果显示
#include <iostream>
using namespace std;
double tempera(double a)
{
return a * 1.8 + 32.0;
}
int main()
{
double tem1;
cout<<"Please enter a Celsius value:";
cin>>tem1;
cout<<tem1<<" degrees Celsius is "<<tempera(tem1)<<" degrees Fahrenheit."<<endl;
return 0;
}
运行结果:
6.编写一个程序按照书中格式实现其功能,并显示书中输出
#include <iostream>
using namespace std;
double astro(double a)
{
return a * 63240;
}
int main()
{
double years;
cout<<"Enter the number of light years:";
cin>>years;
cout<<years<<" light years"<<" = "<<astro(years)<<" astronomical units."<<endl;
return 0;
}
运行结果:
7.编写一个程序,要求用户输入小时数和分钟数
#include <iostream>
using namespace std;
void display(double a,double b)
{
cout<<"Time:"<<a<<":"<<b<<endl;
}
int main()
{
double hours,minutes;
cout<<"Enter the number of hours:";
cin>>hours;
cout<<"Enter the number of minutes:";
cin>>minutes;
display(hours,minutes);
return 0;
}
运行结果:
吐槽:实在是太简单了…就当为漫长c++打基础吧…