English Deutsch Français Italiano Español Português 繁體中文 Bahasa Indonesia Tiếng Việt ภาษาไทย
All categories

Please help me,i will give you 10 points.Please write the code of C++ using class

2006-06-16 17:56:46 · 1 answers · asked by the_gr8_shirin 2 in Computers & Internet Programming & Design

1 answers

I'd love to help you, but I'm not sure what you're looking for. Part of the problem, perhaps, is that while I'm a good computer programmer with 12+ years programming in C++ I'm really lousy with finances and I'm not sure I could work out interest by hand.

But even if I could, it makes no sense to develop this as a class if you don't have either related functions or persistant data. I can't envision this taking more than one function to implement unless you stretch it some. But if you were to stretch it, try this:

class InterestCalculator
{
public:
InterestCalculator() {SetRate(0.05);}
void SetRate(double r) {Rate = r;} //Add error checking here
double CalcInterest(double money, int months);

private:
double Rate;
};

int main()
{
InterestCalculator calc;

calc.SetRate(0.10); //set rate to 10 percent;

cout << "$500 for two years at a 10% rate has an interest of " << calc.CalcInterest(500, 24) << endl;
}

Now, that's a rather contrived solution, designed to use a class even where it makes little sense to do so. I don't know if this helps or not. I've left the implementation of calculating the interest rate to you (as I said, I'm not sure how to do it even by hand).

If you have more information on what else the class should do so that it makes more sense as a class, modify your question here or shoot me an e-mail and I'll see what help I can be.

Good luck.

2006-06-16 18:27:20 · answer #1 · answered by Mantis 6 · 1 0

fedest.com, questions and answers