版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/qq_28467367/article/details/87860504
// 2.7编程练习
#include <iostream>
using namespace std;
//1.
int main1()
{
cout << "My name is HX, LIve in WuHan"<<endl;
return 0;
}
//2.
double longtoma(double);
int main2()
{
double lo;
cout <<"Enter the long: ";
cin >> lo;
double m = longtoma(lo);
cout << lo << " long="<<m <<" ma" << endl;
return 0;
}
double longtoma(double l)
{
return 220 * l;
}
//3.
void mice();
void see();
int main3()
{
mice();
mice();
see();
see();
return 0;
}
void mice()
{
cout << "Three blind mice" << endl;
}
void see()
{
cout << "See how they run" << endl;
}
//4.
int main4()
{
int age;
cout << "Enter your age: ";
cin >> age;
int month = 12 * age;
cout <<age<< " years is " << month << " months. " << endl;
return 0;
}
//5.
double C2F(double);
int main5()
{
double Celsius = 0.0;
cout << "Please enter a Celsius value : ";
cin >> Celsius;
double Fahrenheit = C2F(Celsius);
cout << Celsius << " degrees Celsius is " << Fahrenheit << " degrees Fahrenheit." << endl;
return 0;
}
double C2F(double t)
{
return (1.8 * t + 32.0);
}
//6.
double convert(double);
int main6()
{
double light_year;
cout << "Enter the number of light years: ";
cin >> light_year;
double astro_units = convert(light_year);
cout << light_year << " light years = " << astro_units << " astronomical units . " << endl;
return 0;
}
double convert(double t)
{
return 63240* t;
}
//7.
void time(int h, int m);
int main()
{
int hour, minutes;
cout << "Enter the number of hours: ";
cin >> hour;
cout << "Enter the number of minutes: ";
cin >> minutes;
time(hour,minutes);
return 0;
}
void time(int h,int m)
{
cout << "Time: " << h << ":" << m << endl;
}