You are on page 1of 4

#include <iostream.

>
#include <fstream>
#include <stdio.h>
#include<string.h>
class perstxt
{
char topic[20], date, subj[20], para[500];
void disp();
public:
void get();
void wtf();
void rff();
void search();
void del();
void mod();
}c;
void perstxt::get()
{
puts("\nEnter name of topic:");
gets(topic);
puts("\ndate (dd/mm/yy):");
std::cin>>date;
puts("\nenter subjest of your topic:");
gets(subj);
puts("enter your paragraph:");
gets(para);

}
void perstxt::disp()
{
std::cout<<"The personal text\n";
std::cout<<"\nName of topic: "<<topic;
std::cout<<"\nDate: "<<date;
std::cout<<"\nSubject: "<<subj;
std::cout<<"\nParagraph: "<<para;

}
void perstxt::wtf()
{
std::ofstream ofile;
ofile.open("CBI", std::ios::app);
get();
ofile.write((char*)&c, sizeof(c));
ofile.close();
}
void perstxt::rff()
{
std::ifstream ifile;
ifile.open("CBI");
ifile.seekg(0, std::ios::beg);
ifile.read((char*)&c, sizeof(c));
while(ifile)
{
disp();
ifile.read ((char*)&c, sizeof(c));
}
ifile.close();
}
void perstxt::search()
{
char m[20];
std::ifstream ifile("CBI");
puts("Enter name of topic which has to be searched");
gets(m);
ifile.seekg (0, std::ios::beg);
ifile.read((char*)&c, sizeof(c));
while(ifile)
{
if (strcmpi(m, topic)==0)
disp();
ifile.read((char*)&c, sizeof(c));
}
ifile.close();
}
void perstxt::del()
{
char b[20];
std::ifstream ifile;
ifile.open("CBI", std::ios::app);
std::ofstream ofile;
ofile.open("new", std::ios::app);
puts("Enter the name of the topic you want to del");
gets(b);
ifile.seekg (0, std::ios::beg);
ifile.read((char*)&c, sizeof(c));
while(ifile)
{
if (strcmpi(b, topic))
ofile.write((char*)&c, sizeof(c));
ifile.read((char*)&c, sizeof(c));
}
ifile.close();
ofile.close();
remove ("CBI");
rename("new", "CBI");
}
void perstxt::mod()
{
char d[20];
int p;
puts("\nEnter name of topic you want to modify\n");
gets(d);
std::fstream f;
f.open("CBI", std::ios::in|std::ios::out);
f.seekg(0, std::ios::beg);
f.read((char*)&c, sizeof(c));
int a=f.tellg();
while(! f.eof())
{
if (!strcmpi(d, topic))
{
puts("\nPress 1 to change topic\nPress 2 to change date\nPress 3 to
change subject\nPress 4 to change paragraph");
std::cin>>p;
switch(p)
{
case 1:
gets(topic);
break;
case 2:
std::cin>>date;
break;
case 3:
gets(subj);
break;
case 4:
gets(para);
break;

}
f.seekg(a-sizeof(c), std::ios::beg);
f.write((char*)&c, sizeof(c));
}
f.read((char*)&c, sizeof(c));
a=f.tellg();
}
f.close();
}
int main ()
{
char pass[20]=blabla;
int ch;
char choice;
cout<<"\nwrite the password";
gets(pass);
if(pass=="blabla")
{
do
{
std::cout<<"\t THE PERSONAL TEXT ";
std::cout<<"\n ********************************************";
std::cout<<"\n\n * 1. View topics *";
std::cout<<"\n\n * 2. Add new topic details *";
std::cout<<"\n\n * 3. Search a topic record *";
std::cout<<"\n\n * 4. Delete a topic record *";
std::cout<<"\n\n * 5. Modify a topic record *";
std::cout<<"\n ********************************************";
std::cout<<"\n\n Enter your choice: ";
std::cin>>ch;

switch(ch)
{
case 1:

c.rff();
break;
case 2:

c.wtf();

break;
case 3:
c.search();
break;
case 4:
c.del();
break;
case 5:
c.mod();
break;
default:
{
std::cout<<"\nerror!";
}
break;
}
std::cout<<"\ncontinue? (y/n)\n";
std::cin>>choice;
}while(choice=='y');
}
std::cout<<"\nGood bye";
return 0;
}

You might also like