Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <fstream>
- #include <iomanip>
- #include <cmath>
- using namespace std;
- void papildoma_uzduotis2() {
- int year, month, day, payments;
- float total, presentValue, interestRate;
- float *Remaining, *Principal, *Interest;
- cout << "Insert date" << endl;
- cin >> year >> month >> day;
- cout << "Insert Present Value" << endl;
- cin >> presentValue;
- cout << "Insert Interest Rate" << endl;
- cin >> interestRate;
- cout << "Insert number of payments" << endl;
- cin >> payments;
- Remaining = new(nothrow)float[payments];
- Principal = new(nothrow)float[payments];
- Interest = new(nothrow)float[payments];
- Remaining[0] = presentValue;
- total = (Remaining[0] * (interestRate / 1200)) / (1 - pow(1 + (interestRate / 1200), payments*(-1)));
- ofstream myfile;
- myfile.open ("payments3.csv");
- myfile << "Payment #;Payment date;Remaining amount; \
- Principal payment;Interest payment;Total payment;Interest rate" << endl;
- for (int i = 0; i < payments; i++) {
- myfile << i+1 << ";";
- if (month > 12) {
- month = 1;
- year += 1;
- }
- myfile << year << '-'
- << month << '-'
- << day
- << ";";
- month++;
- Interest[i] = Remaining[i] * (interestRate / 1200);
- Principal[i] = total - Interest[i];
- if (i + 1 < payments)
- Remaining[i+1] = Remaining[i] - Principal[i];
- myfile << fixed << showpoint;
- myfile << setprecision(2);
- myfile << Remaining[i] << ";" << Principal[i] << ";" << Interest[i] << ";\
- " << total << ";" << interestRate << endl;
- }
- myfile.close();
- delete[] Remaining;
- delete[] Principal;
- delete[] Interest;
- }
- void papildoma_uzduotis1(float payments, float total, float presentValue, float interestRate, int year, int month, int day) {
- float Remaining[24], Principal[24], Interest[24];
- Remaining[0] = presentValue;
- ofstream myfile;
- myfile.open ("payments2.csv");
- myfile << "Payment #;Payment date;Remaining amount; \
- Principal payment;Interest payment;Total payment;Interest rate" << endl;
- for (int i = 0; i < payments; i++) {
- myfile << i+1 << ";";
- if (month > 12) {
- month = 1;
- year += 1;
- }
- if (year == 2015 && month == 9 && day > 1) {
- interestRate = 9;
- total = (Remaining[i] * interestRate / 1200) / (1 - pow((1 + (interestRate / 1200)), (payments - (i))*(-1)));
- }
- myfile << year << '-'
- << month << '-'
- << day
- << ";";
- month++;
- Interest[i] = Remaining[i] * (interestRate / 1200);
- Principal[i] = total - Interest[i];
- if (i + 1 < payments)
- Remaining[i+1] = Remaining[i] - Principal[i];
- myfile << fixed << showpoint;
- myfile << setprecision(2);
- myfile << Remaining[i] << ";" << Principal[i] << ";" << Interest[i] << ";\
- " << total << ";" << interestRate << endl;
- }
- myfile.close();
- }
- int main()
- {
- int year = 2015, month = 4, day = 5, payments = 24;
- float total, presentValue = 5000, interestRate = 12;
- float Remaining[24], Principal[24], Interest[24];
- Remaining[0] = presentValue;
- total = (presentValue * interestRate / 1200) / (1 - pow((1 + (interestRate / 1200)), payments*(-1)));
- papildoma_uzduotis1(payments, total, presentValue, interestRate, year, month, day);
- ofstream myfile;
- myfile.open ("payments.csv");
- myfile << "Payment #;Payment date;Remaining amount; \
- Principal payment;Interest payment;Total payment;Interest rate" << endl;
- for (int i = 0; i < payments; i++) {
- myfile << i+1 << ";";
- if (month > 12) {
- month = 1;
- year += 1;
- }
- myfile << year << '-'
- << month << '-'
- << day
- << ";";
- month++;
- Interest[i] = Remaining[i] * (interestRate / 1200);
- Principal[i] = total - Interest[i];
- if (i + 1 < payments)
- Remaining[i+1] = Remaining[i] - Principal[i];
- myfile << fixed << showpoint;
- myfile << setprecision(2);
- myfile << Remaining[i] << "; "
- << Principal[i] << "; "
- << Interest[i] << "; "
- << total << "; "
- << interestRate
- << endl;
- }
- myfile.close();
- papildoma_uzduotis2();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement