Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <cstring>
- using namespace std;
- struct pBook
- {
- char name[100];
- char surname[100];
- char adress[100];
- char pNumber[100];
- }*PhoneBook;
- void init(pBook *a, int &size);
- void addData(pBook*a, int size);
- pBook* add(pBook *a, int &size);
- void showFriendList(pBook *a, int size);
- void main()
- {
- int size = 1;
- PhoneBook = new pBook[size];
- init(PhoneBook, size);
- cout << "Your frined list." << endl << endl;
- showFriendList(PhoneBook, size);
- cout << "nnInfo about Oksana." << endl << endl;
- aboutOksana(PhoneBook, size);
- delete[]PhoneBook;
- cin.get();
- cin.get();
- }
- void init(pBook *a, int &size)
- {
- char s;
- do {
- addData(a, size);
- cout << "Wanna add new friend?ny/nn";
- cin >> s;
- cin.ignore();
- if (s == 'y') a = add(a, size);
- } while (s == 'y');
- }
- void addData(pBook*a, int size)
- {
- cout << "Enter name: ";
- gets_s(a[size - 1].name, 100);
- cout << "Enter surname: ";
- gets_s(a[size - 1].surname, 100);
- cout << "Enter adress: ";
- gets_s(a[size - 1].adress, 100);
- cout << "Enter phone-number: ";
- gets_s(a[size - 1].pNumber, 100);
- }
- pBook* add(pBook *a, int &size)
- {
- pBook *temp = new pBook[size];
- for (int i = 0; i < size; ++i) {
- strcpy_s(temp[i].name, strlen(a[i].name) + 1, a[i].name);
- strcpy_s(temp[i].surname, strlen(a[i].surname) + 1, a[i].surname);
- strcpy_s(temp[i].adress, strlen(a[i].adress) + 1, a[i].adress);
- strcpy_s(temp[i].pNumber, strlen(a[i].pNumber) + 1, a[i].pNumber);
- }
- delete[]a;
- size++;
- a = new pBook[size];
- for (int i = 0; i < size - 1; ++i) {
- strcpy_s(a[i].name, strlen(temp[i].name) + 1, temp[i].name);
- strcpy_s(a[i].surname, strlen(temp[i].surname) + 1, temp[i].surname);
- strcpy_s(a[i].adress, strlen(temp[i].adress) + 1, temp[i].adress);
- strcpy_s(a[i].pNumber, strlen(temp[i].pNumber) + 1, temp[i].pNumber);
- }
- delete[]temp;
- return a;
- }
- void showFriendList(pBook *a, int size)
- {
- for (int i = 0; i < size; ++i) {
- cout << i + 1 << ". ";
- cout << "Name = " << a[i].name << endl;
- cout << "Surname = " << a[i].surname << endl;
- cout << "Adress = " << a[i].adress << endl;
- cout << "Phone-number = " << a[i].pNumber << endl;
- cout << endl;
- }
- }
- #include <iostream>
- #include <cstring>
- using namespace std;
- struct pBook
- {
- char name[100];
- char surname[100];
- char adress[100];
- char pNumber[100];
- }*PhoneBook;
- pBook* init(pBook *a, int &size);
- pBook* addData(pBook*a, int size);
- pBook* add(pBook *a, int &size);
- void showFriendList(pBook *a, int size);
- void aboutOksana(pBook *a, int size);
- void main()
- {
- int size = 1;
- PhoneBook = new pBook[size];
- PhoneBook = init(PhoneBook, size);
- cout << "Your frined list." << endl << endl;
- showFriendList(PhoneBook, size);
- cout << "nnInfo about Oksana." << endl << endl;
- aboutOksana(PhoneBook, size);
- delete[]PhoneBook;
- cin.get();
- cin.get();
- }
- pBook* init(pBook *a, int &size)
- {
- char s;
- do {
- a = addData(a, size);
- cout << "Wanna add new friend?ny/nn";
- cin >> s;
- cin.ignore();
- if (s == 'y') a = add(a, size);
- } while (s == 'y');
- return a;
- }
- pBook* addData(pBook*a, int size)
- {
- cout << "Enter name: ";
- gets_s(a[size - 1].name, 100);
- cout << "Enter surname: ";
- gets_s(a[size - 1].surname, 100);
- cout << "Enter adress: ";
- gets_s(a[size - 1].adress, 100);
- cout << "Enter phone-number: ";
- gets_s(a[size - 1].pNumber, 100);
- return a;
- }
- pBook* add(pBook *a, int &size)
- {
- pBook *temp = new pBook[size];
- for (int i = 0; i < size; ++i) {
- strcpy_s(temp[i].name, strlen(a[i].name) + 1, a[i].name);
- strcpy_s(temp[i].surname, strlen(a[i].surname) + 1, a[i].surname);
- strcpy_s(temp[i].adress, strlen(a[i].adress) + 1, a[i].adress);
- strcpy_s(temp[i].pNumber, strlen(a[i].pNumber) + 1, a[i].pNumber);
- }
- delete[]a;
- size++;
- a = new pBook[size];
- for (int i = 0; i < size - 1; ++i) {
- strcpy_s(a[i].name, strlen(temp[i].name) + 1, temp[i].name);
- strcpy_s(a[i].surname, strlen(temp[i].surname) + 1, temp[i].surname);
- strcpy_s(a[i].adress, strlen(temp[i].adress) + 1, temp[i].adress);
- strcpy_s(a[i].pNumber, strlen(temp[i].pNumber) + 1, temp[i].pNumber);
- }
- delete[]temp;
- return a;
- }
- void showFriendList(pBook *a, int size)
- {
- for (int i = 0; i < size; ++i) {
- cout << i + 1 << ". ";
- cout << "Name = " << a[i].name << endl;
- cout << "Surname = " << a[i].surname << endl;
- cout << "Adress = " << a[i].adress << endl;
- cout << "Phone-number = " << a[i].pNumber << endl;
- cout << endl;
- }
- }
- void aboutOksana(pBook *a, int size)
- {
- for (int i = 0; i < size; ++i) {
- if (strcmp(a[i].name, "Oksana") == 0) {
- cout << "Info about " << a[i].name << " " << a[i].surname << endl;
- cout << "Name = " << a[i].name << endl;
- cout << "Surname = " << a[i].surname << endl;
- cout << "Adress = " << a[i].adress << endl;
- cout << "Phone-number = " << a[i].pNumber << endl;
- cout << endl;
- }
- }
- }
- #include <iostream>
- #include <cstring>
- using namespace std;
- struct pBook
- {
- char name [100];
- char surname[100];
- char adress [100];
- char pNumber[100];
- };
- void fill(pBook*&a, int &size);
- void addData(pBook*&a, int &size);
- void showFriendList(pBook *a, int size);
- int main()
- {
- pBook* PhoneBook = nullptr;
- int PhoneBookSize = 0;
- fill(PhoneBook, PhoneBookSize);
- cout << "Your frined list." << endl << endl;
- showFriendList(PhoneBook, PhoneBookSize);
- //cout << "nnInfo about Oksana." << endl << endl;
- //aboutOksana(PhoneBook, size);
- delete[] PhoneBook;
- cin.get();
- }
- void fill(pBook*&a, int &size)
- {
- for(char s = 'y'; s == 'y'; (cin >> s).ignore())
- {
- addData(a,size);
- cout << "Wanna add new friend?ny/nn";
- };
- }
- void readString(const char * prompt, char * field, int size = 100)
- {
- cout << "Enter " << prompt << ": ";
- gets_s(field, size);
- }
- void addData(pBook*&a, int& size)
- {
- pBook *temp = new pBook[size+1];
- if (a) memcpy(temp,a,sizeof(pBook)*size);
- delete[] a;
- a = temp;
- readString("name", a[size].name);
- readString("surname", a[size].surname);
- readString("address", a[size].adress);
- readString("phone-number",a[size].pNumber);
- ++size;
- }
- void showFriendList(pBook *a, int size)
- {
- for (int i = 0; i < size; ++i) {
- cout << i + 1 << ". ";
- cout << "Name = " << a[i].name << endl;
- cout << "Surname = " << a[i].surname << endl;
- cout << "Adress = " << a[i].adress << endl;
- cout << "Phone-number = " << a[i].pNumber << endl;
- cout << endl;
- }
- }
Add Comment
Please, Sign In to add comment