#include<iostream>
#include<fstream>
#include<iomanip>
#include<conio.h>
#include<string>
using namespace std;
class book_store
{
public:
char code[10],b_name[20],w_name[20];
float price;
void getdata()
{
cout<<"enter book name:";
cin>>b_name;
cout<<endl;
cout<<"enter writer name:";
cin>>w_name;
cout<<endl;
cout<<"enter price";
cin>>price;
cout<<endl;
}
};
class book_file:public book_store
{
public:
void fil()
{
fstream file("All_BOOKS.txt",ios::out|ios::app);
file.width(20);
file<<setiosflags(ios::left);
file<<price<<endl;
file.close();
}
void file();
};
void book_file::file()
{
char fil[20];
getdata();
strcpy(fil,code);
strcat(fil,".txt");
ofstream file(fil);
file<<"Book_name:"<<b_name<<endl;
file<<"writer_name:"<<w_name<<endl;
file<<"book code:"<<code<<endl;
file<<"price:"<<price<<endl;
file.close();
}
class T1:public book_file
{
public:
void book_data()
{
fstream file1("literature.txt",ios::out|ios::app);
file1<<endl;
file1<<"Book-name:"<<b_name<<endl;
file1<<"writer_name:"<<w_name<<endl;
file1<<"book code:"<<code<<endl;
file1<<"price:"<<price<<endl;
file1.close();
}
};
class T2:public book_file
{
public:
void book_data()
{
fstream file1("philosphy.txt",ios::out|ios::app);
file1<<endl;
file1<<"book_name:"<<b_name<<endl;
file1<<"writer_name:"<<w_name<<endl;
file1<<"code:"<<code<<endl;
file1<<"price:"<<price<<endl;
file1.close();
}
};
class T3:public book_file
{
public:
void book_data()
{
fstream file1("science.txt",ios::out|ios::app);
file1<<endl;
file1<<"book_name:"<<b_name<<endl;
file1<<"writer_name:"<<w_name<<endl;
file1<<"code:"<<code<<endl;
file1<<"price:"<<price<<endl;
file1.close();
}
};
class T4:public book_file
{
public:
void book_data()
{
fstream file1("comics.txt",ios::out|ios::app);
file1<<endl;
file1<<"book_name:"<<b_name<<endl;
file1<<"writer_name:"<<w_name<<endl;
file1<<"code:"<<code<<endl;
file1<<"price"<<price<<endl;
file1.close();
}
};
class add_books
{
public:
add_books();
};
add_books::add_books()
{
T1 t1;
T2 t2;
T3 t3;
T4 t4;
int choice;
while(1)
{
cout<<"Add Books"<<endl;
cout<<"1.literature books"<<endl<<"2.philosphy
book"<<endl<<"3.science book"<<endl<<"4.comics book"<<endl<<"5.Exit"<<endl;
cout<<"choice:"<<endl;
cin>>choice;
if(choice==1)
{
t1.file();
t1.book_data();
t1.fil();
}
if(choice==2)
{
t2.file();
t2.book_data();
t2.fil();
}
if(choice==3)
{
t3.file();
t3.book_data();
t3.fil();
}
if(choice==4)
{
t4.file();
t4.book_data();
t4.fil();
}
if(choice==5)
{
break;
}
}
}
class display
{
public:
display();
};
display::display()
{
int choice;
char code[10],ch;
while(1)
{
cout<<"display"<<endl;
cout<<"1.All books"<<endl;
cout<<"2.literature"<<endl;
cout<<"3.philosphy"<<endl;
cout<<"4.science"<<endl;
cout<<"5.comics"<<endl;
cout<<"6.exit"<<endl;
cout<<"enter ur choice"<<endl;
cin>>choice;
if(choice==1)
{
cout<<endl;
cout.width(20);
cout<<setiosflags(ios::left);
cout<<"book name"<<endl;
cout.width(20);
cout<<setiosflags(ios::left);
cout<<"writer name"<<endl;
cout.width(10);
cout<<setiosflags(ios::right);
cout<<"code"<<endl;
cout.width(10);
cout<<setiosflags(ios::right);
cout<<"price"<<endl;
fstream file("All books.txt",ios::in);
file.seekg(0);//seek particular person in file
while(file)
{
file.get(ch);
cout<<ch;
}
file.close();
}
if(choice==2)
{
fstream file("literature.txt",ios::in);
file.seekg(0);
cout<<endl;
while(file)
{
file.get(ch);
cout<<ch;
}
file.close();
}
if(choice==3)
{
fstream file("philosphy.txt",ios::in);
file.seekg(0);
cout<<endl;
while(file)
{
file.get(ch);
cout<<ch;
}
file.close();
}
if(choice==4)
{
fstream file("science.txt",ios::in);
file.seekg(0);
cout<<endl;
while(file)
{
file.get(ch);
cout<<ch;
}
file.close();
}
if(choice==5)
{
fstream file("comics.txt",ios::in);
file.seekg(0);
cout<<endl;
while(file)
{
file.get(ch);
cout<<ch;
}
file.close();
}
if(choice==6)
break;
}
}
class start
{
public:
start();
};
start::start()
{
int choice;
while(1)
{
cout<<"choice"<<endl;
cout<<"1.add books"<<endl;
cout<<"2.display"<<endl;
cout<<"3.exit"<<endl;
cout<<"choice"<<endl;
cin>>choice;
if(choice==1)
{
add_books a;
}
if(choice==2)
{
display d;
}
if(choice==3)
{
cout<<"exit";
cout<<endl;
}
}
}
int main()
{
start end;
return 0;
system("pause");
}
0 comments:
Post a Comment