sources:
M01_3.cpp (1.3k)


website:
more info here
studies/bauelemente/Softwarebauelemente-CodeM3/M01_3.cpp
download file

  1 ///////////////////////////////////////////////////////////
  2 // Softwarebauelemente I, Aufgabe M1.3
  3 //
  4 // author: Stephan Brumme
  5 // last changes: October 14, 2000
  6
  7
  8 // include I/O-streams and mathematical support
  9 #include <iostream.h>
 10 #include <math.h>
 11
 12
 13 void main()
 14 {
 15     // initial payment
 16     double       dPayment;
 17     // interest rate
 18     double         dInterestRate;
 19     // years since payment (0..10, not 2001..2011 !)
 20     unsigned int nYear;
 21
 22     // duration of investment
 23     const int    nDuration = 10;
 24     // interest rates
 25     const double dLowInterestRate  = 0.03;
 26     const double dHighInterestRate = 0.04;
 27     // boundary between both interest rate (in DM)
 28     const double dLimit            = 5000;
 29
 30
 31     // read payment
 32     cout<<"Bitte geben Sie das Anfangsguthaben in DM ein: ";
 33     cin>>dPayment;
 34
 35     // determine interest rate
 36     if (dPayment < dLimit)
 37         dInterestRate = dLowInterestRate;
 38     else         dInterestRate = dHighInterestRate;
 39     cout<<"Ihr Zinssatz betraegt "<<dInterestRate*100<<"%.\n";
 40
 41     // show overview for first 10 years
 42     for (nYear = 0; nYear <= nDuration; nYear++)
 43         cout<<"Guthaben am 01.01."<<(2001+nYear)<<": DM "
 44             <<dPayment * pow(1.0+dInterestRate, nYear)<<"\n";
 45
 46     // calculate expected duration for doubling the investment
 47     cout<<"\nIhr Guthaben wird sich in "<<log(2)/log(1+dInterestRate)
 48         <<" Jahren verdoppelt haben.\n";
 49 }
 50