Hello everyone,,
Can anyone help me with this program please??
----------------------------------------------------------------------
This assignment requires you to write a simple text editor. Your editor will have the following commands:
e filename edits the filename if it exists
If it doesn’t exist, then you’ll be creating a new file.
i (insert mode) insert any number of lines after current line.
Ctrl- v stop inserting data (turn off insert mode)
l list the entire file without line numbers
n list the entire file with line numbers
d n delete the number n
c count the numbr of lines in the file
s save the file opened with the e command
p print the file
q quit the program prompting for save if the file has not been saved
Once your program begins, a prompt must appear on the screen. Commands can be entered following the prompt. A sample run of program is shown below:
> e welcome.cpp
> i
#include <iostream>
using namespace std;
void main ()
{
cout<<”Welcome to Etisalat College”<<endl;
}
^V
1) #include <iostream>
2) using namespace std;
3) void main ()
4) {
5) cout<<”Welcome to Etisalat College”<<endl;
6) }
> c
welcome.cpp has 6 lines
> s
saved welcome.cpp
> p
printing welcome.cpp
> q
================================================== =======
This is the program:
Code:
#include<iostream>
#include<fstream>
using namespace std;
int main ()
{
char letter;
ofstream printer (“USB001”, ios::out);ccout<<”+++++++Welcome to this editor program++++++++”<<endl;
cout<<”i: insert mode” <<endl;
cout<<””ctrl-v: turn off insert mode”<<endl;
cout<<”l: list the entire file without line numbers”<<endl;
cout<<”n: list the entire file with line numbers”<<endl;
cout<<”d n”: delete line number n”<<endl;
cout<<”c: count the number of lines in the file”<<endl;
cout<<”s: save the file opened with the e command”<<endl;
cout<<”q: quit the program prompting for save if the file has not been saved”<<endl;
cout<< ”<<”;
cin>>letter;
while (letter != ‘q’)
{
ifstream infile (“sample.txt”, ios::in);
switch (letter)
{
case ‘p’:
char a;
while (infile.get(a))
printer<<a;
cout<<”Printing”<<infile<<endl;
cout<< “<<”;
cin>>letter;
break;
case ‘s’:
cout<<”Your file is being saved”<<endl;
cout<< “<<”;
cin>>letter;
break;
case ‘n’ ;
int count;
count=1;
char c;
start:
cout<<count << “)”;
while (infile.get(c ) )
{
cout<<c;
if (c= = ‘\n’)
{
++count;
goto start;
}}
cout<<endl<< “<”;
cin>>letter;
break;
case ‘c’;
int counter;
counter= 1;
char d;
while (infile.get(d))
{
if (d= =’\n’)
{
++counter;
}}
if ( counter! =1)
cout<<”Sample.txt has “<<counter<<”lines”;
else if ((counter= =1) && (d= =’\0’))
cout<<”the file sample.txt contains no lines”;
else
cout<<”the file contains only 1 line”;
cout<<endl<< “<”;
cin>>letter;
break;
case’i’:
char in;
while (infile.get(in))
cout<<endl<< “<”;
cin>>letter;
break;
case”l”:
while (infile.get(in))
cout<<in;
cout<<endl<< “<”;
cin>>letter;
break;
default:
cout<<”invalid choice”<<endl;
cout<< ”<”;
cin>>letter;
break;
}}
return 0;
}
================================================== ======
Can anyone tell me how to do the "ctrl-v" and "delete" ???
and is there any other method other than using switch and cases??
ThanX ver much indeed
