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

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

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

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

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

Ответ
 
Опции темы Поиск в этой теме
Старый 01.06.2012, 15:04   #1
gor30
 
Регистрация: 26.05.2012
Сообщений: 5
По умолчанию есть проблема с удалением записи из бинарного файла(С++)

все работает кроме удаления.
вначале находится необходимая запись а вот с ее удалением из бинарного у меня проблема.
Код:
static char text[]="H:\\kyrsavai\\2.txt"; //Bin File
static char name[]="H:\\kyrsavai\\1.txt"; //Text File
class Printer
{
     public:
	char model[80];
	char format[73];
	int speed;
	int garant;
	long cena;
	char firma[80];
	void poisk(Printer);
	void ydalenie(Printer);
};
class MainMenu
{
   public:
	void DrawView();
	void DrawAdd();
	void DrawDelete();
	void DrawSearch();
	void DrawEdit();
	void DrawSort();
	void DrawExit();
	void Draw(int);
};
////////////////////FUNCTION//////////////////////////////
void vivod();
void dobavlenie();

void zap_bin();
void menu_1(int);
void viv(void);
////////////////////OSNOBNAI PROGRAM//////////////////////
void main()
{
	clrscr();
	MainMenu Menu;
	int key,st=0;
	Menu.Draw(st);
	do
	{
		key=getch();
		if (key == 72 || key == 73)
		{
			st--;
			if (st < 0)
				st = 6;
			clrscr();
			Menu.Draw(st);
		}
		if (key == 80 || key == 81)
		{
			st++;
			if (st > 6)
				st = 0;
			clrscr();
			Menu.Draw(st);
		}
	}
	while(key !=27);

}
///////////////////////OPISANI FUNCTION & METODOV////////////////////////
void Printer::ydalenie(Printer str1)
{
	    MainMenu Menu;Printer mt ;
	    ifstream fin(name);
	    fin.close();
	    fin.open(text,ios::binary);
	    cout<<endl;
	    cout<<"   Model           Format Peper                speed  garant  cena      firma"<<endl;
	    cout<<"   -----           ------------                -----  ------  ----      -----"<<endl<<endl;
	   ////////////vivod na ekran//////////////////////////////////////
	   while (fin.read((char*)&mt,sizeof(mt)))
	     {
		if(str1.speed==mt.speed)
		cout<<setw(8)<<mt.model
		    <<setw(36)<<mt.format
		    <<setw(6)<<mt.speed
		    <<setw(7)<<mt.garant
		    <<setw(8)<<mt.cena
		    <<setw(12)<<mt.firma<<endl;
	     }
}
/////////////////////////////////////////////////
void Printer::poisk(Printer str1)
{
	    MainMenu Menu;Printer mt ;
	    ifstream fin(name);
	    fin.close();
	    fin.open(text,ios::binary);
	    cout<<endl;
	    cout<<"   Model           Format Peper                speed  garant  cena      firma"<<endl;
	    cout<<"   -----           ------------                -----  ------  ----      -----"<<endl<<endl;
	   while (fin.read((char*)&mt,sizeof(mt)))
	     {
		if(str1.speed==mt.speed)
		cout<<setw(8)<<mt.model
		    <<setw(36)<<mt.format
		    <<setw(6)<<mt.speed
		    <<setw(7)<<mt.garant
		    <<setw(8)<<mt.cena
		    <<setw(12)<<mt.firma<<endl;
	     }
}
//////////////////////////////
void zap_bin()
{
  MainMenu Menu;Printer mt ;
	    ofstream fout(text,ios::binary);
	    ifstream fin(name);
	    while(!fin.eof())
	      {
		fin>>mt.model
		   >>mt.format
		   >>mt.speed
		   >>mt.garant
		   >>mt.cena
		   >>mt.firma;
		fout.write((char*)&mt,sizeof(mt)); //zapisb B bin fail
	      }

}
gor30 вне форума Ответить с цитированием
Старый 01.06.2012, 15:09   #2
gor30
 
Регистрация: 26.05.2012
Сообщений: 5
По умолчанию продолжение

Код:
///////////////////////////////
void menu_1(int state)
{
	switch (state)
	{
	case 0:
	    cout<<"                                     @@@@@@@@"<<endl;
	    cout<<"                                       MENU"<<endl;
	    cout<<"                                     @@@@@@@@"<<endl<<endl;
	    cout<<"                                      !View!"<<endl;
	    cout<<"                                       Add"<<endl;
	    cout<<"                                       Delete"<<endl;
	    cout<<"                                       Search"<<endl;
	    cout<<"                                       Redactor"<<endl;
	    cout<<"                                       Sort"<<endl;
	    cout<<"                                       Exit"<<endl<<endl;
	    for (int i2 = 0; i2 < 80; i2++) cout<<"|";
	    break;
	case 1:
		cout<<"                                     @@@@@@@@"<<endl;
		cout<<"                                       MENU"<<endl;
		cout<<"                                     @@@@@@@@"<<endl;
		cout<<endl;
		cout<<"                                       View"<<endl;
		cout<<"                                      !Add!"<<endl;
		cout<<"                                       Delete"<<endl;
		cout<<"                                       Search"<<endl;
		cout<<"                                       Redactor"<<endl;
		cout<<"                                       Sort"<<endl;
		cout<<"                                       Exit"<<endl;
		cout<<endl;
		for (int i3=0; i3 < 80; i3++)
		cout<<"|";
		break;
	case 2:
		cout<<"                                     @@@@@@@@"<<endl;
		cout<<"                                       MENU"<<endl;
		cout<<"                                     @@@@@@@@"<<endl;
		cout<<endl;
		cout<<"                                       View"<<endl;
		cout<<"                                       Add"<<endl;
		cout<<"                                      !Delete!"<<endl;
		cout<<"                                       Search"<<endl;
		cout<<"                                       Redactor"<<endl;
		cout<<"                                       Sort"<<endl;
		cout<<"                                       Exit"<<endl;
		cout<<endl;
		for (int i4 = 0; i4 < 80; i4++)cout<<"|";
		break;
	case 3:
		cout<<"                                     @@@@@@@@"<<endl;
		cout<<"                                       MENU"<<endl;
		cout<<"                                     @@@@@@@@"<<endl;
		cout<<endl;
		cout<<"                                       View"<<endl;
		cout<<"                                       Add"<<endl;
		cout<<"                                       Delete"<<endl;
		cout<<"                                      !Search!"<<endl;
		cout<<"                                       Redactor"<<endl;
		cout<<"                                       Sort"<<endl;
		cout<<"                                       Exit"<<endl;
		cout<<endl;
		for (int i5 = 0; i5 < 80; i5++)cout<<"|";
		break;
	case 4:
	       cout<<"                                     @@@@@@@@"<<endl;
	       cout<<"                                       MENU"<<endl;
	       cout<<"                                     @@@@@@@@"<<endl;
	       cout<<endl;
	       cout<<"                                       View"<<endl;
	       cout<<"                                       Add"<<endl;
	       cout<<"                                       Delete"<<endl;
	       cout<<"                                       Search"<<endl;
	       cout<<"                                      !Redactor!"<<endl;
	       cout<<"                                       Sort"<<endl;
	       cout<<"                                       Exit"<<endl;
	       cout<<endl;
	       for (int i6 = 0; i6 < 80; i6++)cout<<"|";
		break;
gor30 вне форума Ответить с цитированием
Старый 01.06.2012, 15:11   #3
gor30
 
Регистрация: 26.05.2012
Сообщений: 5
По умолчанию продолжение

Код:
	case 5:
		cout<<"                                     @@@@@@@@"<<endl;
		cout<<"                                       MENU"<<endl;
		cout<<"                                     @@@@@@@@"<<endl;
		cout<<endl;
		cout<<"                                       View"<<endl;
		cout<<"                                       Add"<<endl;
		cout<<"                                       Delete"<<endl;
		cout<<"                                       Search"<<endl;
		cout<<"                                       Redactor"<<endl;
		cout<<"                                      !Sort!"<<endl;
		cout<<"                                       Exit"<<endl;
		cout<<endl;
		for (int i7=0;i7<80;i7++)cout<<"|";
		break;
	case 6:
		cout<<"                                     @@@@@@@@"<<endl;
		cout<<"                                       MENU"<<endl;
		cout<<"                                     @@@@@@@@"<<endl;
		cout<<endl;
		cout<<"                                       View"<<endl;
		cout<<"                                       Add"<<endl;
		cout<<"                                       Delete"<<endl;
		cout<<"                                       Search"<<endl;
		cout<<"                                       Redactor"<<endl;
		cout<<"                                       Sort"<<endl;
		cout<<"                                      !Exit!"<<endl;
		cout<<endl;
		for (int i8=0;i8<80;i8++)cout<<"|";
		break;
	}
}
//////////////////////////////
void MainMenu::DrawView()
{
	int key;
	menu_1(0);
	key=getch();
	if(key == 13) vivod();
}
/////////////////////////////
void vivod()
{
	    int key, st = 0,count=0,count1=1;
	    MainMenu Menu;Printer mt ;
	    ifstream fin(name);
	 // zap_bin();
	    fin.close();
	    fin.open(text,ios::binary);
	    cout<<"   Model           Format Peper                speed  garant  cena      firma"<<endl;
	    cout<<"   -----           ------------                -----  ------  ----      -----"<<endl<<endl;
	   ////////////vivod na ekran//////////////////////////////////////
	   while (fin.read((char*)&mt,sizeof(mt)))
	     {
		cout<<setw(8)<<mt.model
		    <<setw(36)<<mt.format
		    <<setw(6)<<mt.speed
		    <<setw(7)<<mt.garant
		    <<setw(8)<<mt.cena
		    <<setw(12)<<mt.firma<<endl;
		count++;
		if (count==10)
		 {
		   count=0;
		   cout<<endl<<endl<<endl<<"                                  Page:"<<count1;
		   count1++;
		   cout<<endl<<endl<<"Pres ENTER";
		   cin.get();
		   clrscr();
		   menu_1(0);
		   do
		      {
			key=13;
			cout<<"   Model           Format Peper                speed  garant  cena      firma"<<endl;
			cout<<"   -----           ------------                -----  ------  ----      -----"<<endl<<endl;
		      }
		   while(key!=13);
		 }
	     }
     if(count<10)
	{
	  cout<<endl<<endl<<endl<<"                                  Page:"<<count1;
	}
     cout<<endl<<endl<<"Press any key to return to the menu...";
     getch();
     clrscr();
     Menu.Draw(st);fin.close();
}
////////////////////////////
void dobavlenie()
{
	    MainMenu Menu;
	    Printer mt;
	    int key,st=0;
	    char str[80];
	    ofstream fout (text,ios::app);
	    cout<<"BBEDITE Model:";
	    cin>>mt.model;
	    cout<<"BBEDITE Format:";
	    cin>>mt.format;
	    cout<<"BBEDITE Speed:";
	    cin>>mt.speed;
	    cout<<"BBEDITE Garant:";
	    cin>>mt.garant;
	    cout<<"BBEDITE Ceny:";
	    cin>>mt.cena;
	    cout<<"BBEDITE Firmy:";
	    cin>>mt.firma;
	    fout.write((char*)&mt,sizeof(mt)); //zapisb B bin fail
	    fout.close();
	    if (key==27);
	      {
	       clrscr();
	       Menu.Draw(st);
	      }

}
/////////////////////////
void MainMenu::DrawAdd()
{
	menu_1(1);
	int key=getch();
	if(key==13)  dobavlenie();
}
////////////////////////
void MainMenu::DrawDelete()
{
       menu_1(2);
       Printer str;
	int key=getch();
	if(key==13)
	  {  cout<<"Enter Speed printera kotoriy nado ydalit:";
	     cin>>str.speed;
	     str.ydalenie(str);
	  }

}
////////////////////
void MainMenu::DrawSearch()
{
	menu_1(3);
	Printer str;
	int key=getch();
	if(key==13)
	  {  cout<<"Enter Speed printera kotoriy nado naiti:";
	     cin>>str.speed;
	     str.poisk(str);
	  }
}
////////////////
void MainMenu::DrawEdit()
{
	menu_1(4);
}
/////////////////////////////////
void MainMenu::DrawSort()
{
	menu_1(5);
}
///////////////////////////////
void MainMenu::DrawExit()
{
	menu_1(6);
	int key, st = 6;
	key=getch();
	if (key == 13) exit(1);

}
/////////////////////////
void MainMenu::Draw(int state = 0)
{
	switch (state)
	{
	case 0:
		DrawView();
		break;
	case 1:
		DrawAdd();
		break;
	case 2:
		DrawDelete();
		break;
	case 3:
		DrawSearch();
		break;
	case 4:
		DrawEdit();
		break;
	case 5:
		DrawSort();
		break;
	case 6:
		DrawExit();
		break;
	default:
		DrawView();
		break;
	}
}
gor30 вне форума Ответить с цитированием
Ответ


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



Похожие темы
Тема Автор Раздел Ответов Последнее сообщение
Повреждение данных при записи в середину бинарного файла Aerial Общие вопросы C/C++ 2 01.12.2011 19:32
Проблема с удалением файла Dimarik Assembler - Ассемблер (FASM, MASM, WASM, NASM, GoASM, Gas, RosAsm, HLA) и не рекомендуем TASM 2 25.06.2011 20:15
Проблема при чтении из бинарного файла twiss Помощь студентам 0 02.10.2010 00:04
проблема с удалением файла katttes Общие вопросы Delphi 3 30.04.2010 13:17
проблема при выводе с бинарного файла... xVxSeRGxVx Общие вопросы C/C++ 1 13.01.2010 19:08