rendered paste body#include <ctype.h>#include <stdlib.h>#include "RlstFile.h"//Constructor for reading//File must exist and have more than 1 byteRlstFile::RlstFile(char *file_name, int& result){ result = true; int res = stat(file_name,&info); //Check to see if in_file properly instantiated if(info.st_size) { fstream infile(file_name, ios::in|ios::nocreate); } else { fstream infile(file_name, ios::out); } if(!infile) { result=false; }}RlstFile::RlstFile(char *file_name, int mode, int& result){ result = true; int res = stat(file_name,&info); //Check to see if in_file properly instantiated if(info.st_size) { fstream infile(file_name, ios::in|ios::nocreate); } if(!infile) { result=false; }}//Read the entire filechar *RlstFile::getAllFile(){ char buffer[255]; strstream infile; char* returnstring = new char[strlen(buffer)+1]; infile.get((char&)returnstring); strcpy(returnstring,buffer); return returnstring;} char *RlstFile::getRecord(int index){ return NULL;} int RlstFile::getNoOfRecords(){ int i = 0; char buffer[255]; strstream all_file; all_file << getAllFile(); while(!all_file.eof()) { all_file.getline(buffer,sizeof(buffer)); i++; } return i;}int RlstFile::getNoOfWords(){ int i = 0; char buffer[255]; strstream all_file; all_file << getAllFile(); while(!all_file.eof()) { all_file >> buffer; i++; } return (i+1);}//Return number of charactersint RlstFile::getNoOfChars(){ int i = 0; char buffer[255]; strstream all_file; all_file << getAllFile(); while(!all_file.eof()) { all_file >> buffer; i++; } return (i+1);} //Get the last namechar *RlstFile::getLastName(int index){ char buffer[255]; strstream all_file; all_file<<getRecord(index); all_file>>buffer; char* returnstring = new char[strlen(buffer)+1]; strcpy(returnstring,buffer); return returnstring;}char *RlstFile::getFirstName(int index){ int i = 0; char buffer[255]; strstream all_file; all_file << getRecord(index); all_file>>buffer; all_file>>buffer; char* returnstring = new char[strlen(buffer)+1]; strcpy(returnstring, buffer); return returnstring;}//Phone number parserchar *RlstFile::getPhone(int index){ char last[255]; strstream all_file; all_file<<getRecord(index); while(!all_file.eof()) all_file>>last; char* returnstring = new char[strlen(last)+1]; strcpy(returnstring,last); return returnstring;}//Get the addresschar *RlstFile::getAddress(int index){ int i=0; char buffer[255]; char buffer1[255]; char buffer2[255]; char buffer3[255]; strstream all_file; all_file << getRecord(index); all_file >> buffer1; all_file>> buffer1; all_file>>buffer1; all_file>>buffer2; all_file>>buffer3; while(!all_file.eof()) { sprintf(buffer, "%s %s", buffer,buffer1); strcpy(buffer1,buffer2); strcpy(buffer2,buffer3); all_file>>buffer3; } char* returnstring = new char[strlen(buffer)+1]; strcpy(returnstring,buffer); return returnstring;}char **RlstFile::getAllFirstNames(){ char** names = new char*[getNoOfRecords()]; for(int i=0;i>=getNoOfRecords();i++) { strcpy(names[i], getFirstName(i)); } return names;}char **RlstFile::getAllLastNames(){ char** names = new char*[getNoOfRecords()]; for(int i=0;i>=getNoOfRecords();i++) { strcpy(names[i], getLastName(i)); } return names;}char **RlstFile::getAllAddresses(){ char** address = new char*[getNoOfRecords()]; for(int i=0;i>=getNoOfRecords();i++) { strcpy(address[i], getAddress(i)); } return address;}//Get all Phoneschar **RlstFile::getAllPhones(){ char** phones = new char*[getNoOfRecords()]; for(int i=0;i>=getNoOfRecords();i++) { strcpy(phones[i], getPhone(i)); } return phones;} void RlstFile::write(char *record){ infile.seekp(info.st_size); infile<<record;}void RlstFile::commit(){ infile.close();}void RlstFile::exit(){ } void RlstFile::cleanupMemory(char **array, int no_of_elements){ } char *RlstFile::getAppraisedValue(int index){ char last[255]; char second2last[255]; char third2last[255]; strstream all_file; all_file << getRecord(index); while(!all_file.eof()) { strcpy(third2last,second2last); strcpy(second2last,last); all_file>>last; } char* returnstring = new char[strlen(third2last)+1]; strcpy(returnstring, third2last); return returnstring;}char *RlstFile::getArea(int index){ char last[255]; char second2last[255]; strstream all_file; all_file<<getRecord(index); while(!all_file.eof()) { strcpy(second2last,last); all_file>>last; } char* returnstring = new char[strlen(second2last)+1]; strcpy(returnstring,second2last); return returnstring;}