c++primer plus 第六版 第2章 编程练习之路

94人阅读 评论(0)

//c++ Primer Plus（习题2.2)

//input 以 long为单位的距离，将它转换成码.（1 long =220码）
#include<iostream>

const float Yard = 220;
int main()
{
using namespace std;
cout<< "Input distance by long:";
float result;
cin >> result;
cout << result << "long change to Yard is " << result*Yard << endl;
return 0;
}

//c++ Primer Plus（习题2.3)

//use function twice,input some sentence!
#include<iostream>
void printf1(...); //不带参数列表的要用...
void printf2(...);
using namespace std;
int main(void)
{
printf1();
printf1();
printf2();
printf2();
return 0;
}
void printf1(...)
{
cout << "Three blind mice\n";
}
void printf2(...)
{
cout << "See how they run\n";
}

//c++ Primer Plus（习题2.4)

//Input ages,Output how many mouths!
#include<iostream>
const int Years = 12;
int main(void)
{
using namespace std;
cout << "Enter your age: ";
int ages;
cin >> ages;
cout << "You live " << ages*Years << " months!\n"<<"Bye!";
return 0;
}
//c++ Primer Plus（习题2.5)

//Input Celsius dgree tranform to Fahrenheit
#include<iostream>
using namespace std;
double Celsius_Fahrenheit(double degree);
int main(void)
{
cout << "Please enter a Celsious value: ";
double value,result;
cin >> value;
result=Celsius_Fahrenheit(value);
cout << value << " degree Celsius is " << result << " degrees Fahrenheit.\n";
return 0;
}
double Celsius_Fahrenheit(double degree)
{
return degree*1.8 + 32.0;
}

//c++ Primer Plus（习题2.6)

//以光年值为参数，返回对应天文单位的值
#include<iostream>
using namespace std;
double light_astronomical(double years);
int main(void)
{
cout << "Enter the number of light years: ";
double lightyears, result;
cin >> lightyears;
result =light_astronomical(lightyears);
cout << lightyears << " light years= " << result << " astronomical units.\n";
return 0;
}
double light_astronomical(double years)
{
return years*63240; //1光年=63240天文单位
}

//c++ Primer Plus（习题2.7)

#include<iostream>
using namespace std;
void hours_minutes
(
int hours,int minutes);
int main(void)
{
cout << "Enter the number of hours: ";
int Hours, Minutes;
cin >> Hours;
cout << "Enter the number of minute: ";
cin >> Minutes;
hours_minutes(Hours,Minutes);
return 0;
}
void hours_minutes(int hours,int minutes)
{
cout << "Time: " << hours << ":" << minutes<<endl;
}

0
0

* 以上用户言论只代表其个人观点，不代表CSDN网站的观点或立场
个人资料
• 访问：2806次
• 积分：200
• 等级：
• 排名：千里之外
• 原创：18篇
• 转载：0篇
• 译文：0篇
• 评论：1条
文章分类
文章存档
阅读排行