Jump to content
Sign in to follow this  
yenna

Search N Delete Coding

Recommended Posts

APA KABER SEMUA....BOLEH BANTU SAYA DENGAN CODING NI TAK...

SAYA NAK BUAT CODING UNTUK SEARCH DAN DELETE DLM CLASS...CODING UNTUK ADD DAN DISPLAY DAH OKEY CUMA NAK BUAT SERACH N DELETE JER TAK DER IDEA LA....

BOLEH SAPA-SAPA TOLONG TAK....TERIMA KASIH

KAT CN KITER BAGI ONE PART OF THE CODING TU FOR REFERENCE::

#include <string>

#include <cstdlib>

#include<fstream>

using namespace std;

#include <iostream.h>

#include <conio.h>

class Reservation

{

private:

string Name;

int Id;

int pass;

double Code;

int Valid_Id(int verify);

public:

Reservation()

{

Code=0.00;

};

int Modify_Reser()

{

cout<<"Enter your Credit Card No : ";

cin>>pass;

Reservation::Valid_Id(pass);

if(Reservation::Valid_Id(pass)==1)

{

cout<<" Current Account Holder : "<<Name <<endl;

cout<<"Enter New Destination Code: ";

cin>>Code;

cout<< " =====RESERVATION INFORMATION===== " <<endl <<endl;

cout<<" Account Holder : "<<Name <<endl;

cout<<" Destination Code: "<<Code <<endl;

cout<< " ============================= " <<endl <<endl;

cout<<"Press any key to continue...."<<endl;

getche();

}

else

{

cout<<"ERROR: Wrong Credit Card Number entered"<<endl;

cout<<"Press any key to continue...."<<endl;

getche();

}

return pass;

};

int List_Dest()

{

string destcode;

int code;

ofstream x;

ifstream y;

y.open("destlist.txt");

while(!y.eof())

{

code=0;

destcode=" ";

y>>code>>destcode;

if(destcode!=" ")

cout<<code<<" "<<destcode<<endl;

}

y.close();

cout<<"Press any key to continue...."<<endl;

getche();

return pass;

} ;

int Open_Account()

{

ofstream myfile;

ifstream urfile;

//string n,i,c;

myfile.open ("booking.txt", ios::out | ios::app);

cout<<"Enter Name : ";

cin>>Name; //don't use space or looping will occur...

cout<<"Enter Credit Card Number: ";

cin>>Id;

cout<<" You entered "<<Id <<" as your credit Card Number"<<endl;

cout<<"Enter Destination Code : ";

cin>>Code;

//Display the reservation info

cout<< " =====RESERVATION INFORMATION===== " <<endl <<endl;

cout<<" Account Holder : "<<Name <<endl;

cout<<" Credit Card No : "<<Id <<" (Please remember this!)"<<endl;

cout<<" Destination Code : "<<Code <<endl;

cout<< " ============================= " <<endl;

cout<<"Press any key to continue...."<<endl;

myfile << Name<< "\t\t" << Id<< "\t\t" << Code <<endl;

myfile.close();

//getche();

return Id; } ;

double Disp_Reser()

{

string n,c;

//Display the reservation that have been made

cout<< " =====RESERVATION INFORMATION===== " <<endl <<endl;

cout<<" Account Holder : "<<Name <<endl;

cout<<" Destination Code : "<<Code <<endl;

cout<< " ============================= " <<endl <<endl;

cout<<"Press any key to continue...."<<endl;

getche();

return 0;

};

int Cancel_Reser()

{

cout<<"Enter Credit Card No : ";

cin>>pass;

Reservation::Valid_Id(pass);

if(Reservation::Valid_Id(pass)==1)

{

cout<< " =====RESERVATION INFORMATION===== " <<endl <<endl;

cout<<" Account Holder : "<<Name <<endl;

cout<<" Destination Code : "<<Code <<endl;

cout<< " ============================= " <<endl <<endl;

}

else

{

cout<<"ERROR: Wrong Credit Card Number entered"<<endl;

cout<<"This operation is cancelled" <<endl;

cout<<"Press any key to continue...."<<endl;

getche();

return 0;

}

cout <<" ::CONFIRMATION::\nAre you sure you want to cancel your reservation?"<<endl;

cout<<"[Y] : Yes || [N] : No ==>" ;

char confirm;

cin>>confirm;

if ( (confirm == 'Y') || (confirm=='y') ) //confirm before cancelling reservation

{ //Resetting the account of passanger....

Name= " -=please create an account first!=- ";

//Id = NULL;

// Code = " ";

//Done!

cout<<endl <<" ==== THE RESERVATION IS NOW CANCELLED ===" <<endl <<endl;

cout<<"Press any key to continue...."<<endl;

getche();

}

else

{ cout<<"Operation cancelled by user" <<endl;

cout<<"Press any key to continue...."<<endl;

getche();

return 0;

}

return pass;

};

}; //end of Reservation class declaration

int Reservation::Valid_Id(int verify) //simple algorithm to verify Id

{

if(verify!=Id)

{

return 0;

}

else

{

return 1;

}

}

Share this post


Link to post
Share on other sites

main.cpp

#include "reservation.h"

using namespace txt;

int main()
{
    Reservation z;
    z.Search_Account();

    system("pause");

    return 0;
}
 
reservation.cpp
#include "reservation.h"
#include <string>
#include <cstdlib>
#include <iostream>
#include <fstream>
#include <iomanip>
#include <vector>

using namespace std;
using namespace txt;

Reservation::Reservation()
{
    //ctor
}

Reservation::~Reservation()
{
    //dtor
}

void Reservation::Search_Account()
{

    fstream myfile;
    fstream myfile2;

    j = 0;
    i = 0;


    cout<<"enter string: ";
    cin>>s;

    myfile.open ("booking.txt", ios::in | ios::out);

    myfile.seekg(0);            // go to beginning of file
    while (myfile >> s1 >> id1 >> code1 )   //read the file line by line
    {
        i++;

        //push to stack
        s0.push_back(s1);
        id0.push_back(id1);
        code0.push_back(code1);
        if (s1 == s) j = i;     // if text found, j is not zero

    }

    myfile.close();

    if (j != 0 )    //text found, ask to delete the entry
    {

        --j;
        cout << s0[j] << " was found at line " <<  j << endl;
        cout << "delete this entry? y/n: ";
        char ch;
        cin >> ch;
        if (ch == 'y')
        {

            int k;
            //empty the file
            myfile.open ("booking.txt", ios::in | ios::out | ios::trunc);
            myfile.close();

            //write edited content
            myfile2.open ("booking.txt", ios::in | ios::out | ios::app);
            myfile.seekg(0);
            for (k = 0; k < (int)s0.size() - 1; k++)
            {
                //writing from vector except deleted line
                if (k != j) myfile2 << s0[k] << "\t\t" << id0[k] << "\t\t" << code0[k] << endl;
            }
        }
    }
    else cout << "\nrecord not found \n";

    myfile2.close();

};
reservation.h
#ifndef RESERVATION_H
#define RESERVATION_H
#include<string>
#include<vector>

using namespace std;

namespace txt
{
    class Reservation
    {

    private:
        string Name;
        int Id;
        int Pass;
        double Code;
        string s;
        int j;
        int i;
        string s1;
        int id1;
        double code1;

        vector<string> s0;
        vector<int> id0;
        vector<double> code0;



    public:
        Reservation();
        virtual ~Reservation();
        void Search_Account();

    protected:



    };
}
#endif // RESERVATION_H
sampel booking.txt
saya        432423        0
dasda        432432432    5
saya        4534        5
mamat        123456        1
86        865        0
jyrjr        75675        4
fds        4373360        0
tdrgd        4373360        0
t54        4353        5
hfghf        6546754        76
gdrgd        675        4

aku guna compiler msvc 2005 express

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
Sign in to follow this  

×
×
  • Create New...