lines followed by curlinendx being adjusted appropriately finallywe determine if the horizontal position of the cursor must be adjusted if the line to which the cursor has been moved is shorter than the previous linethen the cursor must be positioned at the end of the new line horizontal movement of the cursor is managed by four methodsmoveleft()moveright()movelinehome()and movelineend(moving the cursor to the beginning or end of line simply requires modifying the value of curcolndx moving the cursor horizontally one space can be as simple as adjusting curcolndx by oneexcept when the cursor is at the beginning or ending of the line when moving left or rightrespectively implementation of the moveleft(method is provided in lines - when moving left one space and the cursor is at the beginning of the linethe cursor must be moved to the end of the previous line this can be accomplished by moving the cursor up one line and then to the end of that line of course this is only done if the current line is not the first line in the buffer moving right one space can be implemented in similar fashion the implementation of the remaining cursor movement methods is left as an exercise modifying the buffer moving the cursor is somewhat easier than modifying the contents of the buffer most modifications must consider the newline characterwhich may require splitting line or merging two lines depending on the specific operation we begin our look at buffer modifications with the operation of adding single character the action taken when adding character in the addchar(methodshown in lines - of listing depends on the entry mode and what character is being added in either modewhen adding newline characterthe result is the same as breaking line at the current position and thus this can be done with the breakline(method when the current entry mode is set to insertthe character is always inserted into the vector at the current cursor positionwhich causes the following characters on the same line to shift down one place when inserting character at the end of the linewe are actually inserting it immediately preceding the newline character thusthe newline character will always be the last character in the vector the action taken when adding character in overwrite mode depends on the position of the cursor when the cursor is at the end of linecharacters are inserted in the same fashion as if the entry mode was set to insert the newline character is never overwritten otherwisethe new character simply replaces the character at the cursor position after adding new characterthe cursor is always moved to the right one place this can be done by simply adding one to curcolndx since the cursor never moves to the next line during an add operation unless newline character is being added the latter case is handled by the breakline(method deleting character from the buffer is straightforward if the character is not the newline character it only requires removing or popping the character at the current cursor position within the vector containing the current line the implementation of the deletechar(method is provided in lines - of listing