Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <fstream>
- #include <cstring>
- using namespace std;
- class Znak {
- public:
- char name[255] = {};
- char surname[255] = "";
- int zodiac;
- int birthday[3] = {};
- void Input() {
- cout << "Имя: ";
- cin.getline(name, 255);
- cout << "Фамилия: ";
- cin.getline(surname, 255);
- cout << "Номер знака зодиака: ";
- cin >> zodiac;
- cout << "День рождения: " << endl;
- cout << "День: "; cin >> birthday[0];
- cout << "Месяц: "; cin >> birthday[1];
- cout << "Год: "; cin >> birthday[2];
- cin.ignore(255, '\n');
- }
- void Output(char* str) {
- cout << str << endl;
- }
- void Write(ofstream &out) {
- out << name << " " << surname << " " << zodiac << " " << birthday[0] << '.'
- << birthday[1] << '.'
- << birthday[2] << endl;
- }
- void Read(ifstream &in, char* str) {
- in.getline(str, 255);
- }
- };
- void swap(Znak &f, Znak &s) {
- if(&f == &s) {
- return;
- }
- Znak tmp;
- memcpy(&tmp, &s, sizeof(Znak));
- memcpy(&s, &f, sizeof(Znak));
- memcpy(&f, &tmp, sizeof(Znak));
- }
- void sort(Znak a[], const int N) {
- for(int i = 0; i < N; i++) {
- int k = i;
- for(int j = i + 1; j < N; j++) {
- if(a[j].zodiac < a[k].zodiac) {
- k = j;
- }
- }
- swap(a[k], a[i]);
- }
- }
- int main() {
- const int n = 8;
- Znak znak[n];
- for(int i = 0; i < n; i++) {
- znak[i].Input();
- }
- sort(znak, n);
- ofstream out("/root/znaki.txt", ios::trunc | ios::out);
- for(int i = 0; i < n; i++) {
- znak[i].Write(out);
- }
- ifstream in("/root/znaki.txt", ios::in);
- char str[255] = {};
- for(int i = 0; i < n; i++) {
- znak[i].Read(in, str);
- znak[i].Output(str);
- }
- in.seekg(0);
- int m, c = 0;
- cout << "Введите номер месяца: ";
- cin >> m;
- for(int i = 0; i < n; i++) {
- znak[i].Read(in, str);
- if(znak[i].birthday[1] == m) {
- znak[i].Output(str);
- c++;
- }
- }
- if(c == 0) {
- cout << "Человека, родившегося в этот месяц, нет";
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement