Skriv til en fil og hente den igen
Er der nogen der er vaagen nu og kan hjælpe mig.Jeg er gaaet helt kold i det at skrive til en fil og hente den igen fra et nummer. Den konkrete opgave er i c++ og skal illustrere et laan, hvor man laver et laane nummer, som tastes ind og man kan saa faa oplysninger om sit laan, osv. (se switch casen)
Jeg mangler hjælp til omraadet omkring den anden class
og hvad der skal ske derefter !???
#include<fstream.h>
#include<iostream.h>
#include<conio.h>
#include<iomanip.h>
#include<cstdlib>
using namespace std;
ifstream in_stream;
ofstream out_stream;
class loan // Creating the class loan
{
private: //Creating the privat classes
int iMonths;
double dInterest;
double dInterest_amount;
double dPayment;
double dRepayment;
int iLoan;
int LoanNumber;
public: //Creating the public classes
void calculate_and_print_loan(); // Creating the functions calls
void input_loan();
void write (ostream& out);
void read (istream& inn);
};
class loan_files
{
public:
void add (loan& l);
bool check ();
//void insert (int in_LoanNumber, int in_LoanAmount, double in_Interest, double in_Repayment);
private:
fstream f;
bool OK_check();
void open();
void close();
};
int main ()
{
int loan_overview ;
cout << "\t +++ Welcome to the NetBank +++ \n";
cout << "\t Press the number of the relevant service you need. \n ";
cout << endl;
cout << "\t Create a new loan: (1)\n";
cout << endl;
cout << "\t Update an existing loan: (2)\n";
cout << endl;
cout << "\t Delete loan: (3)\n";
cout << endl;
cout << "\t See all your loans: (4)\n";
cout << endl;
cout << "\t Calculate all your payments: (5)\n";
cin >> loan_overview;
loan LoanA;
LoanA.input_loan();
LoanA.calculate_and_print_loan();
switch (loan_overview)
{
case 1:
LoanA.input_loan(); //Excecutes the "Input" function
break;
case 2:
LoanA.loan::calculate_and_print_loan();
break;
case 3:
;
break;
case 4:
cout <<" See all Loan ";
break;
case 5:
cout <<" Show all payments ";
break;
default:
cout <<" Make a choice between 1 and 5 ";
}
getch();
return 0;
}
void loan::write( ostream& out )
{
out.setf(ios::fixed); // Just cosmetic lines for the output !!
out.setf(ios::showpoint);
out.precision(2);
out <<setw(15) << LoanNumber << ' '
<<setw(15) << iLoan << ' '
<<setw(15) << dRepayment << ' '
<<setw(15) << dInterest_amount << ' '
<<setw(15) << dPayment << ' ' << endl;
}
void loan::input_loan()
{
cout << "\n\t This program will help you create a new loan \n";
cout << "\n Type in the Loan Number: ";
cin >> LoanNumber;
cout << "\n Type in the amount of money you wanna lend: ";
cin >>iLoan;
cout << "\n Type in the annually interest of your loan: ";
cin >>dInterest;
cout << "\n Type in the length of the loan (months): ";
cin >>iMonths;
}
void loan::calculate_and_print_loan() //Excecute the "C and P" function
{
clrscr(); //Clears the screen
cout << "\n\t\t\t +++ The Loan +++";
cout << endl;
cout << "\n\t\t An Overview Of Your Loan With Interests And Payments ";
cout << endl;
cout << endl;
cout << "NR. of Payments" << setw(9) << "Loan" << setw(20) << "Repayments"
<< setw(15) << "Interest" << setw(20) << "Total Payments " << setw(18) << endl;
int counter = 0;
dRepayment = iLoan/iMonths;
while (iLoan > 0) // Creating a "While loop" for accumulated payments
{
counter ++; //Counts the number of times the "While loop" is running
dInterest_amount =(iLoan * dInterest) / 1200; // Calculating the Interest for a month
dPayment = dRepayment + dInterest_amount;
iLoan = iLoan - dRepayment;
cout << setw(6) << counter << setw(19) << iLoan << setw(18) << dRepayment << setw(15) << dInterest_amount << setw(18) << dPayment << endl;
}
}
void loan_files::add( loan& l)
{
open();
l.write(f);
close();
}