THIS IS WORKING PROGRAM..NEED HELP TO CONVERT IT INTO OBJECT ORIENTED.
#include <iostream>
#include <fstream>
#include <string>
using namespace std;
#define MAX 50
int main()
{
int cnt = 0, k, i;
char temp[31];
char name[MAX][31], phonenum[MAX][21];
fstream infile("phone.txt");
if (infile.fail())
{
cerr << "Failed to open data file\n";
return 1;
}
// Read phone records from the file into arrays.
while (! infile.eof())
{
infile >> name[cnt] >> phonenum[cnt];
++cnt;
} // while
infile.close(); // close the data file
// Sort the records in alphabetical order by names.
for (i=0; i < cnt-1; ++i)
for (k=i+1; k<cnt; ++k)
if (strcmp(name[i], name[k]) > 0)
{ /* swap */
strcpy(temp, name[i]);
strcpy(name[i], name[k]);
strcpy(name[k], temp);
strcpy(temp, phonenum[i]);
strcpy(phonenum[i], phonenum[k]);
strcpy(phonenum[k], temp);
}
// Display the sorted records.
for (k=0; k < cnt; ++k)
cout << name[k] << " " << phonenum[k] << endl;
// Sort the records in ascending order by phone numbers.
for (i=0; i < cnt-1; ++i)
for (k=i+1; k<cnt; ++k)
if (strcmp(phonenum[i], phonenum[k]) > 0)
{ /* swap */
strcpy(temp, name[i]);
strcpy(name[i], name[k]);
strcpy(name[k], temp);
strcpy(temp, phonenum[i]);
strcpy(phonenum[i], phonenum[k]);
strcpy(phonenum[k], temp);
}
// Display the sorted records.
for (k=0; k < cnt; ++k)
cout << name[k] << " " << phonenum[k] << endl;
for one convert your char arrays to strings and use the corresponding string methods for the C-style string fcns. That is all I can see at the moment. also use [ c o d e ] [ / c o d e] tags (w/out spaces)