您的位置:首页 > 编程语言 > C语言/C++

C++ Primer Plus(第六版) 第二章 编程练习

2018-09-01 00:48 260 查看
版权声明:本文为博主原创文章,遵循 CC 4.0 by-sa 版权协议,转载请附上原文出处链接和本声明。 本文链接:https://blog.csdn.net/qq_42212893/article/details/82263602

编程环境:Visual Studio 2017

1:

[code]//practice 1
#include<iostream>
using namespace std;

int main()
{
cout << "Melody" << endl;
cout << "Chengdu, China" << endl;
//cin.get();
return 0;
}

2: 

[code]//practice 2
#include<iostream>
using namespace std;

int main()
{
int ilong = 0;
int iyard = 0;
cout << "Please input a distance in long" << endl;
cin >> ilong;
iyard = 220 * ilong;
cout << "The distance in yards is " << iyard << endl;
//cin.get();
//cin.get();
return 0;
}

3: 

[code]//practice 3
#include<iostream>
using namespace std;

void fun1()
{
cout << "Three blind mice" << endl;
}

void fun2()
{
cout << "See how they run" << endl;
}

int main()
{
fun1();
fun1();
fun2();
fun2();
//cin.get();
return 0;
}

4: 

[code]//practice 4
#include<iostream>
using namespace std;

int main()
{
int iyear = 0;
int imonth = 0;
cout << "Enter your age:";
cin >> iyear;
imonth = iyear * 12;
cout << iyear << " years contain " << imonth << " months" << endl;
//cin.get();
//cin.get();
return 0;
}

5: 

[code]//practice 5
#include<iostream>
using namespace std;

double fun(double celsius)
{
return (1.8*celsius + 32.0);
}
int main()
{
double celsius = 0.0;
double fahrenheit = 0.0;
cout << "Please enter a Celsius value:";
cin >> celsius;
fahrenheit = fun(celsius);
cout << celsius << " degress Celsius is " << fahrenheit << " degress Fahrenheit." << endl;
//cin.get();
//cin.get();
return 0;
}

6: 

[code]//practice 6
#include<iostream>
using namespace std;

double fun(double LightYears)
{
return (63240 * LightYears);
}
int main()
{
double LightYears = 0.0;
double AstronomicalUnit = 0.0;
cout << "Enter the number of light years:";
cin >> LightYears;
AstronomicalUnit = fun(LightYears);
cout << LightYears << " light years = " << AstronomicalUnit << " astronomical units." << endl;
cin.get();
cin.get();
return 0;
}

7:

[code]//practice 7
#include<iostream>
using namespace std;

void ShowTime(int hour, int minute)
{
cout << "Time:" << hour << ":" << minute << endl;
}

int main()
{
int hour = 0;
int minute = 0;
cout << "Enter the number of hours:";
cin >> hour;
cout << "Enter the number of minutes:";
cin >> minute;
ShowTime(hour, minute);
//cin.get();
//cin.get();
return 0;
}

才疏学浅,如有错误或者改进的建议还请大牛多多指出。

继续学习,慢慢更新。

 

内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: