Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <fstream>
- #include <vector>
- #include <sstream>
- #include <string>
- /** Файл містить дані: прізвище, адреса, телефон. Відсортувати прізвищами в
- алфавітному порядку, використавши список, а при наявності однакових прізвищ
- відсортувати адреси теж в алфавітному порядку. Здійснити пошук абонента за
- номером телефону..**/
- using namespace std;
- struct UserInformation {
- string name;
- string address;
- int phone;
- };
- void conclusion(UserInformation &information);
- int main() {
- //database
- vector<UserInformation> base;
- UserInformation temporaryStructure;
- //import file
- ifstream file;
- file.open("..\\tess.txt");
- //File open check
- if (!file.is_open()) {
- cout << "ERROR\n\n";
- return 1;
- }
- //read line by line and write to database
- string line;
- while (getline(file, line)) {
- stringstream word(line);
- word >> temporaryStructure.name;
- word >> temporaryStructure.address;
- word >> temporaryStructure.phone;
- base.push_back(temporaryStructure);
- }
- for (int g = 0; g < base.size() - 1; ++g) {
- for (int i = 0; i < base.size() - 1; ++i) {
- for (int j = 0; j < base[i].name.length(); ++j) {
- cout << int(base[i].name[j]) << " > " << int(base[i + 1].name[j]) << endl;
- if (base[i].name[j] > base[i + 1].name[j]) {
- cout << "[1]" << endl; //?????
- swap(base[i], base[i + 1]);
- break;
- } else if (base[i].name[j] < base[i + 1].name[j]) {
- break;
- }
- }
- }
- }
- for (int g = 0; g < base.size() - 1; ++g) {
- for (int i = 0; i < base.size() - 1; ++i) {
- if (base[i].name == base[i + 1].name) {
- for (int j = 0; j < base[i].address.length(); ++j) {
- cout << int(base[i].address[j]) << " > " << int(base[i + 1].address[j]) << endl;
- if (base[i].address[j] > base[i + 1].address[j]) {
- cout << "[1]" << endl; //?????
- swap(base[i], base[i + 1]);
- break;
- } else if (base[i].address[j] < base[i + 1].address[j]) {
- break;
- }
- }
- }
- }
- }
- for (int i = 0; i < base.size(); ++i) {
- conclusion(base[i]);
- }
- }
- void conclusion(UserInformation &information) {
- cout << information.name << " "
- << information.address << " "
- << information.phone << " "
- << endl;
- }
Advertisement
Add Comment
Please, Sign In to add comment