Guest User

Untitled

a guest
Apr 24th, 2018
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.80 KB | None | 0 0
  1. #include <iostream>
  2. #include <cstring>
  3. using namespace std;
  4.  
  5. struct pBook
  6. {
  7. char name[100];
  8. char surname[100];
  9. char adress[100];
  10. char pNumber[100];
  11. }*PhoneBook;
  12.  
  13. void init(pBook *a, int &size);
  14. void addData(pBook*a, int size);
  15. pBook* add(pBook *a, int &size);
  16. void showFriendList(pBook *a, int size);
  17.  
  18. void main()
  19. {
  20. int size = 1;
  21. PhoneBook = new pBook[size];
  22. init(PhoneBook, size);
  23. cout << "Your frined list." << endl << endl;
  24. showFriendList(PhoneBook, size);
  25. cout << "nnInfo about Oksana." << endl << endl;
  26. aboutOksana(PhoneBook, size);
  27. delete[]PhoneBook;
  28. cin.get();
  29. cin.get();
  30. }
  31.  
  32. void init(pBook *a, int &size)
  33. {
  34. char s;
  35. do {
  36. addData(a, size);
  37. cout << "Wanna add new friend?ny/nn";
  38. cin >> s;
  39. cin.ignore();
  40. if (s == 'y') a = add(a, size);
  41. } while (s == 'y');
  42. }
  43.  
  44. void addData(pBook*a, int size)
  45. {
  46. cout << "Enter name: ";
  47. gets_s(a[size - 1].name, 100);
  48. cout << "Enter surname: ";
  49. gets_s(a[size - 1].surname, 100);
  50. cout << "Enter adress: ";
  51. gets_s(a[size - 1].adress, 100);
  52. cout << "Enter phone-number: ";
  53. gets_s(a[size - 1].pNumber, 100);
  54. }
  55.  
  56. pBook* add(pBook *a, int &size)
  57. {
  58. pBook *temp = new pBook[size];
  59. for (int i = 0; i < size; ++i) {
  60. strcpy_s(temp[i].name, strlen(a[i].name) + 1, a[i].name);
  61. strcpy_s(temp[i].surname, strlen(a[i].surname) + 1, a[i].surname);
  62. strcpy_s(temp[i].adress, strlen(a[i].adress) + 1, a[i].adress);
  63. strcpy_s(temp[i].pNumber, strlen(a[i].pNumber) + 1, a[i].pNumber);
  64. }
  65. delete[]a;
  66. size++;
  67. a = new pBook[size];
  68. for (int i = 0; i < size - 1; ++i) {
  69. strcpy_s(a[i].name, strlen(temp[i].name) + 1, temp[i].name);
  70. strcpy_s(a[i].surname, strlen(temp[i].surname) + 1, temp[i].surname);
  71. strcpy_s(a[i].adress, strlen(temp[i].adress) + 1, temp[i].adress);
  72. strcpy_s(a[i].pNumber, strlen(temp[i].pNumber) + 1, temp[i].pNumber);
  73. }
  74. delete[]temp;
  75. return a;
  76. }
  77.  
  78. void showFriendList(pBook *a, int size)
  79. {
  80. for (int i = 0; i < size; ++i) {
  81. cout << i + 1 << ". ";
  82. cout << "Name = " << a[i].name << endl;
  83. cout << "Surname = " << a[i].surname << endl;
  84. cout << "Adress = " << a[i].adress << endl;
  85. cout << "Phone-number = " << a[i].pNumber << endl;
  86. cout << endl;
  87. }
  88. }
  89.  
  90. #include <iostream>
  91. #include <cstring>
  92. using namespace std;
  93.  
  94. struct pBook
  95. {
  96. char name[100];
  97. char surname[100];
  98. char adress[100];
  99. char pNumber[100];
  100. }*PhoneBook;
  101.  
  102. pBook* init(pBook *a, int &size);
  103. pBook* addData(pBook*a, int size);
  104. pBook* add(pBook *a, int &size);
  105. void showFriendList(pBook *a, int size);
  106. void aboutOksana(pBook *a, int size);
  107.  
  108. void main()
  109. {
  110. int size = 1;
  111. PhoneBook = new pBook[size];
  112. PhoneBook = init(PhoneBook, size);
  113. cout << "Your frined list." << endl << endl;
  114. showFriendList(PhoneBook, size);
  115. cout << "nnInfo about Oksana." << endl << endl;
  116. aboutOksana(PhoneBook, size);
  117. delete[]PhoneBook;
  118. cin.get();
  119. cin.get();
  120. }
  121.  
  122. pBook* init(pBook *a, int &size)
  123. {
  124. char s;
  125. do {
  126. a = addData(a, size);
  127. cout << "Wanna add new friend?ny/nn";
  128. cin >> s;
  129. cin.ignore();
  130. if (s == 'y') a = add(a, size);
  131. } while (s == 'y');
  132. return a;
  133. }
  134.  
  135. pBook* addData(pBook*a, int size)
  136. {
  137. cout << "Enter name: ";
  138. gets_s(a[size - 1].name, 100);
  139. cout << "Enter surname: ";
  140. gets_s(a[size - 1].surname, 100);
  141. cout << "Enter adress: ";
  142. gets_s(a[size - 1].adress, 100);
  143. cout << "Enter phone-number: ";
  144. gets_s(a[size - 1].pNumber, 100);
  145. return a;
  146. }
  147.  
  148. pBook* add(pBook *a, int &size)
  149. {
  150. pBook *temp = new pBook[size];
  151. for (int i = 0; i < size; ++i) {
  152. strcpy_s(temp[i].name, strlen(a[i].name) + 1, a[i].name);
  153. strcpy_s(temp[i].surname, strlen(a[i].surname) + 1, a[i].surname);
  154. strcpy_s(temp[i].adress, strlen(a[i].adress) + 1, a[i].adress);
  155. strcpy_s(temp[i].pNumber, strlen(a[i].pNumber) + 1, a[i].pNumber);
  156. }
  157. delete[]a;
  158. size++;
  159. a = new pBook[size];
  160. for (int i = 0; i < size - 1; ++i) {
  161. strcpy_s(a[i].name, strlen(temp[i].name) + 1, temp[i].name);
  162. strcpy_s(a[i].surname, strlen(temp[i].surname) + 1, temp[i].surname);
  163. strcpy_s(a[i].adress, strlen(temp[i].adress) + 1, temp[i].adress);
  164. strcpy_s(a[i].pNumber, strlen(temp[i].pNumber) + 1, temp[i].pNumber);
  165. }
  166. delete[]temp;
  167. return a;
  168. }
  169.  
  170. void showFriendList(pBook *a, int size)
  171. {
  172. for (int i = 0; i < size; ++i) {
  173. cout << i + 1 << ". ";
  174. cout << "Name = " << a[i].name << endl;
  175. cout << "Surname = " << a[i].surname << endl;
  176. cout << "Adress = " << a[i].adress << endl;
  177. cout << "Phone-number = " << a[i].pNumber << endl;
  178. cout << endl;
  179. }
  180. }
  181.  
  182. void aboutOksana(pBook *a, int size)
  183. {
  184. for (int i = 0; i < size; ++i) {
  185. if (strcmp(a[i].name, "Oksana") == 0) {
  186. cout << "Info about " << a[i].name << " " << a[i].surname << endl;
  187. cout << "Name = " << a[i].name << endl;
  188. cout << "Surname = " << a[i].surname << endl;
  189. cout << "Adress = " << a[i].adress << endl;
  190. cout << "Phone-number = " << a[i].pNumber << endl;
  191. cout << endl;
  192. }
  193. }
  194. }
  195.  
  196. #include <iostream>
  197. #include <cstring>
  198. using namespace std;
  199.  
  200. struct pBook
  201. {
  202. char name [100];
  203. char surname[100];
  204. char adress [100];
  205. char pNumber[100];
  206. };
  207.  
  208. void fill(pBook*&a, int &size);
  209. void addData(pBook*&a, int &size);
  210. void showFriendList(pBook *a, int size);
  211.  
  212. int main()
  213. {
  214. pBook* PhoneBook = nullptr;
  215. int PhoneBookSize = 0;
  216. fill(PhoneBook, PhoneBookSize);
  217. cout << "Your frined list." << endl << endl;
  218. showFriendList(PhoneBook, PhoneBookSize);
  219. //cout << "nnInfo about Oksana." << endl << endl;
  220. //aboutOksana(PhoneBook, size);
  221. delete[] PhoneBook;
  222. cin.get();
  223. }
  224.  
  225. void fill(pBook*&a, int &size)
  226. {
  227. for(char s = 'y'; s == 'y'; (cin >> s).ignore())
  228. {
  229. addData(a,size);
  230. cout << "Wanna add new friend?ny/nn";
  231. };
  232. }
  233.  
  234. void readString(const char * prompt, char * field, int size = 100)
  235. {
  236. cout << "Enter " << prompt << ": ";
  237. gets_s(field, size);
  238. }
  239.  
  240. void addData(pBook*&a, int& size)
  241. {
  242. pBook *temp = new pBook[size+1];
  243. if (a) memcpy(temp,a,sizeof(pBook)*size);
  244. delete[] a;
  245. a = temp;
  246.  
  247. readString("name", a[size].name);
  248. readString("surname", a[size].surname);
  249. readString("address", a[size].adress);
  250. readString("phone-number",a[size].pNumber);
  251.  
  252. ++size;
  253. }
  254.  
  255.  
  256. void showFriendList(pBook *a, int size)
  257. {
  258. for (int i = 0; i < size; ++i) {
  259. cout << i + 1 << ". ";
  260. cout << "Name = " << a[i].name << endl;
  261. cout << "Surname = " << a[i].surname << endl;
  262. cout << "Adress = " << a[i].adress << endl;
  263. cout << "Phone-number = " << a[i].pNumber << endl;
  264. cout << endl;
  265. }
  266. }
Add Comment
Please, Sign In to add comment