这两道请按顺序解答,谢谢了求大神解答

C++菜鸟,两道实验题目希望大神帮忙解答,谢谢 - C++当前位置:& &&&C++菜鸟,两道实验题目希望大神帮忙解答,谢谢C++菜鸟,两道实验题目希望大神帮忙解答,谢谢&&网友分享于:&&浏览:0次C++初学者,两道实验题目希望大神帮忙解答,多谢本帖最后由 u 于
09:18:52 编辑
A&person&invests&$1000.00&in&a&saving&account&yielding&5%&interest.&Assuming&that&all&
interest&is&left&on&deposit&in&the&account,&calculate&and&print&the&amount&of&money&in&the&
account&at&the&end&of&each&year&for&10&years.&Use&the&following&formula&for&determining&
these&amounts:&a=p(1+r)^n&where&p&is&the&original&amount&of&money&invested&(i.e.,&the&
principle),&r&is&the&annual&interest&rate,&n&is&the&number&of&years&and&a&is&the&amount&of&
deposit&at&the&end&of&the&nth&year.&Display&the&result&in&a&table.&Make&sure&the&columns&are&
neatly&aligned.&
Legend&has&it&that,&in&1626,&Peter&Minuit&purchased&Manhattan&Island&for&$24.00&in&barter.&
Did&he&make&a&good&investment?&To&answer&this&question,&modify&part&I&to&begin&with&
p=24.00&and&to&calculate&the&amount&of&deposit&a&until&this&year&(i.e.,&2012).&You&just&need&
to&print&the&value&of&a&every&other&50&years&and&2012&(i.e.,&years&,&…,&2012).&
Try&to&use&different&interest&rates&from&5%,&6%,&…,&to&10%.&------解决方案--------------------#include&&iostream&
#include&&math.h&
using&namespace&
double&calc_money(double&original_money,double&rate,int&year);
int&main()
&&&&int&year&=&10;
&&&&double&original_money=&1000;
&&&&double&rate&=&0.05;
&&&&double&result&=&0;
&&&&result&=&calc_money(original_money,rate,year);
&&&&return&0;
double&calc_money(double&original_money,double&rate,int&year)
&&&&double&result&=&0;
&&&&result&=&original_money*pow(1+rate,year);
&&&&return&
}------解决方案--------------------PartⅠ:
#include&iostream&
#include&cmath&
using&namespace&
const&double&p&=&1000.00;
const&double&r&=&0.05;
double&cal(int&n){
return&p*pow(1&+&r,&n);
int&main(){
for&(int&i&=&0;&i&&&10;&i++){
cout&&&&i&+&1&&&&'\t';
cout.setf(ios::fixed,&ios::floatfield);
cout.precision(2);
cout&&&cal(i&+&1)&&&&
#include&iostream&
#include&cmath&
#include&iomanip&
using&namespace&
const&double&p&=&24.00;
const&double&r[]&=&{&0.05,&0.06,&0.07,&0.08,&0.09,&0.10&};
double&cal(int&n,int&j){
return&pow(1&+&r[j],&n);
int&main(){
int&start_year&=&1626;
double&rate[6];
for&(int&i&=&0;&i&&&6;&i++)
rate[i]&=&cal(50,&r[i]);
for&(int&k&=&0;&k&&&6;&k++){
cout&&&&"年份\t利率"&&r[k]&&&&
for&(int&i&=&1;&i&&&8;&i++){
cout&&&&start_year&+&i&*&50&&&&'\t';
cout.setf(ios::fixed,&ios::floatfield);
cout.precision(2);
cout&&&p*pow(rate[k],&i)&&&&'\t';
cout&&&&"2012\t";
cout.setf(ios::fixed,&ios::floatfield);
cout.precision(2);
cout&&&&p*pow(rate[k],&7)*cal(36,&k)&&&&
最后的结果你再检查检查,仅供参考
12345678910
12345678910
12345678910 上一篇:下一篇:文章评论相关解决方案 12345678910 Copyright & &&版权所有

参考资料

 

随机推荐