c++ primer plus初学,编程题练习
本菜鸟开始学“C++ Primer Plus 第6版 中文版”了,按照章节学习并把章节后面所有的编程题全部做出来,希望大神多多指点!!
2015-07-28 21:46
程序代码:#include<iostream>
using namespace std;
int main()
{
const int da_to_ho=24;
const int ho_to_mi=60;
const int mi_to_se=60;
long s;
long days,hours,minutes,seconds;
cout<<"enter the number of seconds:";
cin>>s;
days=s/da_to_ho/ho_to_mi/mi_to_se;
hours=s%(da_to_ho*ho_to_mi*mi_to_se)/(ho_to_mi*mi_to_se);
//醉醉的 当初写上一个语句是全部用的是除法 结果小于0出错 杀毒软件说我的这个程序有可能是木马哈哈哈
minutes=s%(ho_to_mi*mi_to_se)/(mi_to_se);
seconds=s%(mi_to_se);
cout<<s<<" seconds ="<<days<<"days,"<<hours<<"hours,"<<minutes<<"minutes,"<<seconds<<"seconds\n";
return 0;
}
2015-07-28 21:51
掌柜的也在看这本书,有时间一起交流学习哈
2015-07-28 21:52
2015-07-28 21:53
掌柜的是一个小白,人没关系又没后台,人长的又丑,又不能靠脸吃饭,文凭也没有的社会败类,人渣中的战斗机
2015-07-28 21:59
程序代码:#include<iostream>
using namespace std;
int main()
{
cout.setf(ios_base::fixed,ios_base::floatfield);
double us,world;//题目要求是longlong类型,可是系统不支持,只能用double来代替。
cout<<"enter the world's population: ";
cin>>world;
cout<<"enter the population of the us: ";
cin>>us;
const double n=100;
double percent=us/world*n;
cout<<"the population of the us is "<<percent<<"% of the world population.";
return 0;
}
2015-07-28 22:30
2015-07-28 22:32
,掌柜的也牛
2015-07-29 17:18