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

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

Вернуться   Форум программистов > IT форум > Помощь студентам
Регистрация

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

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

Ответ
 
Опции темы Поиск в этой теме
Старый 07.04.2011, 01:47   #1
Blad47
Пользователь
 
Регистрация: 10.11.2008
Сообщений: 93
По умолчанию Считывание строки

Код:

#include "stdafx.h"
#include "iostream"
#include "vector"
#include "string"

using namespace std;

struct date
{
	int day;
	int month;
	int year;
};

struct time
{
	int hour;
	int min;
	int sec;
};


class Base
{
private:
	char* surname;
	int number;
	date date_call;
	double tarif;
	time time_begin;
	time time_end;
public:
	Base();
	Base(const char*, int, int, int, int , double, int, int ,int , int, int, int);
	~Base();
	void set_surname(const char*);
	void set_number(int);
	void set_date(int, int, int);
	void set_tarif(double);
	void set_time_begin(int, int, int);
	void set_time_end(int, int, int);
	char* get_surname();
	int get_number();
	date get_date();
	double get_tarif();
	time get_time_begin();
	time get_time_end();
};

Base::Base()
{
	surname = new char[255];
}

Base::Base(const char* Nsurname, int Nnumber, int day, int month, int year, double Ntarif, int hour_begin, int min_begin, int sec_begin, int hour_end, int min_end, int sec_end)
{
	surname = new char[strlen(Nsurname)+1];
	strcpy(surname, Nsurname);
	number = Nnumber;
	date_call.day = day;
	date_call.month = month;
	date_call.year = year;
	tarif = Ntarif;
	time_begin.hour = hour_begin;
	time_begin.min = min_begin;
	time_begin.sec = sec_begin;
	time_end.hour = hour_end;
	time_end.min = min_end;
	time_end.sec = sec_end;
}

Base::~Base()
{
	delete []surname;
}

void Base::set_surname(const char* Nsurname)
{
	surname = new char[strlen(Nsurname)+1];
	strcpy(surname, Nsurname);
}

void Base::set_number(int Nnumber)
{
	number = Nnumber;
}

void Base::set_date(int day, int month, int year)
{
	date_call.day = day;
	date_call.month = month;
	date_call.year = year;
}

void Base::set_tarif(double Ntarif)
{
	tarif = Ntarif;
}

void Base::set_time_begin(int hour, int min, int sec)
{
	time_begin.hour = hour;
	time_begin.min = min;
	time_begin.sec = sec;
}

void Base::set_time_end(int hour, int min, int sec)
{
	time_end.hour = hour;
	time_end.min = min;
	time_end.sec = sec;
}

char* Base::get_surname()
{
	char* Nsurname;
	Nsurname = new char[strlen(surname)+1];
	strcpy(Nsurname, surname);
	return Nsurname;
}

int Base::get_number()
{
	int Nnumber;
	Nnumber = number;
	return Nnumber;
}

date Base::get_date()
{
	date Ndate_call;
	Ndate_call.day = date_call.day;
	Ndate_call.month = date_call.month;
	Ndate_call.year = date_call.year;
	return Ndate_call;
}

double Base::get_tarif()
{
	return tarif;
}

time Base::get_time_begin()
{
	time Ntime_begin;
	Ntime_begin.hour = time_begin.hour;
	Ntime_begin.min = time_begin.min;
	Ntime_begin.sec = time_begin.sec;
	return Ntime_begin;
}

time Base::get_time_end()
{
	time Ntime_end;
	Ntime_end.hour = time_end.hour;
	Ntime_end.min = time_end.min;
	Ntime_end.sec = time_end.sec;
	return Ntime_end;
}

class List
{
private:
	vector<Base>temp;

public:
	List(){}
	~List()
	{
		temp.erase(temp.begin()+temp.size());
	}
	void add(Base);
	void info();

};

void List::add(Base record)
{
	temp.push_back(record);
		cout<<"record added"<<"/n";
}

void List::info()
{
	Base record;
	for(int i=0;i<temp.size();i++)
	{
		record = temp[i];
		cout<<record.get_surname()<<" ";
		cout<<record.get_number()<<" ";
		cout<<record.get_date().day<<" ";
		cout<<record.get_date().month<<" ";
		cout<<record.get_date().year<<" ";
		cout<<record.get_tarif()<<" ";
		cout<<record.get_time_begin().hour<<" ";
		cout<<record.get_time_begin().min<<" ";
		cout<<record.get_time_begin().sec<<" ";
		cout<<record.get_time_end().hour<<" ";
		cout<<record.get_time_end().min<<" ";
		cout<<record.get_time_end().sec<<" ";
	}
}

int _tmain(int argc, _TCHAR* argv[])
{

	List base;
	Base record;
	//char ans;
	char* Nname="";
	int Nnumber;
	int day, month, year;
	double Ntarif;
	int hour_b, min_b, sec_b;
    int hour_e, min_e, sec_e;

    cout<<"Name ";
	cin.getline(Nname,10);
	//cin>>Nname;
	record.set_surname(Nname);
	cout<<"number ";
	cin>>Nnumber;
	record.set_number(Nnumber);
	cout<<"data ";
	cin>>day>>month>>year;
	record.set_date(day, month, year);
	cout<<"tarif ";
	cin>>Ntarif;
	record.set_tarif(Ntarif);
	cout<<" time_b ";
	cin>>hour_b>>min_b>>sec_b;
	record.set_time_begin(hour_b, min_b, sec_b);
	cout<<" time_e ";
	cin>>hour_e>>min_e>>sec_e;
	record.set_time_end(hour_e, min_e, sec_e);

	base.add(record);
	base.info();




	return 0;
}
В конце всегда возникает дилема со считыванием строки. Программу выбрасывает, не могу разобраться.
И вообще подскажите, как лучше считывать строки?
Blad47 вне форума Ответить с цитированием
Старый 07.04.2011, 20:31   #2
Blad47
Пользователь
 
Регистрация: 10.11.2008
Сообщений: 93
По умолчанию

не актуально

Последний раз редактировалось Blad47; 07.04.2011 в 23:22.
Blad47 вне форума Ответить с цитированием
Ответ


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



Похожие темы
Тема Автор Раздел Ответов Последнее сообщение
Считывание строки с клавиатуры С++ Влюблённая в мечту Помощь студентам 12 01.04.2011 20:44
Считывание строки из консоли СИ с использованием getchar() vedro-compota Общие вопросы C/C++ 11 17.12.2010 12:19
Считывание строки неограниченной длины (Си) 0kopok Помощь студентам 6 05.10.2009 20:46
Считывание строки из файла до символа Stormzcooler Общие вопросы Delphi 7 18.12.2006 15:01