Автор: Depp (09.11.2007 в 13:26)
Помогите прокомментировать код программы! В особенности, что такое в кое K?
И употребление bool значений!
P.S. Выручайте, иначе отчислят ….
//---------------------------------------------------------------------------
#include "stdafx.h"
//#pragma hdrstop
#include <iostream.h>
#include <fstream.h> #include <string.h>
//---------------------------------------------------------------------------
//====================My VALUES=========================================
struct book
{
char Autor[50];
char Book_Name[50];
bool Off;
};
//====================My VALUES=========================================
int Enter(book Library[])
{
ifstream Input("base.txt");
int i=0 ;
while(Input)
{
Input>>Library[i].Autor;
Input>>Library[i].Book_Name;
i++ ;
}
return i-1;
};
void Save(book Library[],int k)
{
ofstream Base("Base.txt") ;
for(int i=0;i<k;i++)
{
if(Library[i].Off==false)
{
Base<<Library[i].Autor<<'\n'
<<Library[i].Book_Name<<'\n';
}
}
};
void Delete(book Library[100],int k)
{
char Autor[50];
cout<<"Enter second name of autor"<<'\n';
cin>>Autor;
for(int i=0;i<k;i++)
{
if(strcmp(Library[i].Autor,Autor )==0)
{
Library[i].Off=true;
}
}
};
int Add(book Library[],int k)
{
k++;
cout<<"Enter second name of autor"<<'\n';
cin>>Library[k-1].Autor;
cout<<"Enter a name of book"<<'\n';
cin>>Library[k-1].Book_Name;
Library[k-1].Off=false;
return k;
};
//======================MAIN============================================
int main(int argc, char* argv[])
{
//========================Объявление переменных====
book Library[100] ;
book *Ukazatel ;
int j=5 ;
bool End=false ;
ifstream Input("base.txt") ;
int k=0 ;
for(int i=0;i<100;i++)
{
Library[i].Off=false;
}
//========================Объявление переменных===
k=Enter(Library);
while(!End)
{
if(j==5)
{
cout<<"For printing all array -1 "
<<'\n'
<<"For deleting from array -2 "
<<'\n'
<<"For add information to array -3 "
<<'\n'
<<"For exit -4 "
<<'\n';
}
cout<<"For drawing meny -5"<<'\n'<<'\n'<<'\n';
cin>>j;
//=============================Действия меню==============
if(j==4)
{
End=true;
};
if(j==3)
{
k=Add(Library,k);
//cout<<k;
};
if(j==1)
{
for(int i=0;i<k;i++)
{
if(Library[i].Off==false)
{
cout<<"Autor :"<<Library[i].Autor<<'\n'
<<"Book name :"<<Library[i].Book_Name<<'\n';
}
}
};
if(j==2)
{
Delete(Library,k);
};
//=================================Конец===========================
}
Save(Library, k) ;
return 0;
}