Question:
write Program to create binary file of employee?
2009-05-04 02:59:19 UTC
write Program created a binary file of employees where each employee has name, ID and salary. The program should keep on reading employees hnformation from the key board until the user enters -1 as employee ID
after creating the file as explained above , the program should sort the employees according to the descending order of their salaries . The program should display a list of three option to sort the file and then user chooses one of the ways (1,2 or 3) to sort the file as follows:
1. sort the file on hard disk (without using array).
2. sort the file in main memory (use an array) , without modifying the file . (i.e. do not copy the array back to the file).
3. sort the file in main memory (same as #2) and copy the array back to the file.
wherever way the user chooses the sorted employees information should be displayed on screen
Four answers:
ɔıM.is.ME!
2009-05-04 03:10:11 UTC
someones not doing their comp sci hw. ask ur teacher cause your gonna need to know how to do it someday.
karljj1
2009-05-07 08:49:30 UTC
You might have a better response if you at least made an attempt.



What area are you having problems with?



Here is some help on creating a binary file.



#include // A File stream class

#include // good for storing text



....



std::fstream file;

file.open( "File.type", ios::binary | ios::out ); // data will be written/read as bnary.



// Writing the first line of the file.



std::string ExampleName = "Joe";

int ExampleID = 123;

int Example Salary = 30000;



// Write it to file



file << ExampleName << ExampleID << Salary;



// The data has now been written to the file



// To read the file

std::fstream fileIn;

fileIn.open( "File.Type", ios::in | ios::binary );



string sName;

int iID, iSal;



while( fileIn >> sName >> iID >> iSal )

{

// Reads each line of the file, now you can stick them into an array as you loop.

}
2009-05-04 03:03:04 UTC
So, you're asking someone to code a program for you? For free? Not a chance.
?
2016-05-26 12:32:56 UTC
Use a structure pFile = fopen ( "data.bin" , "wb" ); fwrite (thestructure, 1 , sizeof(thestructure) , pFile );


This content was originally posted on Y! Answers, a Q&A website that shut down in 2021.
Loading...