#include <iostream>
#include <iomanip>
#include <string>
#include <cstdlib>
#include <fstream>
#include <vector>
#include "shortphone.cpp"
#include "shortname.cpp"
#include "shortaddress.cpp"
using namespace std;
class Record{
shortName Name;
shortAddress Address;
shortPhone Phone;
public:
void AddNewRecord();
void ViewRecord();
int FindRecord();
};
int menu()
{
int choice;
cout <<" Record List Processing System "<<endl;
cout <<"1. Add New Record "<<endl;
cout <<"2. Remove A Record Object from the list"<<endl;
cout <<"3. View all record object"<<endl;
cout <<"4. Find the object"<<endl;
cout <<"5. Exit"<<endl;
cin >> choice;
return choice;
}
/*void Record::InFile(ofstream fout)
{
string output = Name.getFirst();
fout.write((char*) &output, sizeof(Name.getSizeFirst()));
fout.write(output.c_str(), Name.getSizeFirst());
output = Name.getLast();
fout.write((char*) &output, sizeof(Name.getSizeLast()));
fout.write(output.c_str(), Name.getSizeLast());
}*/
void Record::AddNewRecord()
{
cin.ignore();
string input;
cout << "First Name :";
getline(cin,input,'\n');
Name.setFirst(input);
cout << "Last Name :";
getline(cin,input,'\n');
Name.setLast(input);
cout << "ID: :"; //Address
getline(cin,input,'\n');
Address.setID(input);
cout << "Street :";
getline(cin,input,'\n');
Address.setStreet(input);
cout << "City :";
getline(cin,input,'\n');
Address.setCity(input);
cout << "State :";
getline(cin,input,'\n');
Address.setState(input);
cout << "Zip :";
getline(cin,input,'\n');
Address.setZip(input);
cout << "Area Code :";
getline(cin,input,'\n');
Phone.setArea(input);
cout << "Telephone - Prefix :";
getline(cin,input,'\n');
Phone.setPrefix(input);
cout << "Telephone - Numbers:";
getline(cin,input,'\n');
Phone.setNumber(input);
input.erase();
}
void Record::ViewRecord()
{
cout << Name.getFirst() <<" " << Name.getLast() <<" ";
cout << Address.getID() <<" " << Address.getCity() <<" " << Address.getStreet() <<" " << Address.getState() <<" " << Address.getZip() <<setw(4) ;
cout << Phone.getArea() <<" " <<Phone.getPrefix() <<"-" << Phone.getNumber() <<endl;
}
int Record::FindRecord()
{
cin.ignore();
string input,last_name;
int i = 1;
last_name = Name.getLast();
cout <<"Enter the last name :";
getline(cin, input);
i=last_name.compare(input);
return i;
}
typedef vector<Record> SetRecord;
int main()
{
SetRecord GrowingRecord;
ofstream fout("info.dat", ios::binary|ios::app);
ifstream fin("info.dat", ios::binary);
for(;;){
int choice = menu();
switch(choice)
{
case(1):
{
Record Employee;
Employee.AddNewRecord();
GrowingRecord.push_back (Employee);
// Employee.InFile(fout);
break;
}
case(2):
{
int i,j;
cout <<"Index " << " Name " << setw(2) << " ID " << setw(2) << " Street " << setw(5) << " City " << setw(5) <<"State "<<setw(2) << " Telephone " <<endl;
for(i=0; i<GrowingRecord.size();i++)
{
Record Employee;
Employee = GrowingRecord;
cout << i << setw(2);
Employee.ViewRecord();
}
if(i==0){
cout <<"No Records Exist! "<<endl;
break;
}
cout << "Which record do you wish to delete (-1 to exit) ? (0-" << i-1 <<")" ;
cin >> j;
GrowingRecord.erase(GrowingRecord.begin()+j);
}
break;
case(3):
{
cout <<"Index " << " Name " << setw(2) << " ID " << setw(2) << " Street " << setw(5) << " City " << setw(5) <<"State "<<setw(2) << " Telephone " <<endl;
for(int i=0; i<GrowingRecord.size();i++)
{
Record Employee;
Employee = GrowingRecord;
cout << i << " ";
Employee.ViewRecord();
}
break;
}
case(4):
{
int j;
for(int i=0; i<GrowingRecord.size();i++)
{
Record Employee;
Employee = GrowingRecord;
if((j=Employee.FindRecord()==0)){
cout <<"Found !"<< "The data is located at " << i << "th data" <<endl; break;}
else
cout <<"Not Found !";
}
break;
}
case(5):
exit(1); break;
default:
cout <<"Error" << endl;
};
}
return 0;
}
ShortPhone Definition
#include <iostream>
using namespace std;
const string null = ""; //Define a constant null value...
class shortPhone {
string AreaCode;
string Prefix;
string Number;
public:
//Declare the constructors...
shortPhone();
shortPhone(string, string, string);
//Define the mutators...
void setArea(string Area) { AreaCode = Area; }
void setPrefix(string Pref) { Prefix = Pref; }
void setNumber(string Num) { Number = Num; }
//...and the accesors...
string getArea() { return AreaCode; }
string getPrefix() { return Prefix; }
string getNumber() { return Number; }
};
//Define the default constructor...
shortPhone::shortPhone()
{
AreaCode = null;
Prefix = null;
Number = null;
}
//Define the initializing one...
shortPhone::shortPhone(string Area, string Pre, string Num)
{
AreaCode = Area;
Prefix = Pre;
Number = Num;
}
#include <iostream>
#include <string>
#include <vector>
using namespace std;
//const string null; //Define a constant null value...
class shortName {
string firstName;
string lastName;
public:
//Declare the constructors...
shortName();
shortName(string, string);
//Define the mutator member functions...
void setFirst(string First) { firstName = First;}
void setLast(string Last) { lastName = Last;}
//...and some accessor functions
string getFirst() { return firstName;}
string getLast() { return lastName;}
int getSizeFirst() { return sizeof(firstName);}
int getSizeLast() { return sizeof(lastName);}
};
//Define the default constructor...
shortName::shortName()
{
firstName = "New First Name";
lastName = "New Last Name";
}
//...and the initializing one...
shortName::shortName(string First, string Last)
{
firstName = First;
lastName = Last;
}
#include <iostream>
#include <string>
#include <vector>
using namespace std;
//const string =0; //Define a constant null value...
class shortAddress {
string StreetID;
string StreetName;
string CityName;
string StateName;
string ZipCode;
public:
//Declare the constructors...
shortAddress();
shortAddress(string, string, string, string, string);
//Define the mutators...
void setID(string ID) { StreetID = ID; }
void setStreet(string Street) {StreetName = Street; }
void setCity(string City) { CityName = City; }
void setState(string State) { StateName = State; }
void setZip(string Zip) { ZipCode = Zip; }
//...and the accesors...
string getID() { return StreetID; }
string getStreet() { return StreetName; }
string getCity() { return CityName; }
string getState() { return StateName; }
string getZip() { return ZipCode; }
};
//Define the default constructor...
shortAddress::shortAddress()
{
StreetID = "New";
StreetName = "New";
CityName = "New";
StateName ="New";
ZipCode = "New";
}
//Define the initializing constructor...
shortAddress::shortAddress(string ID, string Street, string City, string State, string Zip)
{
StreetID = ID;
StreetName = Street;
CityName = City;
StateName = State;
ZipCode = Zip;
}
#include <iostream>
using namespace std;
const string null = ""; //Define a constant null value...
class shortPhone {
string AreaCode;
string Prefix;
string Number;
public:
//Declare the constructors...
shortPhone();
shortPhone(string, string, string);
//Define the mutators...
void setArea(string Area) { AreaCode = Area; }
void setPrefix(string Pref) { Prefix = Pref; }
void setNumber(string Num) { Number = Num; }
//...and the accesors...
string getArea() { return AreaCode; }
string getPrefix() { return Prefix; }
string getNumber() { return Number; }
};
//Define the default constructor...
shortPhone::shortPhone()
{
AreaCode = null;
Prefix = null;
Number = null;
}
//Define the initializing one...
shortPhone::shortPhone(string Area, string Pre, string Num)
{
AreaCode = Area;
Prefix = Pre;
Number = Num;
}