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

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

PPTX
Lecture 1
marvellous2
 
PDF
Assignment
MrunalMehta4
 
DOCX
CLASS VIII COMPUTERS FLOW CHART AND ALGORITHM
Rc Os
 
DOCX
Compiler lab final report writing
Umme habiba
 
PPTX
Lecture 6: linked list
Vivek Bhargav
 
PPTX
Chapter 6 - Intermediate Languages.pptxjfjgj
Shemse Shukre
 
PPTX
basic C PROGRAMMING for first years .pptx
divyasindhu040
 
PPTX
F# Console class
DrRajeshreeKhande
 
PDF
Theory of automata and formal language lab manual
Nitesh Dubey
 
PDF
NoteThe menu should contain the following optionsCapitalize .pdf
fedosys
 
DOCX
C++ Please write the whole code that is needed for this assignment- wr.docx
BrianGHiNewmanv
 
PDF
java or oops class not in kerala polytechnic 4rth semester nots j
ishorishore
 
PDF
Module_1_Introduction-to-Problem-Solving.pdf
MaheshKini3
 
PDF
The New Yorker cartoon premium membership of the
shubhamgupta7133
 
PPTX
Python Lecture 2
Inzamam Baig
 
PPTX
Introduction to computer_lec_04_fall_2018
Ramadan Babers, PhD
 
PDF
Question 1 has already been posted to Chegg and I am waiting for the.pdf
anjandavid
 
PPTX
unit1.pptx for python programming CSE department
rickyghoshiit
 
PDF
Lab6: I/O and Arrays
enidcruz
 
Lecture 1
marvellous2
 
Assignment
MrunalMehta4
 
CLASS VIII COMPUTERS FLOW CHART AND ALGORITHM
Rc Os
 
Compiler lab final report writing
Umme habiba
 
Lecture 6: linked list
Vivek Bhargav
 
Chapter 6 - Intermediate Languages.pptxjfjgj
Shemse Shukre
 
basic C PROGRAMMING for first years .pptx
divyasindhu040
 
F# Console class
DrRajeshreeKhande
 
Theory of automata and formal language lab manual
Nitesh Dubey
 
NoteThe menu should contain the following optionsCapitalize .pdf
fedosys
 
C++ Please write the whole code that is needed for this assignment- wr.docx
BrianGHiNewmanv
 
java or oops class not in kerala polytechnic 4rth semester nots j
ishorishore
 
Module_1_Introduction-to-Problem-Solving.pdf
MaheshKini3
 
The New Yorker cartoon premium membership of the
shubhamgupta7133
 
Python Lecture 2
Inzamam Baig
 
Introduction to computer_lec_04_fall_2018
Ramadan Babers, PhD
 
Question 1 has already been posted to Chegg and I am waiting for the.pdf
anjandavid
 
unit1.pptx for python programming CSE department
rickyghoshiit
 
Lab6: I/O and Arrays
enidcruz
 

More from rtodd884 (7)

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

Recently uploaded (20)

PDF
CEREBRAL PALSY: NURSING MANAGEMENT .pdf
PRADEEP ABOTHU
 
PDF
BÀI TẬP BỔ TRỢ TIẾNG ANH 8 - GLOBAL SUCCESS - CẢ NĂM - NĂM 2024 (VOCABULARY, ...
Nguyen Thanh Tu Collection
 
PDF
Reconstruct, Restore, Reimagine: New Perspectives on Stoke Newington’s Histor...
History of Stoke Newington
 
PDF
The dynastic history of the Chahmana.pdf
PrachiSontakke5
 
PDF
The-Ever-Evolving-World-of-Science (1).pdf/7TH CLASS CURIOSITY /1ST CHAPTER/B...
Sandeep Swamy
 
PPTX
SPINA BIFIDA: NURSING MANAGEMENT .pptx
PRADEEP ABOTHU
 
PPT
Talk on Critical Theory, Part II, Philosophy of Social Sciences
Soraj Hongladarom
 
PDF
Dimensions of Societal Planning in Commonism
StefanMz
 
PDF
SSHS-2025-PKLP_Quarter-1-Dr.-Kerby-Alvarez.pdf
AishahSangcopan1
 
PPTX
STAFF DEVELOPMENT AND WELFARE: MANAGEMENT
PRADEEP ABOTHU
 
PDF
The Different Types of Non-Experimental Research
Thelma Villaflores
 
PDF
People & Earth's Ecosystem -Lesson 2: People & Population
marvinnbustamante1
 
PDF
Biological Bilingual Glossary Hindi and English Medium
World of Wisdom
 
PDF
Knee Extensor Mechanism Injuries - Orthopedic Radiologic Imaging
Sean M. Fox
 
PPTX
Soil and agriculture microbiology .pptx
Keerthana Ramesh
 
PPTX
HYDROCEPHALUS: NURSING MANAGEMENT .pptx
PRADEEP ABOTHU
 
PDF
ARAL-Orientation_Morning-Session_Day-11.pdf
JoelVilloso1
 
PDF
CONCURSO DE POESIA “POETUFAS – PASSOS SUAVES PELO VERSO.pdf
Colégio Santa Teresinha
 
PDF
Women's Health: Essential Tips for Every Stage.pdf
Iftikhar Ahmed
 
PPTX
grade 5 lesson matatag ENGLISH 5_Q1_PPT_WEEK4.pptx
SireQuinn
 
CEREBRAL PALSY: NURSING MANAGEMENT .pdf
PRADEEP ABOTHU
 
BÀI TẬP BỔ TRỢ TIẾNG ANH 8 - GLOBAL SUCCESS - CẢ NĂM - NĂM 2024 (VOCABULARY, ...
Nguyen Thanh Tu Collection
 
Reconstruct, Restore, Reimagine: New Perspectives on Stoke Newington’s Histor...
History of Stoke Newington
 
The dynastic history of the Chahmana.pdf
PrachiSontakke5
 
The-Ever-Evolving-World-of-Science (1).pdf/7TH CLASS CURIOSITY /1ST CHAPTER/B...
Sandeep Swamy
 
SPINA BIFIDA: NURSING MANAGEMENT .pptx
PRADEEP ABOTHU
 
Talk on Critical Theory, Part II, Philosophy of Social Sciences
Soraj Hongladarom
 
Dimensions of Societal Planning in Commonism
StefanMz
 
SSHS-2025-PKLP_Quarter-1-Dr.-Kerby-Alvarez.pdf
AishahSangcopan1
 
STAFF DEVELOPMENT AND WELFARE: MANAGEMENT
PRADEEP ABOTHU
 
The Different Types of Non-Experimental Research
Thelma Villaflores
 
People & Earth's Ecosystem -Lesson 2: People & Population
marvinnbustamante1
 
Biological Bilingual Glossary Hindi and English Medium
World of Wisdom
 
Knee Extensor Mechanism Injuries - Orthopedic Radiologic Imaging
Sean M. Fox
 
Soil and agriculture microbiology .pptx
Keerthana Ramesh
 
HYDROCEPHALUS: NURSING MANAGEMENT .pptx
PRADEEP ABOTHU
 
ARAL-Orientation_Morning-Session_Day-11.pdf
JoelVilloso1
 
CONCURSO DE POESIA “POETUFAS – PASSOS SUAVES PELO VERSO.pdf
Colégio Santa Teresinha
 
Women's Health: Essential Tips for Every Stage.pdf
Iftikhar Ahmed
 
grade 5 lesson matatag ENGLISH 5_Q1_PPT_WEEK4.pptx
SireQuinn
 
Ad

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; }