//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)
//Input hours and minutes,follow text;
#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;
}
未完待续。。。。。。。。