Click here to Skip to main content
15,896,267 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
AnswerRe: #define question Pin
Richard MacCutchan7-Apr-12 1:36
mveRichard MacCutchan7-Apr-12 1:36 
AnswerRe: #define question Pin
Randor 7-Apr-12 6:51
professional Randor 7-Apr-12 6:51 
GeneralRe: #define question Pin
_Flaviu7-Apr-12 9:14
_Flaviu7-Apr-12 9:14 
GeneralRe: #define question Pin
Randor 7-Apr-12 19:25
professional Randor 7-Apr-12 19:25 
Questionline algorithm in borland c++ Pin
matarz6-Apr-12 13:31
matarz6-Apr-12 13:31 
AnswerRe: line algorithm in borland c++ Pin
David Crow6-Apr-12 15:31
David Crow6-Apr-12 15:31 
AnswerRe: line algorithm in borland c++ Pin
Luc Pattyn6-Apr-12 16:12
sitebuilderLuc Pattyn6-Apr-12 16:12 
Questionread/writing Linked List to a random access file in c++ Pin
djgmad6-Apr-12 12:47
djgmad6-Apr-12 12:47 
Below is what my driver looks like I'm trying to read/write data from a singly linked list to random access file in c++ but thus far I'm unable to do so....any help in solving this problem would greatly appreciated.


#include"List.h"
#include "Employer.h"


void InitialEmployerRan()
{
int count; //counter for loop
int me=20; //max number of employees
ofstream RanFile("Employer.dat",ios::out |ios::binary);
if (RanFile)
{
//Enter the total number of employees
cout <<"\nEnter maximum number of emplyees ";
cin >> me;
//create an object with default data
Employer obj;
//Initialise employees file with me records
for(count = 0; count < me; ++count)
{
RanFile.write(reinterpret_cast <const char="" *="">(&obj),sizeof(Employer));
}
} else
{
cerr <<"file was not fond";
}
}

//display program instruction to user
void instruction()
{
cout <<"Enter ont of the following:\n"
<<"1 to insert at front\n"
<<"2 to delete from front\n";
}//end function instruction

template<typename t="">
void TestList(List<t> &listObject)
{
instruction();//display instruction
int choice;//store user choice
T value;
Employer emp;
string fname,lname,address,pos,Cname,email ;
int cel, hom, id;






do{
cout <<"enterchoice";
cin >> choice;

system("cls");
switch(choice)
{

case 1:










cout<<"Enter Data: "<<endl;
="" cout<<"id:";
="" fflush(stdin);
="" cin="">> id;
cout <<"\nEnter employeer's first name ";
fflush(stdin);
cin >> fname;
fflush(stdin);
cout <<"\nEnter employeer's last name ";
fflush(stdin);
cin >> lname;
cout <<"\nEnter employeer's jop Title ";
fflush(stdin);
getline(cin,pos) ;
cout <<"\nEnter employeer's email ";
fflush(stdin);
cin >> email;
cout << "\nEnter name of company";
fflush(stdin);
getline(cin,Cname);
cout << "\nEnter employeer addreess";
fflush(stdin);
getline(cin,address);
cout <<"Enter Employer cell number ";
fflush(stdin);
cin>>cel;
cout <<"Enter Empolyer home number ";
fflush(stdin);
cin>>hom;









listObject.insertInFront(Employer(fname,lname,address,pos,Cname,email ,cel,hom,id));
//listObject.print();


break;




case 2:
if(listObject.removeFromFront(value))
cout << value <<" remove from list\n";
listObject.print();
break;


}
}while(choice < 3);

CreateList(listObject,id);
DisplayEmployeeRan(listObject);
}
template<typename p="">
void CreateList(List

&listObject2,int i)
{

Employer emp;

fstream RanFile("Employer.dat",ios::in | ios::out |ios::binary);
if (RanFile)
{
while(!listObject2.isEmpty())

{
RanFile.seekp(sizeof(Employer) * (i- 1));
RanFile.write(reinterpret_cast< const char *>(&emp),sizeof(Employer));
cout<<"file was updated";
break;

}
}
else
{

cerr<<"Error the file was not found";
}

}
template<typename t="">
void DisplayEmployeeRan(List<t> &listObject3)
{
char ans; //answer to store 'y' or 'n'
Employer emp;
int in;
ifstream RanFile("Employer.dat",ios::in |ios::binary);
if (RanFile)
{
while ( !listObject3.isEmpty( ))
{
cout <<"\nEnter employee's id number to"<< " display ";
cin >> in;
RanFile.seekg(sizeof(Employer) *(in - 1));
RanFile.read(reinterpret_cast<char *=""> (&emp),sizeof(Employer));

//if not eof show data
if(! RanFile.eof())
{
//Display the processed
// info for the employee

listObject3.print();

} cout << "Display another "<<"employee's information? [y/n] ";
fflush(stdin);
ans = ' ';
while (ans != 'y' && ans != 'Y'
&& ans != 'n' && ans != 'N')
{
ans = _getch();
} cout << endl;
if (ans == 'n' || ans == 'N')
{
exit(1);
}
}
} else
{
cout <<"Error - random files could not be opened.";
}
}





int main()
{
// InitialEmployerRan();
List <employer> EmpList;
TestList(EmpList);


system("Pause");
return 0;
}


AnswerRe: read/writing Linked List to a random access file in c++ Pin
David Crow6-Apr-12 15:34
David Crow6-Apr-12 15:34 
GeneralRe: read/writing Linked List to a random access file in c++ Pin
djgmad8-Apr-12 3:04
djgmad8-Apr-12 3:04 
GeneralRe: read/writing Linked List to a random access file in c++ Pin
David Crow8-Apr-12 16:28
David Crow8-Apr-12 16:28 
AnswerRe: read/writing Linked List to a random access file in c++ Pin
Richard MacCutchan6-Apr-12 22:01
mveRichard MacCutchan6-Apr-12 22:01 
GeneralRe: read/writing Linked List to a random access file in c++ Pin
djgmad8-Apr-12 3:09
djgmad8-Apr-12 3:09 
GeneralRe: read/writing Linked List to a random access file in c++ Pin
Richard MacCutchan8-Apr-12 6:01
mveRichard MacCutchan8-Apr-12 6:01 
Questionmenubar icons (win32) Pin
sadas232341s6-Apr-12 6:45
sadas232341s6-Apr-12 6:45 
SuggestionRe: menubar icons (win32) Pin
David Crow6-Apr-12 10:32
David Crow6-Apr-12 10:32 
Questionwriting a wave file to currecnt directory from buffer Pin
Member 87012356-Apr-12 4:32
Member 87012356-Apr-12 4:32 
AnswerRe: writing a wave file to currecnt directory from buffer Pin
David Crow6-Apr-12 4:37
David Crow6-Apr-12 4:37 
GeneralRe: writing a wave file to currecnt directory from buffer Pin
Member 87012358-Apr-12 21:11
Member 87012358-Apr-12 21:11 
QuestionLoad image from Open Dialog Pin
sadas232341s6-Apr-12 3:36
sadas232341s6-Apr-12 3:36 
QuestionRe: Load image from Open Dialog Pin
David Crow6-Apr-12 3:53
David Crow6-Apr-12 3:53 
QuestionDate Time Picker Strange Behavior in Windows 7 Pin
softwaremonkey5-Apr-12 20:57
softwaremonkey5-Apr-12 20:57 
GeneralRe: Date Time Picker Strange Behavior in Windows 7 Pin
David Crow6-Apr-12 2:41
David Crow6-Apr-12 2:41 
QuestionUnable To Tackle MoveWindow() Pin
AmbiguousName5-Apr-12 19:51
AmbiguousName5-Apr-12 19:51 
AnswerRe: Unable To Tackle MoveWindow() Pin
Code-o-mat6-Apr-12 2:16
Code-o-mat6-Apr-12 2:16 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.