Удаление строк из файла. Сортировка
#include<fstream.h>
#include<stdlib.h>
#include<stdio.h>
#include<conio.h>
#include<windows.h>
#include<string.h>
#include<iomanip.h>
struct automobil
{
int id;
char fio[30];
int pas;
int got;
char tgot[6];
int vart;
} s[100];
int k = 0;
void Prosmotr_vsey_BD();
void dobavit_sapiz();
void ochistit_BD();
void iz_faila();
void avtor();
void ARG();
void ud_string ();
int main()
{
k = 4;
int vibor = 7;
while (1)
{
if ((1 <= vibor && vibor <= 2) || (4 <= vibor && vibor <= 8) || (vibor == 31) || (vibor == 32) || (vibor == 33))
{
if (vibor == 1)
{
avtor() ;
}
if (vibor == 2)
{
iz_faila();
}
if (vibor == 31)
{
dobavit_sapiz();
}
if (vibor == 32)
{
ud_string () ;
}
if (vibor == 33)
{
ochistit_BD();
}
if (vibor == 4)
{
;
}
if (vibor == 5)
{
;
}
if (vibor == 6)
{
;
}
if (vibor == 7)
{
system("cls");
cout << " MENU:n";
cout << " 1.Ob Avtore:n";
cout << " 2.Vvod BDn";
cout << " 3.Redactirovanie BD:n";
cout << " 31.dobavit sapizn";
cout << " 32.udalit sapizn";
cout << " 33.ochistit BDn";
cout << " 4.Sortirovka AVG:n";
cout << " 5.Sortirovka DEC:n";
cout << " 6.Vuvod BD v file:n";
cout << " 7.Clear consoln";
cout << " 8.Exitnn";
}
if (vibor == 8)
{
break;
}
}
else
{
cout << "ERROR! nn";
}
cout << "n vibor ";
cin >> vibor;
}
return 0;
}
void dobavit_sapiz() //func dobav zapis
{
ofstream f ;
f.open("DAT1.TXT", fstream::app);
cout<<"n id " ;
cin>> s[k].id ;
f <<"n " << s[k].id ;;
cout<<"n FIO " ;
cin>> s[k].fio ;
f <<"n " << s[k].fio , "n" ;
cout<<"n Pasport " ;
cin>> s[k].pas ;
f <<"n " << s[k].pas, "n" ;
cout<<"n Nomer v otele " ;
cin>> s[k].got ;
f <<"n " << s[k].got, "n" ;
cout<<"n Type otelya ";
cin>> s[k].tgot ;
f <<"n " << s[k].tgot, "n" ;
cout<<"n Vartist " ;
cin>> s[k].vart ;
f <<"n " << s[k].vart ;
f.open("DAT1.txt");
/* cout << "=======================n";
cout << " ID: "; cin >> s[k].id;
cout << " Name: n";
cout << " Pasport: "; cin >> s[k].pas;
cout << " Nomer: "; cin >> s[k].got;
cout << " Type: n";
cout << " Cost: "; cin >> s[k].vart;
cout << "=======================";
cout << "nn";
k = k + 1; */
}
void ochistit_BD() //func ochistit BD
{
k = 0;
ofstream f ;
f.open("DAT1.TXT", fstream::trunc);
cout << "BD ydalena! nn";
}
//func iz faila
void iz_faila()
{ { char c[30];
int k=0;
int vop;
ifstream f("DAT1.TXT");
cout<<"Base Data : "<<"DAT1.TXT"<<endl;
f>>k;
for(int i=0;i<k;i++){
f>>s.id>>s.fio>>s.pas>>s.got>>s.tgot>>s.vart;
}
cout<<"___________________________________________________________________";
cout<<"n |ID |Name |Pasport|Nomer|Type |Vartist|";
cout<<"n |===|==============================|=======|=====|=======|=======|";
for(int i=0;i<k;i++){
printf("n |%3d|%30s|%7d|%5d|%7s|%7d|",s.id,s.fio,s.pas,s.got,s.tgot, s.vart) ;
cout<<"n |---|------------------------------|-------|-----|-------|-------";
}
f.close();
}}
void avtor()
{cout<< "Kimalov Valentin" ; //func ob avtore
}
void ARG(){ //nachalo sort
} //konec sort
void ud_string (){ //nachalo ud string
} //konec ud string
#include<stdlib.h>
#include<stdio.h>
#include<conio.h>
#include<windows.h>
#include<string.h>
#include<iomanip.h>
struct automobil
{
int id;
char fio[30];
int pas;
int got;
char tgot[6];
int vart;
} s[100];
int k = 0;
void Prosmotr_vsey_BD();
void dobavit_sapiz();
void ochistit_BD();
void iz_faila();
void avtor();
void ARG();
void ud_string ();
int main()
{
k = 4;
int vibor = 7;
while (1)
{
if ((1 <= vibor && vibor <= 2) || (4 <= vibor && vibor <= 8) || (vibor == 31) || (vibor == 32) || (vibor == 33))
{
if (vibor == 1)
{
avtor() ;
}
if (vibor == 2)
{
iz_faila();
}
if (vibor == 31)
{
dobavit_sapiz();
}
if (vibor == 32)
{
ud_string () ;
}
if (vibor == 33)
{
ochistit_BD();
}
if (vibor == 4)
{
;
}
if (vibor == 5)
{
;
}
if (vibor == 6)
{
;
}
if (vibor == 7)
{
system("cls");
cout << " MENU:n";
cout << " 1.Ob Avtore:n";
cout << " 2.Vvod BDn";
cout << " 3.Redactirovanie BD:n";
cout << " 31.dobavit sapizn";
cout << " 32.udalit sapizn";
cout << " 33.ochistit BDn";
cout << " 4.Sortirovka AVG:n";
cout << " 5.Sortirovka DEC:n";
cout << " 6.Vuvod BD v file:n";
cout << " 7.Clear consoln";
cout << " 8.Exitnn";
}
if (vibor == 8)
{
break;
}
}
else
{
cout << "ERROR! nn";
}
cout << "n vibor ";
cin >> vibor;
}
return 0;
}
void dobavit_sapiz() //func dobav zapis
{
ofstream f ;
f.open("DAT1.TXT", fstream::app);
cout<<"n id " ;
cin>> s[k].id ;
f <<"n " << s[k].id ;;
cout<<"n FIO " ;
cin>> s[k].fio ;
f <<"n " << s[k].fio , "n" ;
cout<<"n Pasport " ;
cin>> s[k].pas ;
f <<"n " << s[k].pas, "n" ;
cout<<"n Nomer v otele " ;
cin>> s[k].got ;
f <<"n " << s[k].got, "n" ;
cout<<"n Type otelya ";
cin>> s[k].tgot ;
f <<"n " << s[k].tgot, "n" ;
cout<<"n Vartist " ;
cin>> s[k].vart ;
f <<"n " << s[k].vart ;
f.open("DAT1.txt");
/* cout << "=======================n";
cout << " ID: "; cin >> s[k].id;
cout << " Name: n";
cout << " Pasport: "; cin >> s[k].pas;
cout << " Nomer: "; cin >> s[k].got;
cout << " Type: n";
cout << " Cost: "; cin >> s[k].vart;
cout << "=======================";
cout << "nn";
k = k + 1; */
}
void ochistit_BD() //func ochistit BD
{
k = 0;
ofstream f ;
f.open("DAT1.TXT", fstream::trunc);
cout << "BD ydalena! nn";
}
//func iz faila
void iz_faila()
{ { char c[30];
int k=0;
int vop;
ifstream f("DAT1.TXT");
cout<<"Base Data : "<<"DAT1.TXT"<<endl;
f>>k;
for(int i=0;i<k;i++){
f>>s.id>>s.fio>>s.pas>>s.got>>s.tgot>>s.vart;
}
cout<<"___________________________________________________________________";
cout<<"n |ID |Name |Pasport|Nomer|Type |Vartist|";
cout<<"n |===|==============================|=======|=====|=======|=======|";
for(int i=0;i<k;i++){
printf("n |%3d|%30s|%7d|%5d|%7s|%7d|",s.id,s.fio,s.pas,s.got,s.tgot, s.vart) ;
cout<<"n |---|------------------------------|-------|-----|-------|-------";
}
f.close();
}}
void avtor()
{cout<< "Kimalov Valentin" ; //func ob avtore
}
void ARG(){ //nachalo sort
} //konec sort
void ud_string (){ //nachalo ud string
} //konec ud string
во первых используйте средства форматирования кода, что такое- не получается?