A bank is providing loan to its customers. Customers will return back loan with installments without any INTEREST but penalty charges are needed to be paid.
Fine Rs. 100 per day will be charged if amount is paid after due date and 5% penalty will be charged on Due amount if pay less amount. write c++ code using arrays. only math.h lib can be used if needed.
part 2:
can this c++ code be done using no library as we are not allowed to use any. We can only use array which is compulsory for this question and along side arrays we are allowed to use switch else if while for loops only.and also we have to take loan amount, no of installment, amount of each installment date, installment amounts from user to calculate penalty and show the data in tabular form.
#include<iostream>
using namespace std;
double penalty_charged(double l, double r, int d){
double penalty = 0;
if (d > 0) {
penalty = d*100;
}
if (r < l) {
penalty += (l - r)*0.05;
}
return penalty;
}
int main(){
double loan_amount[5] = {10000, 20000, 100000, 50000, 45000};
double refund_amount[5] = {10000, 15000, 100000, 40000, 45000};
double penalty_amount[5];
int days[5] = {0, 5, 2, 0, 1};
for (int i=0; i<5; i++) {
penalty_amount[i] = penalty_charged(loan_amount[i], refund_amount[i], days[i]);
cout<<"Loans Rs. "<<loan_amount[i]<<", Refund Rs. "<<refund_amount[i]<<" "<<days[i]<<" days delay\n";
cout<<"Penalty is Rs. "<<penalty_amount[i]<<" \n\n";
}
double arr[5][4];
int ii;
double x;
for (int i=0; i<5; i++) {
cout<<"Enter dat for "<<(i+1)<<"-th loan\n";
cout<<"Loan amount: ";
cin>>x;
arr[i][0] = x;
cout<<"Refund: ";
cin>>x;
arr[i][1] = x;
cout<<"Day after due date: ";
cin>>ii;
arr[i][2] = ii;
arr[i][3] = penalty_charged(arr[i][0], arr[i][1], (int) arr[i][2]);
}
cout<<"\n";
cout<<"NN | Loan amnt | Refund | Days | Penalty \n";
cout<<"---+-----------+-----------+------+----------\n";
for (int i=0; i<5; i++) {
cout<< i+1<<" | "<<arr[i][0]<<" | "<< arr[i][1]<<" | "<<arr[i][2]<<" | "<< arr[i][3]<<"\n";
}
return 0;
}
Comments
Leave a comment