Ok, I'm wanting to do the following...

A C++ program that can edit a sentence with word insertions and deletions. You can assume
the sentence has words and numbers separated by spaces and punctuation symbols.
The input is a regular text file, where each line is terminated with an end-of-line character(s). Each line will contain a list of words. There are insert, delete and print commands to manipulate the list. Insertion and deletion have the word and position as parameters. Notice worod positions may change after a word is inserted or deleted. The edited string is saved to the output file when the input commands file ends.

Input file example:
This is is an an icorrect sntence

Input commands file example with the print output:

Input Output
delete("is",2)
print "This is an an icorrect sntence"
delete("an",3)
print "This is an icorrect sntence"
delete("icorrect",4)
print "This is an sntence"
insert("incorrect",4)
print "This is an incorrect sntence"
delete("sntence",5)
insert("sentence",4)
print "This is an incorrect sentence"

Output Example:

This is an incorrect sentence.


Does anybody know how to do this? It seems very complicated!

Recommended Answers

All 4 Replies

I'm assuming you are looking for an algorithm?

Are the word insertions and deletions prompted for and controlled by the user? If the editing is controlled by the user, it's pretty easy. You just need to read the string in from the cin, seperate the word being inserted/deleted from the int value which looks to be the location of the word in the sentence, then modify the master string by searching through the white space, finding the appropriate word, then adding or removing it.

No, it's not controlled by the user. ;/

You will need to use a hash table for spelling and grammar. You would need something similar to microsoft word spelling checker and autocomplete function. Sorry, but this is a bit to advanced for me to even begin to understand where to start as far as spelling is concerned.

Iterations of words can be checked easily though.

If word x = word x + 1, then it's an iteration of the same word. The only issue I could see with that is if the iteration is grammatically correct, such as "I told him that that isn't right". That is the only exception I can think of.

No, there is no spell checker. It gets it from the input file. So th spelling isn't concerned.

You get a sentence, then create a list with it. Then the input file,
enumerates a set of operations. Insert, Delete or print. That's what you have to do with the sentences.

Insert element in the list
Delete an element in the list
print your list.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.