Sorting of records in the file

Hello friends
First of all i would like to thanks all who helped me for solving my password program problem in c++.I had a two problems 1.searching 2.sorting of records in the file from which first problem of searching the records is solved but Now i have a problem that's how to short a records in the file in c++.I also want to ask u Is there are any online full preview c++ book with free of cost which can i read for better understanding of c++.Try to understand my problem through Example.i downloaded the program the internet when i don't come to solution but this program also not working and is showing two errors.

#include
class emp
{
private:
int empno;
char name [20];
float salary;
public:
void get();
void display();
};
void emp::get()
{
cin>>empno>>name>>salary;
}
void emp::display()
{
cout< }

void show_recs(ifstream&);
int no_of_recs(ifstream&);

int main (void)
{
ifstream fin;
ofstream fout;
emp *ep,e,t;
int position,i,j,nor;

fin.open("emp.dat");
cout<<"\n Unsorted List of Employees \n";
show_recs(fin);

nor=no_of_recs(fin);
ep=new emp[nor];

i=0;
fin.seekg(0);
while(fin.read((char*)&e,sizeof(e)))
{
ep=e;
i++;
}
fin.close();

/* sorting begins */
for(i=0; i < nor; i++)
for(j=i+1; j < nor; j++)
if (ep.salary>ep[j].salary) //here two error showing 1. sorting.cpp 50: 'emp::salary' is is not accesible. 2.sorting.cpp 50: 'emp::salary' is not accesible
{
t=ep;
ep=ep[j];
ep[j]=t;
}

/* sorting ends */

fout.open("emps.dat");
for (i=0;i< nor;i++)
fout.write((char*)&ep,sizeof(ep));

fout.close();
cout<<"\n Sorted List of Employees in the increaseing order of salary \n";

fin.open("emps.dat");
show_recs(fin);
return 0;
}

int no_of_recs(ifstream& fin)
{
int last_byte,nor;
fin.seekg(0,ios::end);
last_byte=fin.tellg();
nor=last_byte/ sizeof(emp);
return nor;
}
void show_recs(ifstream& fin)
{
emp e;
while(fin.read((char*)&e,sizeof(e)))
e.display();
fin.clear();
}

Replies

  • bill190
    bill190
    1. The file or data needs to be in some sort of "format". Common are called fixed length, and comma delimited. More...
    Google

    2. Read about parsing data...
    Google

    3. Sorting algorithms...
    Google

    4. Sorting data is common with a database. Might want to read about how a database works. Also there is a thing called a "flat file database". More...
    Google
  • sumit_goel
    sumit_goel
    Thank you friend for giving response to my problem of sorting the file. But i think you don't understand my problem fully actually i want to ask how to sort the records within the file using class and without pointer.I'll try to understand my problem through example and i hope u definitely understand my problem and 'll help me solving the problem
  • Srikz
    Srikz
    Not exactly answering your main question here. But as for where you can get full preview books, Google Books have always been a great help to me. Be it licensed or unlicensed, you get a preview of the books. Though only some pages are visible and most of the problems hidden, nevertheless its a great way to take a peek inside almost any book.
    Other than this, i'm afraid i do not know of any other preview sites that host licensed books.
    What i find helpful is, find the right book for me with the content i'm able to understand through Google Books then either buy it or search for topics in plain Google. Helps a lot.

You are reading an archived discussion.

Related Posts

Hello Ceans ! I saw that many ceans are asking about the project or posting threads regarding the query in their project but no one replies back with the status...
Hi Guys, I have few doubts regarding Metallurgy. We are using Bearing Steel (EN-31 / SAE 52100) for manufacturing certain components. We are using commercial quality material from ISMT and...
hi folks, I am having Internet connection from BSNL and it frequently gets disconnected. I am using Ubuntu 10.0.4 and i use "wget" command to download file and if internet...
Hey people...i have a question regarding multiplexer. Implement the following function with a multiplexer f(A,B,C,D) = ∑(0,1,3,4,8,9,15)
Hi Friends, Its been long since I last posted on CE. Reason I was busy with my MBA after a successful CAT 08. Now that I have completed my course...