Untitled
unknown
plain_text
3 years ago
1.7 kB
9
Indexable
#include <iostream>
#include <string>
using namespace std;
int main() {
string name[30], surname[30], phone_number[30];
int index = 0, choice;
while (true) {
cout << "1 - добавить контакт" << endl;
cout << "2 - показать контакт по индексу" << endl;
cout << "0 - выход" << endl;
cin >> choice;
if (choice == 0) break;
if (choice == 1) {
if (index >= 30) {
cout << "Телефонная книга полна!" << endl;
continue;
}
cout << "Введите имя: ";
cin >> name[index];
cout << "Введите фамилию: ";
cin >> surname[index];
cout << "Введите номер телефона: ";
cin >> phone_number[index];
index++;
} else if (choice == 2) {
if (index == 0) {
cout << "Телефонная книга пуста!" << endl;
continue;
}
int i;
cout << "Введите индекс (1-" << index << "): ";
cin >> i;
i--;
if (i < 0 || i >= index) {
cout << "Неверный индекс!" << endl;
continue;
}
cout << "ФИО: " << name[i] << " " << surname[i] << endl;
cout << "Номер телефона: " << phone_number[i] << endl;
} else {
cout << "Неверный выбор!" << endl;
}
}
return 0;
}Editor is loading...