#include <iostream.h>
#include <string.h>
#include <stdlib.h>
#include <conio.h>
#include <graphics.h>
#include <ctype.h>
#include <cstring.h>
#include <stdlib.h>
#include <stdio.h>
class edit
{
private:
int first_find (string str, string pattern)
{
size_t loc;
loc = str.find(pattern);
if(loc!=string::npos){cout<<"\n\t\t\t\tFound at "<< int(loc); return int(loc);}
else {cout<<"\n\t\t\t\tNot there"; return -1;}
}
int find_next(string str, string pattern)
{
size_t loc = first_find(str, pattern);
loc = str.find(pattern,loc+1);
if(loc!=string::npos){cout<<"\n\t\t\t\tFound at "<< int(loc);return int(loc);}
else{cout<<"\n\t\t\t\tNot there"; return -1;}
}
void cut(string text)
{
gotoxy(23,20); cout<<"What do you want to cut?";
string cutted;
gotoxy(23,22); cout<<"Enter here: "cin>>cutted;
do
{
replace_this(text, cutted, "", text.find(cutted));
}while(text.find (cutted!=string::npos));
goto(23,26); cout<<"Where do you want to paste?";
int loc; goto(23,28); cout<<"Enter positin here: "; cin>>loc;
do
{
replace_this(text, "", cutted, loc);
}while(loc<=text.length());
}
void copy(string text)
{
gotoxy(23,20); cout<<"What do you want to copy?";
string cutted;
gotoxy(23,22); cout<<"Enter here: "cin>>cutted;
goto(23,26); cout<<"Where do you want to paste?";
int loc; goto(23,28); cout<<"Enter position here: "; cin>>loc;
do
{
replace_this(text, "", cutted, loc);
}while(loc<=text.length());
}
int first_find(string str)
{
string pattern;
gotoxy(23,20); cout<<"Type the part you want to search for";
gotoxy(23,22); cout<<"Enter here: "cin>>pattern;
size_t loc;
loc = str.find(pattern);
if(loc!=string::npos){cout<<"\n\t\t\t\tFound at "<< int(loc);return int(loc);}
else{cout<<"\n\t\t\t\tNot there"; return -1;}
}
int find_next(string str)
{
string pattern;
gotoxy(23,20); cout<<"Type the part you want to search for";
gotoxy(23,22); cout<<"Enter Here: "; cin>>pattern;
size_t loc = first_find(str, pattern);
loc = str.find(pattern,loc+1);
if(loc!=string::npos){cout<<"\n\t\t\t\t\tFound at "<< int(loc);return int(loc);}
else{cout<<"\n\t\t\t\tNot there"; return -1;}
}
void replace_all(string str)
{
gotoxy(23,20); cout<<"To replace: "; string pattern; cin>>pattern;
gotoxy(23,22); cout<<"With: "; string replacement; cin>>replacement;
size_t loc = first_find(str, pattern);
while(loc!=-1)
{
str.replace(loc,pattern.length(),replacement);
loc = find_next(str, pattern);
}
}
void replace_this(string str, string pattern, string replacement, int loc)
{
gotoxy(23,20);str.replace(loc,pattern.length(),replacement);
}
public:
int funda(char filename[80])
{
string text;
ifstream t;
t.open(filename);
if(!t){cerr<<"\n\t\t\t\tNot found, Invalid"; menu::funda();}
t.seekg(0, std::ios::end);
length = t.tellg();
t.seekg(0, std::ios::beg);
text = new char[length];
t.read(text, length);
t.close();
int i;
gotoxy(23,14); cout<<"Edit :" ;
gotoxy(23,16); cout<<"1) Cut and Paste";
gotoxy(23,18); cout<<"2) Copy and Paste";
gotoxy(23,20); cout<<"3) Find";
gotoxy(23,22); cout<<"4) Find Next";
gotoxy(23,24); cout<<"5) Replace";
gotoxy(23,26); cout<<"6) Replace All";
gotoxy(23,28); cout<<"7) Back";
gotoxy(18,32); cout<<"What would you like to open?? Enter the number";
gotoxy(23,34); cout<<"Enter Here: [ ]";
gotoxy(36,34);
int choice;
cin>>choice;
while(choice!=1||choice!=2||choice!=3||choice!=4||choice!=5||choice!=6||choice!=7||choice!=8)
{
switch(choice)
{
case 1:clrscr(); cut(text); menu::save(filename, text); return 1; break;
case 2:clrscr(); copy(text); menu::save(filename, text); return 2; break;
case 3:clrscr(); i = first_find(text); menu::save(filename, text); return 4; break;
case 4:clrscr(); i = find_next(text); menu::save(filename, text); return 5; break;
case 5:clrscr(); replace_this(text); menu::save(filename, text); return 6; break;
case 7:clrscr(); return 0; break;
case 6:clrscr(); replace_all(text); menu::save(filename, text); return 7; break;
default: gotoxy(18,36);
cout<<"Invalid choice, Press <enter>";
gotoxy(36,34);
}
cin>>choice;
}
};
class file
{
void create_file()
{
int filecount=0;
char file_no[33];
char untitled[]="Untitled";
char filename[80];
itoa(filecount++, file_no, 10);
strcpy(filename, untitled);
strcat(filename, file_no);
strcat(filename, ".txt");
ofstream file;
file.open(filename);
file.close();
cout<<"File successfully created";
}
void save()
{
char nam[21];
cout<<"\n Enter a name for your file";
cin.getline(nam,21);
if(strcmp(nam,"") == 0)
ey h1("Untitled.txt");
h1.write();
}
else
{
hey h2(nam);
h2.write();
}
ofstream output_file;
output_file.open((const char*)"C:\\Users\\Abhishek\\Desktop\\hello.txt");
char s[100];
input_file>>s;
cout<<s;
}
public:
void write()
{
ofstream file;
file.open(filename,ios::out);
char reply;
do
{
cout<<"\nEnter a line";
char line[41];
cin.getline(line,41);
file << line << endl;
cout<<"\nEnter again ?";
cin >> reply;
cin.get();
} while(reply=='y'||reply=='Y');
file.close();
}
private:
int funda()
{
int i;
gotoxy(23,14); cout<<"File :" ;
gotoxy(23,16); cout<<"1) Create New File";
gotoxy(23,18); cout<<"2) Save";
gotoxy(23,20); cout<<"3) Close";
gotoxy(23,22); cout<<"4) Back";
gotoxy(18,26); cout<<"What would you like to open?? Enter the number";
gotoxy(23,34); cout<<"Enter Here: [ ]";
gotoxy(36,34);
int choice;
cin>>choice;
while(choice!=1||choice!=2||choice!=3||choice!=4)
{
switch(choice)
{
case 1:clrscr(); create_file(); clrscr(); write(); return 1; break;
case 2:clrscr(); save(); return 2; break;
case 3:clrscr(); cout<<"\nThanks for using this, Press <enter>"; exit(9); return 4; break;
case 4:clrscr(); return 0; break;
default: gotoxy(18,36);
cout<<"Invalid choice, Press <enter>";
gotoxy(36,34);
}
cin>>choice;
}
}
};
class tools
{
private:
int length;
void colour(string str)
{
int count = 0;
gotoxy(23,14);cout<<"The various colours available are : ";
for(int i = 0; i<9; i++)
{
textcolor(i); gotoxy(23,14+2*i) cout<< i+1<< ") TEXT COLOR";
}
do
{
count++;
if(count) cout<<"\n\t\t\t\tPlease enter correctly or this message will keep occurring";
gotoxy(23,14+2*i); cout<<"Select textcolor, Enter number: "; cin>>i;
}while(i<10);
textcolor(i-1);
cout<<str;
}
void background(string str)
{
int count = 0;
gotoxy(23,14);cout<<"The various Background colours available are: ";
for(int i = 0; i<9; i++)
{
textcolor(i); gotoxy(23,14+2*i) cout<< i+1<< ") TEXT COLOR";
}
do
{
count++;
if(count) cout<<"\n\t\t\t\tPlease enter correctly or this message will keep occurring";
gotoxy(23,14+2*(i+1)); cout<<"Select textcolor, Enter number: "; cin>>i;
}while(i<11);
textbackground(i-1);
clrscr();
cout<<str;
}
void font(string str)
{
gotoxy(23,14);cout<<"The various fonts available are: ";
for(int i = 0; i<=10; i++)
{
settextstyle(i,HORIZ_DIR,1);
outtextxy(23, 14+25*(i+1), "Font" ));
cout<<"\t no:"<<i+1;
}
cout<<"\n\t\tSelect a font number:"; cin>>i;
settextstyle(i-1, HORIZ_DIR, 1);
outtextxy(10,10, str);
}
public:
int funda(char filename[80])
{
string text;
ifstream t;
t.open(filename);
if(!t){cerr<<"\n\t\t\t\tNot found, Invalid"; menu::funda();}
t.seekg(0, std::ios::end);
length = t.tellg();
t.seekg(0, std::ios::beg);
text = new char[length];
t.read(text, length);
t.close();
gotoxy(23,14); cout<<"Tools :" ;
gotoxy(23,16); cout<<"1) Font";
gotoxy(23,18); cout<<"2) Colour";
gotoxy(23,20); cout<<"3) Background Colour";
gotoxy(23,22); cout<<"4) Back";
gotoxy(18,32); cout<<"What would you like to open?? Enter the number";
gotoxy(23,34); cout<<"Enter Here: [ ]";
gotoxy(36,34);
int choice;
cin>>choice;
while(choice!=1||choice!=2||choice!=3||choice!=4)
{
switch(choice)
{
case 1:clrscr(); font(text); menu::save(filename, text); return 1; break;
case 2:clrscr(); colour(text); menu::save(filename, text); return 3; break;
case 3:clrscr(); background(text); menu::save(filename, text); return 4; break;
case 4: return 0; break;
default: gotoxy(18,36);
cout<<"Invalid choice, Press <enter>";
gotoxy(36,34);
}
cin>>choice;
}
};
class view
{
void v_open(char filename[80])
{
ifstream f;
f.open(filename, ios::in);
if(!f){cerr<<"\n\t\t\t\tError"; menu::funda();}
char line[50];;
f.getline(line,50);
while(!f.eof())
{
cout<<line<<endl;
file.getline(line,50);
}
}
int funda(char filename[80])
{
ifstream t;
t.open(filename);
if(!t){cerr<<"\n\t\t\t\tNot found, Invalid"; menu::funda();}
t.close();
gotoxy(23,14); cout<<"View :" ;
gotoxy(23,16); cout<<"1) Open";
gotoxy(23,18); cout<<"2) Back";
gotoxy(18,32); cout<<"What would you like to open?? Enter the number";
gotoxy(23,34); cout<<"Enter Here: [ ]";
gotoxy(36,34);
int choice;
cin>>choice;
while(choice!=1||choice!=2)
{
switch(choice)
{
case 1:clrscr(); v_open(filename); return 1; break;
case 2:clrscr(); return 0; break;
default: gotoxy(18,36);
cout<<"Invalid choice, Press <enter>";
gotoxy(36,34);
}
cin>>choice;
}
}
};
class menu : protected edit, protected tools, protected view, protected file//help
{
private:
char filename[80];
string str;
int valid(char choice)
{
if(choice == 'f' || choice == 'e' || choice == 't' || choice =='h' || choice == 'v')
return 1;
else return 0;
}
public:
void funda()
{
clrscr();
gotoxy(2,2);
cout<<"File Edit Tools View Help";
gotoxy(23,20);
cout<<"What would you like to do??";
gotoxy(23,22);cout<<"Enter Here: [ ]";
gotoxy(36,22);
char choice;
cin>>choice;
tolower(choice);
while(!valid(choice))
{
int i;
switch(choice)
{
case "f": clrscr(); cout<<"\n\t\t\t\tEnter File name;" cin>>filename; i = file::funda(filename);
if(!i) choice = 'z';
break;
case "e": clrscr(); cout<<"\n\t\t\t\tEnter File name;" cin>>filename; i = edit::funda(filename);
if(!i) choice = 'z';
break;
case "v": clrscr(); cout<<"\n\t\t\t\tEnter File name;" cin>>filename; i = view::funda(filename);
if(!i) choice = 'z';
break;
case "t": clrscr(); cout<<"\n\t\t\t\tEnter File name;" cin>>filename; i = tools::funda(filename);
if(!i) choice = 'z';
break;
case "h": clrscr(); cout<<"\n\t\t\t\tEnter File name;" cin>>filename; i = help::funda(str);
if(!i) choice = 'z';
break;
default: gotoxy(20,24);
cout<<"Invalid entry, Press <Enter>, refer Help by typing H above";
cin.get();
}
gotoxy(36,22);
cin>>choice;
}
}
void save(char filename[80], string str)
{
ofstream f;
f.open(filename,ios::out);
if(!f){cerr<<"\n\t\t\t\tWrong"; funda();}
f.write(str);
file.close();
}
};
void main()
{
textbackground(WHITE);
textcolor(BLACK);
clrscr();
menu m;
cout<<"\n\t\t\t\tWelcome to funda word processor. Please Press Enter";
cin.get();
m.funda();
}
Using Dev c++, tested using Turbo c++ compiler, It cannot recognise string

New Topic/Question
Reply



MultiQuote







|