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
|
#include <iostream>
#include <stdlib.h>
#include <fstream>
#include <sstream>
using namespace std;
typedef string ElementType;
class Node
{
private:
ElementType first, mid, last, phone;
Node *next;
friend class List;
public:
Node(ElementType f, ElementType mi, ElementType sur, ElementType ph){
first = f;
mid = mi;
last = sur;
phone = ph;
next = nullptr;
};
void printNode(){
cout << first << " " << mid << " " << last << " " << phone;
}
};
typedef Node* NodePointer;
/*--------------------------------------------------------------*/
class List {
private:
Node* first;
public:
List(){
first = nullptr;
}
NodePointer getFirst(){
return first;
};
/*--------------------------------------------------------*/
void insert(ElementType fir, ElementType midd, ElementType las, ElementType phon, NodePointer pos){
NodePointer pN;
if(pos == first){
pN = new Node(fir, midd, las, phon);
pN->next = pos;
first = pN;
}
else{
pN = new Node(fir, midd, las, phon);
pN->next = pos->next;
pos->next = pN;
}
}
/*--------------------------------------------------------------*/
void printContactList(){
NodePointer pN;
for(pN = first; pN != nullptr; pN = pN->next){
pN->printNode();
cout << endl;
}
}
};
/*--------------------------------------------------------------*/
void readData(){
List L;
ElementType fi, mi, la, ph, ph1, ph2;
ifstream fin;
fin.open("C:\\Users\\owner\\Documents\\contacts.txt");
while(!fin.eof()){
fin >> fi >> mi >>la >> ph >> ph1 >> ph2;
ph = ph + " " + ph1 + " "+ ph2;
L.insert(fi, mi, la, ph, L.getFirst());
}
L.printContactList();
}
/*--------------------------------------------------------------*/
int main()
{
readData();
return 0;
}
|