1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146
|
#include <iostream>
#include <cmath>
#include <fstream>
#include <string>
using namespace std;
class Person{
protected:
char* Name;
char* SurName;
public:
Person( char *Name, char* SurName){
Set(Name,SurName);
}
void Set( char *Name, char* SurName){
SetName(Name);
SetSurName(SurName);
}
void SetName( char *Name){
this->Name=Name;
}
void SetSurName( char* SurName){
this->SurName=SurName;
}
char *GetName(){
return Name;
}
char *GetSurName(){
return SurName;
}
};
class Abon:public Person{
protected:
char* PhNum;
public:
Abon( char *Name,
char *Surname,
char* PhNum) : Person(Name, Surname){
SetPhNum(PhNum);
}
void SetPhNum(char* PhNum){
this->PhNum=PhNum;
}
char* GetNum(){
return PhNum;
}
};
class Citizen:public Abon{
protected:
char *IdNum;
char *Addr;
public:
Citizen( char *Name=" ",
char *SurName=" ",
char *PhNum=" ",
char *Addr=" ",
char *IdNum=" "): Abon(Name,SurName,PhNum){
Set(IdNum,Addr);
}
void Set(char *IdNum, char* Addr){
SetId(IdNum);
SetAddr(Addr);
}
void SetId(char* IdNum){
this->IdNum=IdNum;
}
void SetAddr(char* Addr){
this->Addr=Addr;
}
char* GetAddr(){
return this->Addr;
}
char* GetIdNum(){
return this->IdNum;
}
};
class ContactList{
private:
const char *FileName;
public:
ContactList(const char *MyFileName){
this->FileName=MyFileName;
}
void WriteData(Citizen PPL){
fstream MyData;
MyData.open (FileName,std::fstream::app);
MyData<<PPL.GetName()<<";"<<PPL.GetSurName()<<";"
<<PPL.GetNum()<<";"<<PPL.GetIdNum()<<";"<<PPL.GetAddr()<<";"<<endl;
MyData.close();
}
Citizen ReadData(){
Citizen TMP=Citizen();
string s;
string Sign=";";
fstream f(FileName, fstream::in );
getline( f, s, '\n');
f.close();
////////////////////////
size_t pos = 0;
string token;
pos = s.find(Sign);
token = s.substr(0, pos);
char* A=strdup(token.c_str());;
TMP.SetName(A);
s.erase(0, pos + Sign.length());
pos = s.find(Sign);
token = s.substr(0, pos);
TMP.SetSurName(token);
s.erase(0, pos + Sign.length());
pos = s.find(Sign);
token = s.substr(0, pos);
TMP.SetId(token);
s.erase(0, pos + Sign.length());
pos = s.find(Sign);
token = s.substr(0, pos);
TMP.SetPhNum(token);
s.erase(0, pos + Sign.length());
pos = s.find(Sign);
token = s.substr(0, pos);
TMP.SetAddr(token);
s.erase(0, pos + Sign.length());
return TMP;
}
};
int main(int argc, char** argv) {
Citizen CTZ=Citizen("name","surname","12345","New York","54612");
ContactList Friend=ContactList("Friends.txt");
Friend.WriteData(CTZ);
Friend.ReadData();
return 0;
}
| |