Advertisement
Guest User

Untitled

a guest
Feb 9th, 2016
42
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.76 KB | None | 0 0
  1. #include <iostream>
  2. #include <fstream>
  3. #include <iomanip>
  4. #include <cmath>
  5. using namespace std;
  6.  
  7. void papildoma_uzduotis2() {
  8. int year, month, day, payments;
  9. float total, presentValue, interestRate;
  10. float *Remaining, *Principal, *Interest;
  11. cout << "Insert date" << endl;
  12. cin >> year >> month >> day;
  13. cout << "Insert Present Value" << endl;
  14. cin >> presentValue;
  15. cout << "Insert Interest Rate" << endl;
  16. cin >> interestRate;
  17. cout << "Insert number of payments" << endl;
  18. cin >> payments;
  19. Remaining = new(nothrow)float[payments];
  20. Principal = new(nothrow)float[payments];
  21. Interest = new(nothrow)float[payments];
  22. Remaining[0] = presentValue;
  23. total = (Remaining[0] * (interestRate / 1200)) / (1 - pow(1 + (interestRate / 1200), payments*(-1)));
  24. ofstream myfile;
  25. myfile.open ("payments3.csv");
  26. myfile << "Payment #;Payment date;Remaining amount; \
  27. Principal payment;Interest payment;Total payment;Interest rate" << endl;
  28. for (int i = 0; i < payments; i++) {
  29. myfile << i+1 << ";";
  30. if (month > 12) {
  31. month = 1;
  32. year += 1;
  33. }
  34. myfile << year << '-'
  35. << month << '-'
  36. << day
  37. << ";";
  38. month++;
  39. Interest[i] = Remaining[i] * (interestRate / 1200);
  40. Principal[i] = total - Interest[i];
  41. if (i + 1 < payments)
  42. Remaining[i+1] = Remaining[i] - Principal[i];
  43. myfile << fixed << showpoint;
  44. myfile << setprecision(2);
  45. myfile << Remaining[i] << ";" << Principal[i] << ";" << Interest[i] << ";\
  46. " << total << ";" << interestRate << endl;
  47. }
  48. myfile.close();
  49. delete[] Remaining;
  50. delete[] Principal;
  51. delete[] Interest;
  52. }
  53. void papildoma_uzduotis1(float payments, float total, float presentValue, float interestRate, int year, int month, int day) {
  54. float Remaining[24], Principal[24], Interest[24];
  55. Remaining[0] = presentValue;
  56. ofstream myfile;
  57. myfile.open ("payments2.csv");
  58. myfile << "Payment #;Payment date;Remaining amount; \
  59. Principal payment;Interest payment;Total payment;Interest rate" << endl;
  60. for (int i = 0; i < payments; i++) {
  61. myfile << i+1 << ";";
  62. if (month > 12) {
  63. month = 1;
  64. year += 1;
  65. }
  66. if (year == 2015 && month == 9 && day > 1) {
  67. interestRate = 9;
  68. total = (Remaining[i] * interestRate / 1200) / (1 - pow((1 + (interestRate / 1200)), (payments - (i))*(-1)));
  69. }
  70. myfile << year << '-'
  71. << month << '-'
  72. << day
  73. << ";";
  74. month++;
  75. Interest[i] = Remaining[i] * (interestRate / 1200);
  76. Principal[i] = total - Interest[i];
  77. if (i + 1 < payments)
  78. Remaining[i+1] = Remaining[i] - Principal[i];
  79. myfile << fixed << showpoint;
  80. myfile << setprecision(2);
  81. myfile << Remaining[i] << ";" << Principal[i] << ";" << Interest[i] << ";\
  82. " << total << ";" << interestRate << endl;
  83. }
  84. myfile.close();
  85. }
  86. int main()
  87. {
  88. int year = 2015, month = 4, day = 5, payments = 24;
  89. float total, presentValue = 5000, interestRate = 12;
  90. float Remaining[24], Principal[24], Interest[24];
  91. Remaining[0] = presentValue;
  92. total = (presentValue * interestRate / 1200) / (1 - pow((1 + (interestRate / 1200)), payments*(-1)));
  93. papildoma_uzduotis1(payments, total, presentValue, interestRate, year, month, day);
  94. ofstream myfile;
  95. myfile.open ("payments.csv");
  96. myfile << "Payment #;Payment date;Remaining amount; \
  97. Principal payment;Interest payment;Total payment;Interest rate" << endl;
  98. for (int i = 0; i < payments; i++) {
  99. myfile << i+1 << ";";
  100. if (month > 12) {
  101. month = 1;
  102. year += 1;
  103. }
  104. myfile << year << '-'
  105. << month << '-'
  106. << day
  107. << ";";
  108. month++;
  109. Interest[i] = Remaining[i] * (interestRate / 1200);
  110. Principal[i] = total - Interest[i];
  111. if (i + 1 < payments)
  112. Remaining[i+1] = Remaining[i] - Principal[i];
  113. myfile << fixed << showpoint;
  114. myfile << setprecision(2);
  115. myfile << Remaining[i] << "; "
  116. << Principal[i] << "; "
  117. << Interest[i] << "; "
  118. << total << "; "
  119. << interestRate
  120. << endl;
  121. }
  122. myfile.close();
  123. papildoma_uzduotis2();
  124. return 0;
  125. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement