1 / 11

程式錄影作業

程式錄影作業. 資工一 A 4980E008 劉建宏. 求出實現某未來價值所需的初期投資額.

wood
Download Presentation

程式錄影作業

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. 程式錄影作業 資工一A 4980E008 劉建宏

  2. 求出實現某未來價值所需的初期投資額 • #include<iostream>#include<cmath>#include<iomanip>#include<locale>using namespace std;double initval(double targetValue,double rateOfRet,int numYears,int compPerYear){       double b,e;       rateOfRet /=100.0;        b = (1 + rateOfRet/compPerYear);         e = compPerYear * numYears;     return targetValue / pow(b,e);}int main(){    double p,r;    int y,cpy;    cout<<"Enter desired future value:";    cin>>p;    cout<<"Enter rate of return:";    cin>>r;     cout<<"Enter number years:";    cin>>y;    cout<<"Enter number of compoundings per year:";    cin>>cpy;    cout<<"\nInitial investment required:"        <<fixed<<setprecision(2)        <<initval(p,r,y,cpy)<<endl;    system("pause");    return 0;}

  3. 執行結果

  4. 某筆投資的未來價值 • #include<iostream>#include<cmath>#include<iomanip>#include<locale>#include<conio.h>using namespace std;double futval(double principal,double rateOfRet,int numYears,int compPerYear){  double b,e;  rateOfRet /=100.0;  b = (rateOfRet/compPerYear + 1);   e = compPerYear * numYears;  return principal * pow(b,e);}int main(){    double p,r;    int y,cpy;    cout<<"Enter principal:";    cin>>p;    cout<<"Enter rate of return (as a percentage):";    cin>>r;    cout<<"Enter number years:";    cin>>y;    cout<<"Enter number of compoundings per year:";    cin>>cpy;    cout<<"\nFuture value:"<<fixed<<setprecision(2)<<futval(p,r,y,cpy)<<endl;    getch();    return 0;}

  5. 執行結果

  6. 某筆投資最大年金 • #include<iostream>#include<cmath>#include<iomanip>#include<locale>using namespace std;double maxwd(double principal,double rateOfRet,int numYears,int wdPerYear){       double b,e;       double t1,t2;       rateOfRet /=100.0;       t1 = rateOfRet / wdPerYear;       b = (1+t1);       e = wdPerYear * numYears;       t2 = pow(b,e) - 1;        return principal * (t1/t2+t1);}int main(){    double p,r;    int y,wpy;    cout<<"Enter principal:";    cin>>p;    cout<<"Enter rate of return (as a percentage):";    cin>>r;    cout<<"Enter number years:";    cin>>y;    cout<<"Enter number of withdrawals per year:";    cin>>wpy;    cout<<"\nMaximum withdrawal:"        <<fixed<<setprecision(2)        <<maxwd(p,r,y,wpy)<<endl;    system("pause");    return 0;}

  7. 執行結果

  8. 針對期望年金求出最初投資額 • #include<iostream>#include<cmath>#include<iomanip>#include<locale>using namespace std;double annuity(double regWD,double rateOfRet,int numYears,int wdPerYear){       double b,e;       double t1,t2;       rateOfRet /=100.0;       t1 = ((regWD * wdPerYear)/rateOfRet);       b = ( rateOfRet/wdPerYear + 1);        e = wdPerYear * numYears;       t2 = 1 - (1/pow(b,e));       return t1 * t2;}int main(){    double wd,r;    int y,wpy;    cout<<"Enter desired withdrawal:";    cin>>wd;    cout<<"Enter rate of return (as a percentage):";    cin>>r;    cout<<"Enter number years:";    cin>>y;    cout<<"Enter number of withdrawals per year:";    cin>>wpy;    cout<<"\nInitial investment required:"        <<fixed<<setprecision(2)        <<annuity(wd,r,y,wpy)<<endl;        system("pause");        return 0;        }

  9. 執行結果

  10. 貸款的繳款額度 • #include<iostream>#include<cmath>#include<iomanip>#include<locale>#include<conio.h>using namespace std;double regpay(double principal,double intRate,int numYears,int payPerYear){double numer;double denom;double b,e;intRate /=100.0;numer = intRate*principal / payPerYear;e = -payPerYear * numYears;b = (intRate / payPerYear) +1.0;denom = 1.0 - pow(b,e);return numer / denom;}int main(){    double p,r;    int y,ppy;    cout<<"Enter principal:";    cin>>p;    cout<<"Enter interest rate (as a percentage):";    cin>>r;    cout<<"Enter number years:";    cin>>y;    cout<<"Enter number of payments per year:";    cin>>ppy;    cout<<"\nPayment:" <<fixed<<setprecision(2)<<regpay(p,r,y,ppy)<<endl;    getch();    return 0;}

  11. 執行結果

More Related