3.7练习题

C++编程练习题精选
本文精选了多个C++编程练习题目,涵盖了单位换算、时间转换、百分比计算等实用场景,通过这些练习,读者可以加深对C++基本语法和数据类型的理解。
//3.6编程练习c
#include<iostream>

//1

/*
const int inch = 12;
int main() {
	using namespace std;
	int feet;
	cout << "Please enter your height:____\b\b\b\b" ;
	cin >> feet;
	cout << "\nIt's " << feet << " feet,same as " << feet * inch << " inches.";
	return 0;
}
*/

//2

/*
const int FtI = 12;
const double ItM = 0.0254;
const double PtK = 1 / 2.2;
int main() {
	using namespace std;
	int feet, inch, pound;
	cout << "Please enter your height and weight" << endl;
	cin >> feet;
	cin >> inch;
	cin >> pound;

	int height = feet * FtI + inch;
	cout << "Your height is " << height << " inches,same as " << height*ItM << " miles." << endl;
	cout << "Your weight is " << pound * PtK << " kg." << endl;
	cout << "Your BMX is " << (pound * PtK) /(height*ItM* height*ItM);
	return 0;
}
*/

//3
/*
const double DtM = 60;
const double MtS = 60;
int main() {
	using namespace std;
	double degree, minute, second;
	cout << "Enter a latitude in degrees,minutes, and seconds:" << endl;
	cout << "First, enter the degrees: ";
	cin >> degree;
	cout << "Next, enter the minutes of arc: ";
	cin >> minute;
	cout << "Finally, enter the seconds of arc: ";
	cin >> second;
	double dtm = minute / DtM;
	double mts = second / MtS;
	double latitude = degree + dtm + mts;
	cout << degree << " degrees, " << minute << " minutes, " << second << " seconds = " << latitude << " degrees";

	return 0;
}
*/

//4
/*
const int Day = 24 * 60 * 60;
const int Hour = 60*60;
const int Minute = 60;
int main() {
	using namespace std;
	long long int second;
	cout << "Enter the number of seconds: ";
	cin >> second;
	int days = second / Day;
	int hours = second % Day / Hour;
	int minutes = (second % Day) % Hour / Minute;
	int seconds = (second % Day) % Hour % Minute;

	cout << second << " seconds = " << days << " days, " << hours << " hours, " << minutes << " minutes, " << seconds << " seconds";

	return 0;
}
*/

//5
/*
int main() {
	using namespace std;
	long long int Am;
	long long int To;
	cout << "Enter the world's population: ";
	cin >> To;
	cout << "Enter the population of US: ";
	cin >> Am;
	cout << "The population of the US is " << double(Am) / double(To)*100 << "% of the world population.";
	return 0;

}
*/

//6
/*
int main() {
	using namespace std;
	int mile, gal;
	cout << "Enter your miles: ";
	cin >> mile;
	cout << "Enter your gallon:";
	cin >> gal;
	cout << "Your car's mpg is: " << double(mile) / double(gal);
	return 0;
}
*/

//7
/*
const double mile = 0.6214;
const double gal = 0.264172;
int main() {
	using namespace std;
	int kmeter, litre;
	cout << "Enter your kmeter: ";
	cin >> kmeter;
	cout << "Enter your litre: ";
	cin >> litre;
	cout << "The Mpg in Eu is " << double(litre) / double(kmeter)<<endl ;
	cout << "The Mpg in US is " << (double(kmeter)*mile) / (double(litre)*gal);
	return 0;

}
*/

 

转载于:https://my.oschina.net/Almon/blog/3035242

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值