Форум программистов
 

Восстановите пароль или Зарегистрируйтесь на форуме, о проблемах и с заказом рекламы пишите сюда - alarforum@yandex.ru, проверяйте папку спам!

Вернуться   Форум программистов > C/C++ программирование > Общие вопросы C/C++
Регистрация

Восстановить пароль
Повторная активизация e-mail

Купить рекламу на форуме - 42 тыс руб за месяц

Ответ
 
Опции темы Поиск в этой теме
Старый 10.10.2014, 18:31   #1
TLandertinger
Пользователь
 
Регистрация: 09.05.2013
Сообщений: 29
По умолчанию Стек

Здравствуйте. У меня возникли проблемы. Вот задание:
Описать массив записей "семья".
--------------------------------------------------------------
Отец ! Мать ! Ребенок ! ! Ребенок
--------------------------------------- -----------
Ф.И.О.!дата !Ф.И.О.!дата ! Имя !дата ! ...... ! Имя !дата
!рожд.! !рожд.! !рожд.! ! !рожд.
---------------------------------------------------------------
!__________________ ________________!
не более 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);
  }
};
Изображения
Тип файла: jpg Безымянный.jpg (50.6 Кб, 38 просмотров)
TLandertinger вне форума Ответить с цитированием
Старый 10.10.2014, 18:31   #2
TLandertinger
Пользователь
 
Регистрация: 09.05.2013
Сообщений: 29
По умолчанию

Код:
int main()
{
	cout << "       Avtor – Shusharin A.V., student gr. ISEbd-11" << endl;
	cout << "       Variant N 1" << endl;
	cout << "       Programma sozdaet massiv structur, zapolnaet ego dannimi i vivodit na ekran etot massiv v vide tablici"  << endl;
	cout << "       Programma opredelaet i vivodit imya mladshego rebenka u Ivanova I.I"  << endl;
	date_of_birth d;
    cout<<"Stack count items please: ";
    cin>>smax;
	char c;
	cin.get(c);
	for(int i=0;i<smax;i++)
	{
		d.push(i);
	}
	cout << "\nlist of structs\n!      name           !  date of birth !\n";
	d.print();
	d.search();
	_getch();
}
TLandertinger вне форума Ответить с цитированием
Ответ


Купить рекламу на форуме - 42 тыс руб за месяц



Похожие темы
Тема Автор Раздел Ответов Последнее сообщение
Стек Eugenelife Помощь студентам 3 12.11.2012 19:29
Стек Bizunov Паскаль, Turbo Pascal, PascalABC.NET 1 08.05.2011 15:52
Стек Darknes Общие вопросы C/C++ 2 11.04.2011 23:30
Стек [ICQ] Помощь студентам 5 02.05.2010 13:44