Incorrectly displays the date of birth and telephone in the table, as well as displays data on the last name request

Describe the structure named NOTE2, containing the fields: Name - last name and initials, TELE - phone number, DATE - date of birth (year, month, date).

Write a program that performs:

  • input from the keyboard data in the array BLOCK2, consisting of 7 elements of type NOTE1, the records must be ordered by last name in alphabetical order;
  • displaying information about a person whose last name was entered from the keyboard;
  • if there is none, give a message.

Incorrectly displays the date of birth and telephone in the table, and also displays incorrect data for the last name after the table.

Tell me what is the error?

#include "stdafx.h" #include <iostream> #include <cstring> #include <conio.h> #include <cstdlib> #define M 15 #define N 7 #pragma warning(disable : 4996)// Ρ‡Ρ‚ΠΎΠ±Ρ‹ компилятор Π½Π΅ ругался Π½Π° strcpy using namespace std; struct NOTE2 { char name[M]; int num; char date[M]; }; int main() { setlocale(0, "rus"); NOTE2 BLOCK2[N]; int i; for (i = 0; i < N; i++) { cout << "\nΠ’Π²Π΅Π΄ΠΈΡ‚Π΅ имя: "; cin >> BLOCK2[i].name; cout << "\nΠ’Π²Π΅Π΄ΠΈΡ‚Π΅ Π½ΠΎΠΌΠ΅Ρ€ Ρ‚Π΅Π»Π΅Ρ„ΠΎΠ½Π°: "; cin >> BLOCK2[i].num; cout << "\nΠ’Π²Π΅Π΄ΠΈΡ‚Π΅ Π΄Π°Ρ‚Ρƒ роТдСния: "; cin >> BLOCK2[i].date; } char cur[M]; for (i = 0; i<N - 1; i++) for (int j = i + 1; j<N; j++) if (strcmp(BLOCK2[i].name, BLOCK2[j].name)>0) { strcpy(cur, BLOCK2[i].name); strcpy(BLOCK2[i].name, BLOCK2[j].name); strcpy(BLOCK2[j].name, cur); } cout << "\n ________________________________________________________\n"; for (i = 0; i < N; i++) { cout << BLOCK2[i].name << " " << BLOCK2[i].num << " " << BLOCK2[i].date << endl; } cout << "\n ________________________________________________________\n"; char temp[M]; int count; while (strcmp(temp, "exit")) { cout << "\nΠ’Π²Π΅Π΄ΠΈΡ‚Π΅ Ρ„Π°ΠΌΠΈΠ»ΠΈΡŽ: "; cin >> temp; count = 0; for (i = 0; i < N; i++) { if (strcmp(BLOCK2[i].date, temp) == 0) { cout << endl << BLOCK2[i].name << " " << BLOCK2[i].num << endl; count++; } } if (count == 0) cout << endl << " НСт Ρ‚Π°ΠΊΠΎΠΉ Ρ„Π°ΠΌΠΈΠ»ΠΈΠΈ\n"; } _getch(); } 
  • Debugging done? - MBo
  • Enter the surname, and compare with the date: strcmp(BLOCK2[i].date, temp) - acade
  • Corrected, now displays the name. but sorting alphabetically in 1 point, in the table it incorrectly selects the date and phone, and when entering the name of interest, the data is also incorrect. I will attach a screen now - msmv
  • Look at your sorting: you change only the name. And about the rest of the field forgotten. Date and number also need to change. - acade

0