The task:
Create a program "List of students of the group", in which are specified - Last name, first name, gender, place of birth, year of birth. Need to generate files:
- The list of boys born in the city whose name is entered from the keyboard
- List of girls
- List of students born in the year that is entered from the keyboard. files to organize.
My question is this- How do I make the simultaneous use of two conditions with an object.
That is, using the function, finding only boys and the desired city. Here is the code itself, the functions with the object are all there (they are commented out)
#include <iostream> #include <string> using namespace std; struct Student //Структура Студент { char Family[35]; //Фамилия студента char Name[35]; //Имя студента char Sex[20]; //Пол студента char City[100]; //Город рождения студента int Date[3]; //Дата рождения студента void Show(); //Функция будет отображать данные студента void Input(); //Функция ввода данных в структуру void Gorod();// Город void Year(const int Date1, const int Date2);//год }; void Student::Input() { cout << "\n\n"; cout << "Family\t\t"; cin.getline(Family, 35); //Считали фамилию cout << "Name \t\t"; cin.getline(Name, 35); //Считали имя int k; cout << "Sex chouse 1=Male ,2 =Female \t\t";//Выбираем пол cin >> k; if (k == 1) strcpy(Sex, "Male"); else strcpy(Sex, "Female"); cout << "Date born\t"; cin >> Date[0]; //cin.ignore(); cin >> Date[1]; //cin.ignore(); cin >> Date[2]; cin.ignore(); cout << "City\t\t"; cin.getline(City, 100); cout << "\n\n"; cout << "======================\n"; } void Student::Show() //Функция показывает данные структуры на экране { cout << Name << " " << Family << "\n" << "Sex: " << Sex << "\nBorn in " << Date[0] << "." << Date[1] << "." << Date[2] << "\n"; cout << "In the city which is called " << City << "\n\n"; } void Student::Gorod() { char s1[20]; cout << "\nВедите нужный город:"; gets(s1); if (strcmp(s1, City) == 0) { cout << "\nГорода одинаковые записываем в файл" << endl; } else { cout << "\nГорода разные не записываем в файл" << endl; } } void Student::Year(const int Date1, const int Date2) //Внутри функции ничего менять не планируется, поэтому константы { if ((Date[2]>Date1) && (Date[2]<Date2)) Show(); //Проверка принадлежности диапазону и при вхождении в диапазон вывод элемента структуры на экран }; int prompt_menu_item() { // Выбранный вариант меню int variant; cout << "Choose you variant\n" << endl; cout << "1. Men born in towns\n" //список юношей родившихся в городе, вводим с клавы << "2. Only girls\n" //только девушки << "3. All students born in years\n" //список всех студентов родившихся в годах с какого то по какой то, вводим с клавы << "4. Open file\n" << endl; cout << ">>> "; cin >> variant; return variant; } int main() { ////////ЭТО НУЖНЫЕ ФУНКЦИИ// //for (int i = 0; i < N; i++) Student[i].Show(); //С помощью цикла показываем заполненную структуру на экране, вызывая метод структуры. //for (int i = 0; i < N; i++) Student[i].Gorod();// C помощью цикла показываем нужные города //for (int i = 0; i < N; i++) // if (strcmp(Student[i].Sex, "Male") == 0) // Student[i].Show(); //С помощью цикла показываем всех мальчиков. //for (int i = 0; i < N; i++) // if (strcmp(Student[i].Sex, "Female") == 0) // Student[i].Show(); //С помощью цикла показываем всех девочек. /////////////////// const int N = 2; //Количество элементов в структуре Student Student[N]; //Структура студентов из N элементов. (Справа объект, слева тип) for (int i = 0; i < N; i++) Student[i].Input(); //С помощью цикла заполняем структуру, вызывая метод структуры. setlocale(LC_ALL, "Rus"); int variant = prompt_menu_item(); switch (variant) { case 1: for (int i = 0; i < N; i++) if (strcmp(Student[i].Sex, "Male") == 0) Student[i].Show()&& for (int i = 0; i < N; i++) Student[i].Gorod(); system("pause"); break; int o, p; cout << "Enter need yaers\t"; cin >> o; cin >> p; // ввод нужных годов for (int i = 0; i < N; i++) Student[i].Year(o, p); //Выводим студентов, которые родились в нужные года cin.get(); system("pause"); } }