извените! прошу помочь! Весь запутался со вторым пунктом - "Поиск" во втором кэйсе Вобщем, команда "Поиск" запрашивает фамилию и выводит телефон, если же в справочнике есть люди с одинаковыми фамилиями, то выводиться список всех этих людей.
Как это грамотно прописать ?!!
| Цитата | #include "stdafx.h" #include <locale> #include <iostream> #include <conio.h> #include <fstream> using namespace std;
int _tmain(int argc, _TCHAR* argv[]) { setlocale(0,".1251"); int instr,defa=0,num=1; char fam[15],name[10],phone[8]; char s[20]; //FILE *p; cout << "1 - Добавить \n2 - Поиск\n3 - Справочник\n4 - Выход\n" << endl; cout << "Введите команду: "; cin >> instr; cout << endl; while (defa!=1) { switch (instr) { case 1: { system("cls"); cout << " ________" << endl << " Добавить" << endl << " ________\n\n" << endl; cout << "Введите данные. Пример - [ Фамилия: Петров Имя: Олег Номер: 56-34-22 ]\n"<< endl; cout << " Фамилия: ";setlocale(0,".866"); cin >> fam;setlocale(0,".1251"); cout << " Имя: ";setlocale(0,".866"); cin >> name; setlocale(0,".1251"); cout << " Номер: "; cin >> phone; cout << "\n\nДобавлена запись: "; setlocale(0,".866"); cout << fam << " " << name << " ----- " << phone << "\n"; ofstream out("d://derevo.txt",ios::app); setlocale(0,".1251"); out << fam << " " << name << " " << phone << "\n"; //setlocale(0,".866"); out << flush; //setlocale(0,".1251"); cout << "\n ---------------- \n| |\n"; cout << "| 1 - Добавить |\n| 2 - Поиск |\n| 3 - Справочник |\n| 4 - Выход |\n| |" << endl; cout << " ---------------- \n\n"; cout << endl << " Выберите пункт меню (1-4):"; cin >> instr; if (1>=instr<=4) continue; else break; } case 2: { system("cls"); cout << " _____" << endl << " Поиск" << endl << " _____" << endl; cout << "\n ---------------- \n| |\n"; cout << "| 1 - Добавить |\n| 2 - Поиск |\n| 3 - Справочник |\n| 4 - Выход |\n| |" << endl; cout << " ---------------- \n"; cout << endl << " Выберите пункт меню (1-4):"; cin >> instr; if (1>=instr<=4) continue; else break; } case 3: { system("cls"); cout << " __________" << endl << " Справочник" << endl << " __________" << endl; cout << "\n\n\n"; ifstream in("d://derevo.txt"); while (!in.eof()) { if (in.eof()) cout << num << ") "; num++; setlocale(0,".866"); for(int i=0;i<3;i++) { in >> s; cout << s << " "; } cout << endl; setlocale(0,".1251"); } num=1; in.close(); cout << "\n ---------------- \n| |\n"; cout << "| 1 - Добавить |\n| 2 - Поиск |\n| 3 - Справочник |\n| 4 - Выход |\n| |" << endl; cout << " ---------------- \n"; cout << endl << " Выберите пункт меню (1-4):"; cin >> instr; if (1>=instr<=4) continue; else break; } case 4: { system("cls"); cout << " _____" << endl << " Выход" << endl << " _____" << endl; cout << "\n\n\n"; break; } default: { cout << "Не верная команда\n"; cout << "Повторите попытку: "; cin >> instr; cout << endl; continue; } } if (4>=instr<=1) break; } //system("cls"); return 0; }
|
|