C++ Primer Plus 习题答案 第三章

//3.7.1   1英尺=12英寸 
# include <iostream>
using namespace std;
int main()
{
	const int change= 12;
	int ft;
	int inch;
	cout << "Please enter your height in ft: ";
	cin>> ft;
	inch=change*ft;
	cout <<"Your height in ft is :"<<ft<<" ft"<<endl;
	cout <<"Your height in inch is :"<<inch<<" inch"<<endl;
	return 0;	
} 


//3.7.2
# include <iostream>
using namespace std;
int main()
{
	int ft,inch;
	int pounds;
	cout << "Please enter your height: ";
	cin>>ft;
	cin>>inch;
	cout <<"Please enter your weight in pounds: ";
	cin>>pounds;
	cout<<"Your height is "<<ft<<" ft"<<inch<<" inch"<<endl;
	cout <<"Your weight is "<<pounds<<" pounds"<<endl;
	float mi=(ft*12+inch)*0.0254;
	float kg=pounds*0.46;
	float BMI= kg/(mi*mi);
	cout << "Your BMI is :"<< BMI <<" BMI"<<endl;
	return 0;
}


//3.7.3
# include <iostream>
using namespace std;
int main()
{
	double f1=0.0166;
	double f2=2.7778e-4;
	int degrees,minutes,second;
	double total;
	cout << "Enter a latitude in degrees,minutes,and second:"<<endl;
	cout <<"Firts ,enter the degrees:";
	cin>>degrees;
	cout <<"Next,enter the minutes of arc:";
	cin>>minutes;
	cout<<"Finally,enter the seconds of arc:";
	cin>>second;
	total=degrees+minutes*f1+second*f2;
	cout <<degrees <<" degrees ,"<<minutes <<" minutes,"<<second<<" seconds="<<total<<" degrees."<<endl;
	return 0;
 } 



//3.7.4
# include <iostream>
using namespace std;
int main()
{
	const int day=86400,hour=3600,minute=60;
	long int seconds;
	cout <<"Enter the number of seconds: ";
	cin>>seconds;
	int days=seconds/day;
	int hours=seconds/hour;
	int minutes = seconds/minute;
	cout<<seconds<<" seconeds = "<<days<<" days,"<<hours<<" hours,"<<minutes<<" minutes."<<endl;
	return 0;
}

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值