Модераторы: bsa
  

Поиск:

Ответ в темуСоздание новой темы Создание опроса
> Дерево, Описать массив записей в виде дерева  
:(
    Опции темы
TLandertinger
Дата 18.7.2014, 11:45 (ссылка) | (нет голосов) Загрузка ... Загрузка ... Быстрая цитата Цитата


Новичок



Профиль
Группа: Участник
Сообщений: 5
Регистрация: 18.7.2014

Репутация: нет
Всего: нет



Здравствуйте. У меня возникли проблемы. Вот задание:
Описать массив записей "семья".
--------------------------------------------------------------
   Отец     !    Мать    !   Ребенок  !           !   Ребенок
---------------------------------------            -----------
Ф.И.О.!дата !Ф.И.О.!дата ! Имя  !дата !   ......  ! Имя  !дата
          !рожд.!          !рожд.!        !рожд.!          !         !рожд.
---------------------------------------------------------------
                         !__________________ ________________!
                                        не более 5 детей

Найти и вывести имя младшего ребенка у Иванова И.И. по форме
_______________________________
имя ребенка  ! дата рождения   !
--------------------------------------------------
Я практически сделал, но у меня выходят ошибки(описание ошибок в скриншоте). k_min -- переменная, отвечающая за хранение номера самого младшего ребенка у Иванова И.И. Она как бы не нужна. Вот строка:  

Цитата
202 printf("!  %10s  ! %2d.%2d.%4d !\n", young->family.ch[k_min].name_of_child, young->family.ch[k_min].d_birth_child.day, young->family.ch[k_min].d_birth_child.month, young->family.ch[k_min].d_birth_child.year); 

Чем ее заменить? Заранее спасибо. Среда c++ visual studio 2010. Компилятор консольный CLR.


Присоединённый файл ( Кол-во скачиваний: 7 )
Присоединённый файл  Безымянный2.png 36,28 Kb
PM MAIL   Вверх
TLandertinger
Дата 18.7.2014, 11:45 (ссылка) | (нет голосов) Загрузка ... Загрузка ... Быстрая цитата Цитата


Новичок



Профиль
Группа: Участник
Сообщений: 5
Регистрация: 18.7.2014

Репутация: нет
Всего: нет



Вот мой код.
Код
// laba 12-1.cpp: главный файл проекта.
#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;

}; 

struct TreeNode
{
    int k;
    T_family family;
    Children ch[5];
    TreeNode *next;
    TreeNode *child;
};

class date_of_birth
{
private:
    TreeNode *head;
public:
date_of_birth()
    {
        head = new TreeNode;
        TreeNode *node1 = new TreeNode;
        node1->k = 1;
        node1->child = NULL;
        node1->next = NULL;
        head->child = node1;
        TreeNode *node2 = new TreeNode;
        node2->k = 2;
        node2->child = NULL;
        node2->next = NULL;
        node1->next = node2;
        TreeNode *node3 = new TreeNode;
        node3->k = 3;
        node3->child = NULL;
        node3->next = NULL;
        node2->next = node3;
        T_family a = {"Ivanov I. I.", 21,5,1965,"Ivanova E.G.",13,2,1967,"Oleg",19,7,1994,"Olga",13,8,1996};
        TreeNode *nodeA = new TreeNode;
        nodeA->family = a;
        nodeA->child = NULL;
        nodeA->next = NULL;
        node1->child = nodeA;
        T_family b = {"Petrov P. P.", 12,4,1962,"Petrova E.O.",8,12,1965,"Pavel",12,4,1988,"Ekaterina",24,8,1992};
        TreeNode *nodeB = new TreeNode;
        nodeB->family = b;
        nodeB->child = NULL;
        nodeB->next = NULL;
        node2->child = nodeB;
}

void add_node(int i)
    {
    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 >> a.ch[k].d_birth_child.year;
        cin.get(c); 
    }

      TreeNode *node = head->child;
        while(true)
        {
            if(node->k == a.k)
            {
                TreeNode *newNode = new TreeNode;
                newNode->family = a;
                newNode->child = NULL;
                newNode->next = NULL;
                if(node->child == NULL)
                    node->child = newNode;
                else    
                {
                    TreeNode *elem = node->child;
                    while(elem->next != NULL)
                        elem = elem->next;
                    elem->next = newNode;
                }
                return;
            }
            if(node->next == NULL)
                break;
            node = node->next;
        }

        TreeNode *newNode = new TreeNode;
        newNode->k = a.k;
        newNode->child = NULL;
        newNode->next = NULL;
        node->next = newNode;
        TreeNode *nodeA = new TreeNode;
        nodeA->family = a;
        nodeA->child = NULL;
        nodeA->next = NULL;
        newNode->child = nodeA;
    }

void print_tree()
    {
        printf("[ \n");
        TreeNode *node = head->child;
        while(node != NULL)
        {
            cout << " --> " << node->k << endl;
            if(node->child != NULL)
            {
                TreeNode *child = node->child;
                while(child != NULL)
                {
                printf("! %10s ! %2d.%2d.%4d !",child->family.fio_father, child->family.d_birth_father.day, child->family.d_birth_father.month, child->family.d_birth_father.year);
                printf("! %10s ! %2d.%2d.%4d !",child->family.fio_mother, child->family.d_birth_mother.day, child->family.d_birth_father.month, child->family.d_birth_father.year);
                for (int k = 0; k < child->family.k ; k++) {
                printf("! %10s ! %2d.%2d.%4d!", child->family.ch[k].name_of_child, child->family.ch[k].d_birth_child.day, child->family.ch[k].d_birth_child.month, child->family.ch[k].d_birth_child.year);
                printf("\n");
    }
                    child = child->next;
                }
            }
            node = node->next;
        }
        printf("]\n");
    }

void find_min()
    {
        TreeNode *node = head->child;
        TreeNode *young = node->child;
        while(node != NULL)
        {
            if(node->k < young->k && node->child != NULL)
                young = node->child;
            node = node->next;
        }
printf("!  %10s  ! %2d.%2d.%4d !\n", young->family.ch[k_min].name_of_child, young->family.ch[k_min].d_birth_child.day, young->family.ch[k_min].d_birth_child.month, young->family.ch[k_min].d_birth_child.year);
    }
};

int main()
{
    date_of_birth d;
    for(int i = 2; i < 4; i++)
    {    
        d.add_node(i);
    };
    cout << "\nlist of structs\n!       father        !       mother        !        child        !\n";
    d.print_tree();
    d.find_min();
    _getch();
    return 0;
}


Модератор: в следующий раз сам выкладывай свой код в таком виде - кнопка "Код"

Это сообщение отредактировал(а) bsa - 18.7.2014, 14:08
PM MAIL   Вверх
bsa
Дата 18.7.2014, 14:12 (ссылка) | (нет голосов) Загрузка ... Загрузка ... Быстрая цитата Цитата


Эксперт
****


Профиль
Группа: Модератор
Сообщений: 9185
Регистрация: 6.4.2006
Где: Москва, Россия

Репутация: 85
Всего: 196



Цитата(TLandertinger @  18.7.2014,  12:45 Найти цитируемый пост)
 k_min -- переменная, отвечающая за хранение номера самого младшего ребенка у Иванова И.И. Она как бы не нужна.
Где эта "как бы ненужная переменная" объявлена? Где ей присвоено значение? В С/С++ нельзя использовать необъявленные переменные.
PM   Вверх
  
Ответ в темуСоздание новой темы Создание опроса
Правила форума "C/C++: Для новичков"
JackYF
bsa

Запрещается!

1. Публиковать ссылки на вскрытые компоненты

2. Обсуждать взлом компонентов и делиться вскрытыми компонентами

  • Действия модераторов можно обсудить здесь
  • С просьбами о написании курсовой, реферата и т.п. обращаться сюда
  • Вопросы по реализации алгоритмов рассматриваются здесь


Если Вам понравилась атмосфера форума, заходите к нам чаще! С уважением, JackYF, bsa.

 
0 Пользователей читают эту тему (0 Гостей и 0 Скрытых Пользователей)
0 Пользователей:
« Предыдущая тема | C/C++: Для новичков | Следующая тема »


 




[ Время генерации скрипта: 0.0686 ]   [ Использовано запросов: 22 ]   [ GZIP включён ]


Реклама на сайте     Информационное спонсорство

 
По вопросам размещения рекламы пишите на vladimir(sobaka)vingrad.ru
Отказ от ответственности     Powered by Invision Power Board(R) 1.3 © 2003  IPS, Inc.