现在的位置: 首页 > 综合 > 正文

第三章课后练习

2018年04月30日 ⁄ 综合 ⁄ 共 1933字 ⁄ 字号 评论关闭

第一题

//3.1
#include<iostream>
using namespace std;
const int tran=12;
int main()
{
	void trans(int);
	int h_cun;
	int h_chi,h_cun1;
	cout<<"input your hight______\b\b\b\b\b\b";
	cin>>h_cun;
	trans(h_cun);
	return 0;
}

void trans(int h)
{
	int chi,cun;
	chi=h/tran;
	cun=h%tran;
	cout<<"shengaowei:"<<chi<<"chi"<<cun<<"cun"<<endl;
}

第二题

//3.2
#include<iostream>
using namespace std;
const int ft_to_in=12;
const double in_to_m=0.0254;
const double pound_to_kg=2.2;

int main()
{
	int ft,in;
	int in1;
	double m;
	double pound,kg;
	double BMI;
	cout<<"input"<<endl;
	cin>>ft>>in>>pound;
	in1=ft*ft_to_in+in;
	m=in1*in_to_m;
	kg=pound/pound_to_kg;
	BMI=kg/m/m;
	cout<<"shengao"<<in1<<endl;
	cout<<"tizhong"<<kg<<endl;
	cout<<"BMI"<<BMI<<endl;
	return 0;
}

第三题

//3.3
#include<iostream>
using namespace std;
const int tran=60;
int main()
{
	double degree,minute,second;
	double degree1,minute1,second1;
	cout<<"enter a latitude in degree,minutes,and seconds"<<endl;
	cout<<"frist,enter the degree";
	cin>>degree;
	cout<<"next,enter the minutes of arc";
	cin>>minute;
	cout<<"finally,enter the seconds of arc";
	cin>>second;
	minute1=minute/tran;
	second1=second/tran/tran;
	degree1=degree+minute1+second1;
	cout<<degree<<"degrees"<<minute<<"minutes"<<second<<"seconds="<<degree1<<endl;
	return 0;
}

第四题

//3.4
#include<iostream>
using namespace std;
const int sec_hour=3600;
const int sec_min=60;
const double sec_day=86400;

int main()
{
	int day,hour,minute,second;
	long long second1;
	cout<<"enter the number of seconds"<<endl;
	cin>>second1;
	day=second1/sec_day;
	hour=(second1-day*sec_day)/sec_hour;
	minute=(second1-day*sec_day-hour*sec_hour)/sec_min;
	second=second1%60;
	cout<<second1<<"seconds ="<<day<<"days"<<hour<<"hours"<<minute<<"minutes"<<second<<"seconds"<<endl;
	return 0;

}

第五题

3.5
#include<iostream>
using namespace std;

int main()
{
	long long number_world,number_Amarican;
	double percent;
	cout<<"enter the world's population";
	cin>>number_world;
	cout<<"enter the population of us";
	cin>>number_Amarican;
	percent=double(number_Amarican)/double(number_world);//强制类型转换
	cout<<"the population of the us is "<<percent*100<<"% of the wworld population";
	return 0;
}

第七题第八题类似。

【上篇】
【下篇】

抱歉!评论已关闭.