如题,从Python的语言转入C ++语言学习,记录下自己的习题练习!
每个题目后,附上调试结果,大家可以直接复制代码自行编译!
纯参考,希望大家提出批评!
#include "pch.h"
#include
using namespace std;
int main()
{
cout << "my name is huangchao, and i live in xi'an! " << endl;
return 0;
}
#include "pch.h"
#include
//将long转换成ma,1long=30ma
using namespace std;
float conv(float);
int main()
{
float changdu;
cout << "please enter the changdu: " << endl;
cin >> changdu;
float ma = conv(changdu);
cout << changdu << " chang is ";
cout << ma << " ma " << endl;
return 0;
}
float conv(float unit1)
{
return 30 * unit1;
}
#include "pch.h"
#include
void fuc_1();
void fuc_2();
using namespace std;
int main()
{
fuc_1();
fuc_1();
fuc_2();
fuc_2();
return 0;
}
void fuc_1()
{
cout << "Three blind mice " << endl;
}
void fuc_2()
{
cout << "See how they run " << endl;
}
#include "pch.h"
#include
int fuc_1(int);
using namespace std;
int main()
{
int age;
cout << "Enter your age: ";
cin >> age;
int month = fuc_1(age);
cout << "Your are " << age << "years; ";
cout << "and equal to " << month << " month! " << endl;
return 0;
}
int fuc_1(int n)
{
int months = n * 12;
return months;
}
#include "pch.h"
#include
float fuc_1(float);
using namespace std;
int main()
{
int cels;
cout << "Please enter a Celsius value: ";
cin >> cels;
int fahr = fuc_1(cels);
cout << cels << " degrees celsius is " << fahr << " degrees Fahrenheit" << endl;
return 0;
}
float fuc_1(float n)
{
int fahr = n * 1.8+32.0;
return fahr;
}
#include "pch.h"
#include
float fuc_1(float);
using namespace std;
int main()
{
float guangnian;
cout << "Enter a number of light years: ";
cin >> guangnian;
int tianwen = fuc_1(guangnian);
cout << guangnian << " light years = " << tianwen << " astronomical units." << endl;
return 0;
}
float fuc_1(float n)
{
int unit = n * 63240;
return unit;
}
#include "pch.h"
#include
void fuc_1(int,int);
using namespace std;
int main()
{
cout << "Enter the number of hours: ";
int time;
cin >> time;
cout << "Enter the number of minutes: ";
int minutes;
cin >> minutes;
fuc_1(time, minutes);
return 0;
}
void fuc_1(int m, int n)
{
cout << "Time: " << m <<":"<< n ;
}