2.7编程练习
开始进行C++学习,希望能坚持下来,完整的过完一遍C++Primer Plus(第五版) 一遍。同时开始写属于自己的技术博客,+.+,记录自己再技术路上的成长,也希望我的心得体会能帮助到更多的人,找到志同道合的小伙伴。
另外,题目都没有写全,书本上有,这里只提了一个大概。懒,囧...
第一题:显示姓名地址。
include<iostream>
int main(void)
{
using namespace std;
cout<<"姓名:杰尼西斯。\n";
cout<<"地址:陕西,西安,雁塔区。\n";
//cin.get();
cin.get();
return 0;
}
第二题:输入距离,单位浪,转换为码。
#include<iostream>
int main(void)
{
using namespace std;
int a;
cout << "请输入浪数:";
cin >> a;
cout << a<<"浪="<<a*220<<"码\n\n";
cin.get();
return 0;
}
第三题:编写程序,包含三个用户自定义函数,满足题目规定的输出。
#include<iostream>
#include<string>
using namespace std;
string str1(void);
void str2(void);
int main(void)
{
using namespace std;
cout << str1() <<endl;
cout << str1() << endl;
str2();
cout << endl;
str2();
cin.get();
return 0;
}
string str1(void)
{
using namespace std;
string a;
a="Three blind mice";
return a;
}
void str2(void)
{
cout << "See how they run";
}
第四题:编写程序,调用一个自定义函数,进行温度转换。
#include<iostream>
double trans(double);
int main(void)
{
using namespace std;
double a;
cout << "Please enter a Celsius value:";
cin >> a;
cout << a << " degrees Celsius is " << trans(a) << " degrees Fahrenheit.\n";
getchar();
getchar();
return 0;
}
double trans(double a)
{
return 1.8*a + 32.0;
}
第五题:编写程序,调用一个自定义函数,进行光年转换。
#include<iostream>
double trans(double);
int main(void)
{
using namespace std;
double a;
cout << "Enter the number of liget years:";
cin >> a;
cout << a << " liget years = " << trans(a) << " astronomical units.\n";
cin.get();
getchar();
return 0;
}
double trans(double a)
{
return a*63240;
}
第六题:编写程序,让用户输入时间,调用一个自定义void函数,显示时间。
#include<iostream>
void trans(double a, double b);
int main(void)
{
using namespace std;
double a,b;
cout << "Enter the number of hours:";
cin >> a;
cout << "Enter the number of minutes:";
cin >> b;
trans(a,b);
cin.get();
getchar();
return 0;
}
void trans(double a, double b)
{
using namespace std;
cout<<"Time: "<<a<<":"<<b<<endl;
}
第二章编程练习结束,都是基础内容。.