有一道C++编程题,救命啊!

来源:百度知道 编辑:UC知道 时间:2024/05/12 11:46:55
一、 编程题(100分)
[题目]假设某地GDP增长率恒定, 定义一个类GDP,具体要求如下:(40分)
1)私有数据成员
 double GDP;
 double zzl;
 int iYear;
2)公有数据成员
 GDP (int iYear,double Gdp,double zzl);构造函数,用某年iYear的Gdp及增长率zzl初始化该对象。
 double GetGDP(int iYear);返回某年的GDP。
3)在主函数中对该类进行测试:
中华人民共和国2000年的GDP为1万亿美元,GDP的年增长率为9%,求2007年GDP为多少?(30分)
日本2000年的GDP为4万亿美元,GDP的年增长率为2%,求中国GDP赶上日本的年份? (30分)

#include "stdafx.h"
#include <iostream>
#include <cmath>
using namespace std;

const int BASEYEAR = 2000;

class GDP
{
public:
GDP(int year, double gdp, double zzl) : m_dGDP(gdp),m_dZZL(zzl),m_iYear(year){}

double getGDP(int year) const
{
return m_dGDP * pow(1 + m_dZZL, year - BASEYEAR);
}

private:
double m_dGDP;
double m_dZZL;
int m_iYear;
};

const GDP CHINA(2000, 1.0, 0.09);
const GDP FUCKJAPAN(2000, 4.0, 0.02);

void main()
{
cout << "GDP in 2007 of China : " << CHINA.getGDP(2007) << endl;

int year = 2000;
while(CHINA.getGDP(year) < FUCKJAPAN.getGDP(year))
{
++year;
}

cout << "China GDP will bigger than Japan in " << year << endl;
}