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
|
#include <iostream>
#include <stdlib.h>
#include <fstream>
#include <bits/stdc++.h>
using namespace std;
typedef string ElementType;
class Node
{
private:
ElementType first, mid, last, phone;
Node *next;
friend class List;
//Constructors
public:
Node(ElementType f, ElementType mi, ElementType sur, ElementType ph){
first = f;
mid = mi;
last = sur;
phone = ph;
next = NULL;
};
Node* getNext(){
return next;
}
//Mutator function
void printNode(){
cout << first << " " << mid << " " << last << " " << phone;
}
//Accessor
bool sameAs(Node *q){
return (first == q->first && mid == q->mid && last == q->last && phone == q->phone);
}
};
typedef Node* NodePointer;
//This class can create a list.
class List {
private:
Node* first;
public:
List(){
first = NULL;
}
NodePointer getFirst(){
return first;
};
void insert(ElementType fir, ElementType midd, ElementType las, ElementType phon, NodePointer pos){
NodePointer pN;
pN = new Node(fir, midd, las, phon);
NodePointer last = first;
if (first == NULL){
first = pN;
return;
}
else{
while(last->next != NULL){
last = last->next;
}
last->next = pN;
}
}
//This function reads data (contacts) from a file and puts each line into a list.
void readData(List &L) {
ElementType fi, mi, la, ph, ph1, ph2;
ifstream fin;
fin.open("dadexcel.txt");
while(!fin.eof()){
fin >> fi >> mi >> la >> ph >> ph1 >> ph2;
ph = ph + " " + ph1 + " " + ph2;
L.insert(fi, mi, la, ph, L.getFirst());
}
}
//This function prints out the nodes in a list
void printContactList(){
NodePointer pN;
for(pN = first; pN != NULL; pN = pN->next){
pN->printNode();
cout << endl;
}
}
};
//Main function
int main()
{
List R;
readData(R);
R.printContactList();
return 0;
}
| |