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

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

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

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

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

Ответ
 
Опции темы Поиск в этой теме
Старый 28.09.2014, 15:13   #11
Stilet
Белик Виталий :)
Старожил
 
Аватар для Stilet
 
Регистрация: 23.07.2007
Сообщений: 57,097
По умолчанию

А что не полчается?
I'm learning to live...
Stilet вне форума Ответить с цитированием
Старый 28.09.2014, 15:23   #12
TLandertinger
Пользователь
 
Регистрация: 09.05.2013
Сообщений: 29
По умолчанию

Реализация вывода таблицы. И еще один вопрос: допустимы ли следующие структуры в случае с стеком:
Код:
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 rec
{
T_family tf;
};
?

Последний раз редактировалось TLandertinger; 28.09.2014 в 15:26.
TLandertinger вне форума Ответить с цитированием
Старый 28.09.2014, 17:52   #13
Stilet
Белик Виталий :)
Старожил
 
Аватар для Stilet
 
Регистрация: 23.07.2007
Сообщений: 57,097
По умолчанию

Цитата:
Реализация вывода таблицы.
А как пробовал?
Цитата:
допустимы ли следующие структуры в случае с стеком:
Учитывая что стэк это массив указателей там "хранить" допустимо все что угодно.
Надо просто правильно будет обрабатывать хранимое.
I'm learning to live...
Stilet вне форума Ответить с цитированием
Старый 28.09.2014, 18:21   #14
TLandertinger
Пользователь
 
Регистрация: 09.05.2013
Сообщений: 29
По умолчанию

Цитата:
Реализация вывода таблицы.
Цитата:
А как пробовал?
Ну не знаю. Будет ли верной эта часть кода, отвечающая за ввод информации о семье?
Код:
        int count;		 
	char c;
	cout << endl << " Enter data of person\n ";
	cout << " fio of father ";
	cin.getline (stack[top++].tf.fio_father, 30);
	cout << "Enter date of father's birthday: \n";
	cout << " day (1-31) ";
	cin >> stack[top++].tf.d_birth_father.day;
	cin.get(c);
	cout << " month (1-12)";
	cin >> stack[top++].tf.d_birth_father.month;
	cin.get(c);
	cout << " year ";
	cin >> stack[top++].tf.d_birth_father.year;
	cin.get(c);
	cout << " fio of mother ";
	cin.getline (stack[top++].tf.fio_mother, 30);
	cout << endl <<"Enter date of mother's birthday: \n";
	cout <<" day (1-31) ";
	cin >> stack[top++].tf.d_birth_mother.day;
	cin.get(c);
	cout << " month (1-12)";
	cin >> stack[top++].tf.d_birth_mother.month;
	cin.get(c);
	cout << " year ";
	cin >> stack[top++].tf.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;
	stack[top].tf.k = count;
	for (int k=0; k < count; k++) {
		cout << endl << " Name of " " " << k+1 << " " " child ";
		cin.getline (stack[top++].tf.ch[k].name_of_child, 30);
		cout << endl << "Enter date of" " "<< k+1 << " " "child's birthday: \n";
		cout <<" day (1-31) ";
		cin >> stack[top++].tf.ch[k].d_birth_child.day;
		cin.get(c);
		cout << " month (1-12)";
		cin >> stack[top++].tf.ch[k].d_birth_child.month;
		cin.get(c);
		cout << " year ";
		cin >> stack[top++].tf.ch[k].d_birth_child.year;
		cin.get(c);
	}

Последний раз редактировалось TLandertinger; 28.09.2014 в 18:29.
TLandertinger вне форума Ответить с цитированием
Старый 28.09.2014, 20:54   #15
Stilet
Белик Виталий :)
Старожил
 
Аватар для Stilet
 
Регистрация: 23.07.2007
Сообщений: 57,097
По умолчанию

Ну не... Я бы не сказал что это правильно. Тебе top увеличивать нужно только после того как ввел все элементы записи. т.е. только на последнем cin >> stack[top++]
I'm learning to live...
Stilet вне форума Ответить с цитированием
Старый 29.09.2014, 18:18   #16
TLandertinger
Пользователь
 
Регистрация: 09.05.2013
Сообщений: 29
По умолчанию

После обработки (если, конечно, я правильно сделал) на 98 строке кода
Код:
#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;//номер ребенка
}; 

// Сам стек
T_family *stack;
// Его вершина и максимум
int top=0,smax;

// Функция помещения в стек
bool push(){
 //Если не превышает пределы стека то норм, иначе вернуть false
 if (top==smax) return false;
 // Просим ввести данные
    int count;		 
	char c;
	T_family a;
	cout << endl << " Enter data of 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);
		}
 return true;
}

// Извлекаем из стека
bool pop(){
 //Если конечно есть что извлекать
 if (top<0) return false;
 //Передвигаем указатель с вершины на один вниз
 // показывая данные
 cout<<stack[--top]<<'\n';
 return true;
}

int main()
{
    //Спрашиваем размер стека
    cout<<"Stack count items please: ";
    cin>>smax;
    stack=new T_family[smax];
    //Забиваем в него данные
    int i;
    for(i=0;i<smax;i++) if(!push()) {cout<<"Problems pushing"<<'\n';break;}
    // Извлекаем из него данные
    for(i=0;i<smax;i++) if(!pop()) {cout<<"Problems popping"<<'\n';break;}
    //Освобождаем стек
    delete[] stack;
    cin.get();
	_getch();
    return 0;
}
компилятор ругается
TLandertinger вне форума Ответить с цитированием
Старый 29.09.2014, 18:21   #17
TLandertinger
Пользователь
 
Регистрация: 09.05.2013
Сообщений: 29
По умолчанию

Вот первая часть ругательства
Цитата:
1>------ Построение начато: проект: Neuer Stack, Конфигурация: Debug Win32 ------
1> Neuer Stack.cpp
1>Neuer Stack.cpp(98): error C2679: бинарный "<<": не найден оператор, принимающий правый операнд типа "T_family" (или приемлемое преобразование отсутствует)
1> C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\include\ostream(679): может быть "std::basic_ostream<_Elem,_Trai ts> &std:perator <<<char,std::char_traits<char>>(std ::basic_ostream<_Elem,_Traits> &,const char *)"
1> with
1> [
1> _Elem=char,
1> _Traits=std::char_traits<char>
1> ]
1> C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\include\ostream(726): или "std::basic_ostream<_Elem,_Trai ts> &std:perator <<<char,std::char_traits<char>>(std ::basic_ostream<_Elem,_Traits> &,char)"
1> with
1> [
1> _Elem=char,
1> _Traits=std::char_traits<char>
1> ]
1> C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\include\ostream(764): или "std::basic_ostream<_Elem,_Trai ts> &std:perator <<<std::char_traits<char>>(std::bas ic_ostream<_Elem,_Traits> &,const char *)"
1> with
1> [
1> _Elem=char,
1> _Traits=std::char_traits<char>
1> ]
1> C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\include\ostream(811): или "std::basic_ostream<_Elem,_Trai ts> &std:perator <<<std::char_traits<char>>(std::bas ic_ostream<_Elem,_Traits> &,char)"
1> with
1> [
1> _Elem=char,
1> _Traits=std::char_traits<char>
1> ]
1> C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\include\ostream(937): или "std::basic_ostream<_Elem,_Trai ts> &std:perator <<<std::char_traits<char>>(std::bas ic_ostream<_Elem,_Traits> &,const signed char *)"
TLandertinger вне форума Ответить с цитированием
Старый 29.09.2014, 18:25   #18
TLandertinger
Пользователь
 
Регистрация: 09.05.2013
Сообщений: 29
По умолчанию

Вот вторая часть
Цитата:
1> with
1> [
1> _Elem=char,
1> _Traits=std::char_traits<char>
1> ]
1> C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\include\ostream(944): или "std::basic_ostream<_Elem,_Trai ts> &std:perator <<<std::char_traits<char>>(std::bas ic_ostream<_Elem,_Traits> &,signed char)"
1> with
1> [
1> _Elem=char,
1> _Traits=std::char_traits<char>
1> ]
1> C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\include\ostream(951): или "std::basic_ostream<_Elem,_Trai ts> &std:perator <<<std::char_traits<char>>(std::bas ic_ostream<_Elem,_Traits> &,const unsigned char *)"
1> with
1> [
1> _Elem=char,
1> _Traits=std::char_traits<char>
1> ]
1> C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\include\ostream(958): или "std::basic_ostream<_Elem,_Trai ts> &std:perator <<<std::char_traits<char>>(std::bas ic_ostream<_Elem,_Traits> &,unsigned char)"
1> with
1> [
1> _Elem=char,
1> _Traits=std::char_traits<char>
1> ]
1> C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\include\ostream(968): или "std::basic_ostream<_Elem,_Trai ts> &std:perator <<<char,std::char_traits<char>,T_fa mily>(std::basic_ostream<_Elem,_Tra its> &&,_Ty)"
1> with
1> [
1> _Elem=char,
1> _Traits=std::char_traits<char>,
1> _Ty=T_family
1> ]
1> C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\include\ostream(1085): или "std::basic_ostream<_Elem,_Trai ts> &std:perator <<<char,std::char_traits<char>>(std ::basic_ostream<_Elem,_Traits> &,const std::error_code &)"
1> with
1> [
1> _Elem=char,
1> _Traits=std::char_traits<char>
и т.д.
TLandertinger вне форума Ответить с цитированием
Старый 29.09.2014, 22:04   #19
Stilet
Белик Виталий :)
Старожил
 
Аватар для Stilet
 
Регистрация: 23.07.2007
Сообщений: 57,097
По умолчанию

Правильно. cout<<stack[--top]<<'\n'; не может вывести всю структуру. Он маршалить не способен.
Нужно выводить каждое поле:
Код:
 cout
  <<"Children: "
    <<stack[top].ch[0].name_of_child<<'\t'<<stack[top].ch[0].d_birth_child.day<<'\n'
    <<stack[top].ch[1].name_of_child<<'\t'<<stack[top].ch[1].d_birth_child.day<<'\n'
    <<stack[top].ch[2].name_of_child<<'\t'<<stack[top].ch[2].d_birth_child.day<<'\n'
    <<stack[top].ch[3].name_of_child<<'\t'<<stack[top].ch[3].d_birth_child.day<<'\n'
    <<stack[top].ch[3].name_of_child<<'\t'<<stack[top].ch[4].d_birth_child.day<<'\n'
  <<"Father: "<<stack[top].fio_father<<'\t'<<stack[top].d_birth_father.day<<'\n'
  <<"Mother: "<<stack[top].fio_mother<<'\t'<<stack[top].d_birth_mother.day<<'\n'
 ;
...
top--;
I'm learning to live...
Stilet вне форума Ответить с цитированием
Старый 29.09.2014, 22:05   #20
Stilet
Белик Виталий :)
Старожил
 
Аватар для Stilet
 
Регистрация: 23.07.2007
Сообщений: 57,097
По умолчанию

Правильно. cout<<stack[--top]<<'\n'; не может вывести всю структуру. Он маршалить не способен.
Нужно выводить каждое поле:
Код:
 cout
  <<"Children: "
  <<stack[top].ch[0].name_of_child<<'\t'<<stack[top].ch[0].d_birth_child.day<<'\n'
    <<stack[top].ch[1].name_of_child<<'\t'<<stack[top].ch[1].d_birth_child.day<<'\n'
    <<stack[top].ch[2].name_of_child<<'\t'<<stack[top].ch[2].d_birth_child.day<<'\n'
    <<stack[top].ch[3].name_of_child<<'\t'<<stack[top].ch[3].d_birth_child.day<<'\n'
    <<stack[top].ch[3].name_of_child<<'\t'<<stack[top].ch[4].d_birth_child.day<<'\n'
  <<"Father: "<<stack[top].fio_father<<'\t'<<stack[top].d_birth_father.day<<'\n'
  <<"Mother: "<<stack[top].fio_mother<<'\t'<<stack[top].d_birth_mother.day<<'\n'
 ;
...
top--;
I'm learning to live...
Stilet вне форума Ответить с цитированием
Ответ


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



Похожие темы
Тема Автор Раздел Ответов Последнее сообщение
Стек Igor95 Общие вопросы C/C++ 19 17.01.2013 04:31
Стек на С++ Electroflower Общие вопросы C/C++ 37 05.01.2012 14:20
Стек Darknes Общие вопросы C/C++ 2 11.04.2011 23:30
Стек [ICQ] Помощь студентам 5 02.05.2010 13:44
стек в с++ Aleksa_ks Помощь студентам 0 02.05.2010 12:12