Здравствуйте. У меня возникли проблемы. Вот задание:
Описать массив записей "семья".
--------------------------------------------------------------
Отец ! Мать ! Ребенок ! ! Ребенок
--------------------------------------- -----------
Ф.И.О.!дата !Ф.И.О.!дата ! Имя !дата ! ...... ! Имя !дата
!рожд.! !рожд.! !рожд.! ! !рожд.
---------------------------------------------------------------
!__________________ ________________!
не более 5 детей
Найти и вывести имя младшего ребенка у Иванова И.И. по форме
_______________________________
имя ребенка ! дата рождения !
--------------------------------
У меня получилась какая-то непонятка (см.скриншот). Может быть, где-нить цикл забыл?
Вот код:
Код:
#include "stdafx.h"
#include "iostream"
#include "conio.h"
using namespace std;
struct Date
{
unsigned day;
unsigned month;
unsigned year;
};
struct Children
{
char name_of_child[30];
Date d_birth_child;
};
struct T_family
{
char fio_father[30];
Date d_birth_father;
char fio_mother[30];
Date d_birth_mother;
Children ch[5];
int k;
};
int top=0,smax;
class date_of_birth
{
// Сам стек
private:
T_family *stack;
// Его вершина и максимум
public:
// Функция помещения в стек
void push(int i)
{
bool st=false;
//Если не превышает пределы стека то норм, иначе вернуть false
if (top==smax) st=false;
// Просим ввести данные
int count;
T_family a;
char c;
cout << endl << " Enter data of" << i+1 << "person\n ";
cout << " fio of father ";
cin.getline(a.fio_father, 30);
cout << "Enter date of father's birthday: \n";
cout << " day (1-31) ";
cin >> a.d_birth_father.day;
cin.get(c);
cout << " month (1-12)";
cin >> a.d_birth_father.month;
cin.get(c);
cout << " year ";
cin >> a.d_birth_father.year;
cin.get(c);
cout << " fio of mother ";
cin.getline(a.fio_mother, 30);
cout << endl <<"Enter date of mother's birthday: \n";
cout <<" day (1-31) ";
cin >> a.d_birth_mother.day;
cin.get(c);
cout << " month (1-12)";
cin >> a.d_birth_mother.month;
cin.get(c);
cout << " year ";
cin >> a.d_birth_mother.year;
cin.get(c);
//запросить кол-во детей и запомнить в count
cout << "Enter count of children" << endl;
cin >> count;
cin.get(c);
if ((count > 5) && (count < 0)) cout << " Fatal error " << endl;
a.k = count;
for (int k=0; k < count; k++) {
cout << endl << " Name of " " " << k+1 << " " " child ";
cin.getline(a.ch[k].name_of_child, 30);
cout << endl << "Enter date of" " "<< k+1 << " " "child's birthday: \n";
cout <<" day (1-31) ";
cin >> a.ch[k].d_birth_child.day;
cin.get(c);
cout << " month (1-12)";
cin >> a.ch[k].d_birth_child.month;
cin.get(c);
cout << " year ";
cin >> stack[top++].ch[k].d_birth_child.year;
cin.get(c);
}
st=true;
}
void print()
{
printf("! %10s ! %2d.%2d.%4d !",stack[top].fio_father, stack[top].d_birth_father.day, stack[top].d_birth_father.month, stack[top].d_birth_father.year);
printf("! %10s ! %2d.%2d.%4d !",stack[top].fio_mother, stack[top].d_birth_mother.day, stack[top].d_birth_mother.month, stack[top].d_birth_mother.year);
for (int k = 0; k < stack[top].k ; k++) {
printf("! %10s ! %2d.%2d.%4d!", stack[top].ch[k].name_of_child, stack[top].ch[k].d_birth_child.day, stack[top].ch[k].d_birth_child.month, stack[top].ch[k].d_birth_child.year);
printf("\n");
}
}
void search()
{
int k_min = 0;
if(strcmp(stack[top].fio_father, "Ivanov I.I.") == 0 )
{
for (int k = 0; k < stack[top].k; k++){
if (stack[top].ch[k].d_birth_child.year > stack[top].ch[k_min].d_birth_child.year) {
k_min=k;
}
else if (stack[top].ch[k].d_birth_child.year == stack[top].ch[k_min].d_birth_child.year)
{
if (stack[top].ch[k].d_birth_child.month > stack[top].ch[k_min].d_birth_child.month) {
k_min=k;
}
else if (stack[top].ch[k].d_birth_child.month == stack[top].ch[k_min].d_birth_child.month)
if (stack[top].ch[k].d_birth_child.day > stack[top].ch[k_min].d_birth_child.day) {
k_min=k;
}
}
break;
}
}
printf("\n\n! %10s ! %2d.%2d.%4d !\n", stack[top].ch[k_min].name_of_child, stack[top].ch[k_min].d_birth_child.day, stack[top].ch[k_min].d_birth_child.month, stack[top].ch[k_min].d_birth_child.year);
}
};