C++初学者,两道实验题目希望大神帮忙解答,多谢

崖下人生 2014-02-06 09:16:17
Part I.
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.

Part II.

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 1676, 1726, …, 2012).
Try to use different interest rates from 5%, 6%, …, to 10%.
...全文
282 8 打赏 收藏 转发到动态 举报
写回复
用AI写文章
8 条回复
切换为时间正序
请发表友善的回复…
发表回复
崖下人生 2014-02-07
  • 打赏
  • 举报
回复
尽管语言有时很苍白,但是我非常诚恳的向楼上两位表示感谢
Falleyes 2014-02-06
  • 打赏
  • 举报
回复
PartⅠ:
#include<iostream>
#include<cmath>
using namespace std;

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) << endl;
	}
}
Part Ⅱ:
#include<iostream>
#include<cmath>
#include<iomanip>
using namespace std;

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] << endl;
		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 << endl;
		}
		cout << "2012\t";
		cout.setf(ios::fixed, ios::floatfield);
		cout.precision(2);
		cout << p*pow(rate[k], 7)*cal(36, k) << endl;
		cout << endl;
	}
}
最后的结果你再检查检查,仅供参考
auq404 2014-02-06
  • 打赏
  • 举报
回复
#include <iostream> #include <math.h> using namespace std; 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 result; }
u012723504 2014-02-06
  • 打赏
  • 举报
回复
你先翻译一下再做,很简单的
崖下人生 2014-02-06
  • 打赏
  • 举报
回复
引用 3 楼 u013601512 的回复:
[quote=引用 1 楼 vcf_reader 的回复:] That is too simple.
I know that it is so easy. However, It is difficult to do by using C++ for beginner.Therefore,I hope you can help me. Thank you very much
崖下人生 2014-02-06
  • 打赏
  • 举报
回复
引用 1 楼 vcf_reader 的回复:
That is too simple.
I know that it is so easy. However, It is different to do by using C++ for beginner.Therefore,I hope you can help me. Thank you very much
Falleyes 2014-02-06
  • 打赏
  • 举报
回复
其实只要读懂题目就很简单的,小学数学题啊。 建议楼主用在线段落翻译,然后自己做吧。
vcf_reader 2014-02-06
  • 打赏
  • 举报
回复
That is too simple.

65,210

社区成员

发帖
与我相关
我的任务
社区描述
C++ 语言相关问题讨论,技术干货分享,前沿动态等
c++ 技术论坛(原bbs)
社区管理员
  • C++ 语言社区
  • encoderlee
  • paschen
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
  1. 请不要发布与C++技术无关的贴子
  2. 请不要发布与技术无关的招聘、广告的帖子
  3. 请尽可能的描述清楚你的问题,如果涉及到代码请尽可能的格式化一下

试试用AI创作助手写篇文章吧