Changes

Jump to: navigation, search

Project R0.1 20123- OOP344

7,105 bytes removed, 14:18, 4 October 2012
no edit summary
===edit() method===
<big><pre>
int edit(char *str, int row, int col, int fieldLength, int maxStrLength,
bool* insertMode, int* strOffset, int* curPosition,
bool IsTextEditor = false, bool ReadOnly = false);
</pre></big>
 
This method is to be written in two steps.
====Step one====
''Ignore the last two arguments of the the edit method '''(IsTextEditor and ReadOnly)''' and write the method as follows:''
 
This methods edits the C-style, null-terminated string pointed to by str. The parameter row holds the row (0 is the top row) of the string on the screen. The parameter col holds the starting column (0 is the left-most column) on the screen. The parameter fieldLength holds the length of the editable field. The string may be larger than the field itself, in which case part of the string is hidden from view. The parameter maxStrLength holds the maximum length of the string, excluding the null byte. The parameter insertMode points to a bool variable that holds the current insert mode of the string. The parameter insertMode receives the address of a variable that stores the current editing mode - insert or overwrite. The parameter strOffset points to an int variable that holds the initial offset of the string within the field; that is, the index of the character in the string that initially occupies the first character position in the field. The parameter curPosition points to an int variable that holds the initial cursor position within the field; that is, the index of the character in the field at which the cursor is initially placed.
 
If the initial offset is beyond the end of the string, your function resets the offset to the length of the string; that is, to the index of the character immediately beyond the end of the string. If no offset variable is pointed to; that is, if the address of the variable is NULL, your function sets the offset to the index of the first character in the string; that is, to 0.
 
If the initial cursor position is beyond the end of the field, your function resets the position to the last character in the field. If the position is beyond the end of the string, your function resets the position to that immediately beyond the end of the string. If no cursor position variable is pointed to; that is, if the address of the variable is NULL, your function sets the cursor position to the first position in the field; that is, to position 0.
 
Your function does not allow the cursor to move before the start of the field or past the end of the field. If the field ends at the right edge of the screen, your function does not allow the cursor to the right of that edge.
 
Your function uses the symbolic names for non-ASCII and special keys defined in the keys.h header file. These names are the same symbolic names as those used in the original library module.
 
The user terminates editing by pressing ENTER, TAB, ESCAPE, UP, DOWN, PGUP, PGDN or any of the function keys F(1) through F(12) inclusive. If the user presses ESCAPE, your function aborts editing, replaces the contents of the string with the original contents upon entry into your function, and leaves the offset and cursor position values unaltered. In order to be able to revert to the original string, your function needs to allocate memory at run time.
 
At termination, your function passes back through the same int variables the current values of the offset and the cursor position, unless no variables were pointed to upon entry into your function; that is, unless the value of either address was NULL.
 
Your function returns an int identifying the key that the user pressed to exit the function.
 
Your function takes no action (other than perhaps beeping) if the user tries to enter too many characters (if, for example, the string is full in insert mode, or the cursor is positioned after the last character of a full string in overstrike mode).
 
Your function handles the non-ASCII keys as follows
 
*LEFT - moves the cursor left one character, if possible, changing the offset, if necessary.
*RIGHT - moves the cursor right one character, if possible, changing the offset, if necessary.
*HOME - moves the cursor to the beginning of the string, changing the offset, if necessary.
*END - moves the cursor to the position to the right of the last character in the string, changing the offset, if necessary. If the last character is at the edge of the screen, moves the cursor to that character.
*INSERT - toggles Insert/Overstrike mode. In Insert mode, your function inserts a printable character into the string at the current cursor position, moves the remainder of the string to the right to make room for the inserted character, and positions the cursor just to the right of the inserted character. The printable characters are the characters from space (' ') to tilde ('~') inclusive in the ASCII table. In Overstrike mode, your function overwrites the character (if any) at the current cursor position with a printable character and advances the cursor just to the right of the new character. If the cursor is past the end of the string, your function appends a printable character to the string as long as the string isn't full, regardless of the mode.
*DEL - discards the character at the current cursor position and moves all characters to the right of the cursor position one position to the left.
*BACKSPACE - discards the character to the left of the current cursor position, if possible, moves the characters at and to the right of the cursor position one position to the left, if possible, and positions the cursor one character to the left, if possible.
 
edit() always displays blanks in any part of the field that is not occupied by the string. UNDER NO CIRCUMSTANCES DOES YOUR FUNCTION CHANGE ANY POSITION ON THE SCREEN OUTSIDE THE FIELD. For example, your function does not display status information (such as "INS" or "OVR") elsewhere on the screen, since such displays limit the programmer's ability to design their own screen layouts.
 
You may assume that it is the calling program's responsibility to ensure that the string array is large enough to handle maxStrLength characters and that the starting screen position provides enough room (on the screen) for the field, etc.
 
 
====Step two====
''First run your program with cio_test.cpp and make sure it passes all the tests up to and including "4.16". If all tests are passed continue with step two:
 
=====IsTextEditor=====
If '''IsTextEditor''' is true and the value of '''*strOffset''' is changed at any time, then terminate the edit function immediately and return '''0''';
======TAB key======
If '''IsTextEditor''' is true and TAB key is hit, then instead of terminating the function, ''CIO_TABSIZE'' spaces are inserted into ''str''.
'''''CIO_TABSIZE is to be global variable (unsigned integer initially set to be 4) to hold the number of spaces to be inserted when tab is hit.'''''
=====ReadOnly=====
If '''ReadOnly''' is true, then edit function works exactly like before, except that any modification to the data (the content of the '''str''' string) will be ignored.
===Overload "<<" and ">>" operators===

Navigation menu