SlideShare a Scribd company logo
Problem 1. Text Editor using files and strings using C++ In this project, you should write a
simple line editor. Keep the entire text on a file, one line in a key Enter. Start the program with
entering EDIT file, after which a prompt appears along with the line number. If the letter I is
entered with a number n following it, then insert the text to be followed before line n. If I is not
followed by a number, then insert the text before the current line. If D is entered with two
numbers n and m, one n, or no number following it, then delete lines n through m, line n, or the
current line. Do the same with the command L, which stands for listing lines. If A is entered,
then append the text to the existing lines. Entry E signifies exit and saving the text in a file. Here
is an Example: EDIT testfile 1>The first line 2> 3> And another line 4>I3 3> The second line 4>
One more line 5> L 1>The first line 2> 3> The second line 4> One more line 5> And another
line // This is now line 5, not 3; 5> D2 // line 5, since L was issued from line 5; 4> L //line 4,
since one line was deleted; The first line 2> The second line // this and the following lines 3>
One more line // now have new numbers 4> And another line 4> E
Solution
I did for Insert and exit only
#include <iostream>
#include <fstream>
#include <stdlib.h>
#include <string.h>
#include <limits>
using namespace std;
std::fstream& GotoLine(fstream& file, unsigned int num){
file.seekg(ios::beg);
for(int i=0; i < num - 1; ++i){
file.ignore(numeric_limits<streamsize>::max(),' ');
}
return file;
}
int main()
{
char command;
char character; string dataLine;
int line=0,lineNumber=0;
ifstream dataFile;
dataFile.open("myFile.txt");
cout << "File Data is : ";
while(getline(dataFile,dataLine)){
cout << dataLine << " " ;
lineNumber++;
}
cout << " Enter File operation :";
cin >> command;
cin >> line;
switch(command)
{
case 'I':
if(line <= 0)
{
}
else{
fstream file("myFile.txt");
ofstream newFile;
newFile.open("myFile.txt", std::ios_base::app);
GotoLine(file,line);
newFile << " other line after " << line;
}
break;
case 'D':
if(line <= 0)
{
}
else{
}
break;
case 'A':
if(line <= 0)
{
}
else{
}
break;
case 'L':
if(line <= 0)
{
}
else{
}
break;
case 'E':
cout << "thank YOU: ";
exit(0);
}
return 0;
}

More Related Content

PDF
#include iostream #include cstring #include vector #i.pdf
PDF
IN C++ languageWrite a simple word processor that will accept text.pdf
PDF
Objectives 1. Understand the design, implementation, usage and limita.pdf
DOCX
C++ Loops General Discussion of Loops A loop is a.docx
PPTX
Programming Fundamentals lecture-22.pptx
PPTX
C++ Programming Club-Lecture 3
PPTX
Data file handling in c++
#include iostream #include cstring #include vector #i.pdf
IN C++ languageWrite a simple word processor that will accept text.pdf
Objectives 1. Understand the design, implementation, usage and limita.pdf
C++ Loops General Discussion of Loops A loop is a.docx
Programming Fundamentals lecture-22.pptx
C++ Programming Club-Lecture 3
Data file handling in c++

Similar to Problem 1- Text Editor using files and strings using C++ In this proje.docx (20)

PDF
please help!! C++ Program D@t@ Structur3ss classplease comment cod.pdf
PPT
FP 201 - Unit 3 Part 2
PPT
File in cpp 2016
DOCX
Lab Manual Data Structure and Algorithm.docx
DOC
Labsheet_3
DOCX
Exmaples of file handling
PPTX
MUST CS101 Lab11
DOCX
Text editors project
PPTX
File_Handling_Slides_v2 of C++ (Bs CS.pptx
PPTX
Overview of c++ language
DOCX
Design problem
PPTX
Pf cs102 programming-8 [file handling] (1)
PDF
C++ Course - Lesson 1
PDF
C++ and OOPS Crash Course by ACM DBIT | Grejo Joby
PPTX
working with files
PPTX
Object Oriented Programming Using C++: Ch12 Streams and Files.pptx
PPTX
Object Oriented Programming using C++: Ch12 Streams and Files.pptx
PDF
c++ lab manual
PPTX
Lesson 2 starting output
DOCX
Satz1
please help!! C++ Program D@t@ Structur3ss classplease comment cod.pdf
FP 201 - Unit 3 Part 2
File in cpp 2016
Lab Manual Data Structure and Algorithm.docx
Labsheet_3
Exmaples of file handling
MUST CS101 Lab11
Text editors project
File_Handling_Slides_v2 of C++ (Bs CS.pptx
Overview of c++ language
Design problem
Pf cs102 programming-8 [file handling] (1)
C++ Course - Lesson 1
C++ and OOPS Crash Course by ACM DBIT | Grejo Joby
working with files
Object Oriented Programming Using C++: Ch12 Streams and Files.pptx
Object Oriented Programming using C++: Ch12 Streams and Files.pptx
c++ lab manual
Lesson 2 starting output
Satz1
Ad

More from rtodd884 (7)

DOCX
Poly-meta-morphic malware looks different each time it is stored on di.docx
DOCX
Please write a formal summary of the case before proceeding to answer.docx
DOCX
Please respond in detail with an example- Thank you! Financial interme.docx
DOCX
Presented below is the balance sheet of Sargent Corporation for the cu.docx
DOCX
Presented below is information related to Dino Radja Company- Date End.docx
DOCX
Prepare the journal entry to record salaries payable for the month of.docx
DOCX
Prepare a short --talking points-- paper in which you identify and dis.docx
Poly-meta-morphic malware looks different each time it is stored on di.docx
Please write a formal summary of the case before proceeding to answer.docx
Please respond in detail with an example- Thank you! Financial interme.docx
Presented below is the balance sheet of Sargent Corporation for the cu.docx
Presented below is information related to Dino Radja Company- Date End.docx
Prepare the journal entry to record salaries payable for the month of.docx
Prepare a short --talking points-- paper in which you identify and dis.docx
Ad

Recently uploaded (20)

PDF
Chapter 2 Heredity, Prenatal Development, and Birth.pdf
PDF
Microbial disease of the cardiovascular and lymphatic systems
PDF
Anesthesia in Laparoscopic Surgery in India
PPTX
Institutional Correction lecture only . . .
PPTX
Microbial diseases, their pathogenesis and prophylaxis
PDF
STATICS OF THE RIGID BODIES Hibbelers.pdf
PDF
Module 4: Burden of Disease Tutorial Slides S2 2025
PPTX
human mycosis Human fungal infections are called human mycosis..pptx
PDF
O7-L3 Supply Chain Operations - ICLT Program
PDF
A systematic review of self-coping strategies used by university students to ...
PDF
FourierSeries-QuestionsWithAnswers(Part-A).pdf
PPTX
school management -TNTEU- B.Ed., Semester II Unit 1.pptx
PDF
A GUIDE TO GENETICS FOR UNDERGRADUATE MEDICAL STUDENTS
PPTX
master seminar digital applications in india
PDF
ANTIBIOTICS.pptx.pdf………………… xxxxxxxxxxxxx
PPTX
1st Inaugural Professorial Lecture held on 19th February 2020 (Governance and...
PDF
Chinmaya Tiranga quiz Grand Finale.pdf
PPTX
GDM (1) (1).pptx small presentation for students
PPTX
202450812 BayCHI UCSC-SV 20250812 v17.pptx
PDF
VCE English Exam - Section C Student Revision Booklet
Chapter 2 Heredity, Prenatal Development, and Birth.pdf
Microbial disease of the cardiovascular and lymphatic systems
Anesthesia in Laparoscopic Surgery in India
Institutional Correction lecture only . . .
Microbial diseases, their pathogenesis and prophylaxis
STATICS OF THE RIGID BODIES Hibbelers.pdf
Module 4: Burden of Disease Tutorial Slides S2 2025
human mycosis Human fungal infections are called human mycosis..pptx
O7-L3 Supply Chain Operations - ICLT Program
A systematic review of self-coping strategies used by university students to ...
FourierSeries-QuestionsWithAnswers(Part-A).pdf
school management -TNTEU- B.Ed., Semester II Unit 1.pptx
A GUIDE TO GENETICS FOR UNDERGRADUATE MEDICAL STUDENTS
master seminar digital applications in india
ANTIBIOTICS.pptx.pdf………………… xxxxxxxxxxxxx
1st Inaugural Professorial Lecture held on 19th February 2020 (Governance and...
Chinmaya Tiranga quiz Grand Finale.pdf
GDM (1) (1).pptx small presentation for students
202450812 BayCHI UCSC-SV 20250812 v17.pptx
VCE English Exam - Section C Student Revision Booklet

Problem 1- Text Editor using files and strings using C++ In this proje.docx

  • 1. Problem 1. Text Editor using files and strings using C++ In this project, you should write a simple line editor. Keep the entire text on a file, one line in a key Enter. Start the program with entering EDIT file, after which a prompt appears along with the line number. If the letter I is entered with a number n following it, then insert the text to be followed before line n. If I is not followed by a number, then insert the text before the current line. If D is entered with two numbers n and m, one n, or no number following it, then delete lines n through m, line n, or the current line. Do the same with the command L, which stands for listing lines. If A is entered, then append the text to the existing lines. Entry E signifies exit and saving the text in a file. Here is an Example: EDIT testfile 1>The first line 2> 3> And another line 4>I3 3> The second line 4> One more line 5> L 1>The first line 2> 3> The second line 4> One more line 5> And another line // This is now line 5, not 3; 5> D2 // line 5, since L was issued from line 5; 4> L //line 4, since one line was deleted; The first line 2> The second line // this and the following lines 3> One more line // now have new numbers 4> And another line 4> E Solution I did for Insert and exit only #include <iostream> #include <fstream> #include <stdlib.h> #include <string.h> #include <limits> using namespace std; std::fstream& GotoLine(fstream& file, unsigned int num){ file.seekg(ios::beg); for(int i=0; i < num - 1; ++i){ file.ignore(numeric_limits<streamsize>::max(),' '); } return file; } int main()
  • 2. { char command; char character; string dataLine; int line=0,lineNumber=0; ifstream dataFile; dataFile.open("myFile.txt"); cout << "File Data is : "; while(getline(dataFile,dataLine)){ cout << dataLine << " " ; lineNumber++; } cout << " Enter File operation :"; cin >> command; cin >> line; switch(command) { case 'I': if(line <= 0) { } else{ fstream file("myFile.txt"); ofstream newFile; newFile.open("myFile.txt", std::ios_base::app); GotoLine(file,line); newFile << " other line after " << line; } break; case 'D': if(line <= 0) { } else{ } break; case 'A':
  • 3. if(line <= 0) { } else{ } break; case 'L': if(line <= 0) { } else{ } break; case 'E': cout << "thank YOU: "; exit(0); } return 0; }