Avatar billede bajads Nybegynder
25. oktober 2002 - 01:25 Der er 2 kommentarer og
1 løsning

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();
}
Avatar billede bajads Nybegynder
25. oktober 2002 - 01:26 #1
Dette er saadan lidt blandet landhandel, saa evt. maa gerne være med kommentarer saa jeg har nemmere ved at rette og forstaa ( forhaabentlig) !!!
Avatar billede bajads Nybegynder
25. oktober 2002 - 01:51 #2
Lukker igen, da jeg skulle aflevere det .....næsten færdige program - suk- !!
Avatar billede soepro Nybegynder
05. november 2002 - 11:03 #3
Søg her på eksperten - dette spørgsmål er stillet et utal af gange. (Søg f.eks. på 'fil skriv læs tekst' og check de svar der kommer op.)
Avatar billede Ny bruger Nybegynder

Din løsning...

Tilladte BB-code-tags: [b]fed[/b] [i]kursiv[/i] [u]understreget[/u] Web- og emailadresser omdannes automatisk til links. Der sættes "nofollow" på alle links.

Loading billede Opret Preview
Kategori
Kurser inden for grundlæggende programmering

Log ind eller opret profil

Hov!

For at kunne deltage på Computerworld Eksperten skal du være logget ind.

Det er heldigvis nemt at oprette en bruger: Det tager to minutter og du kan vælge at bruge enten e-mail, Facebook eller Google som login.

Du kan også logge ind via nedenstående tjenester