Console Class - OOP344 20121
OOP344 | Weekly Schedule | Student List | Teams | Project | Student Resources
Contents
Release
- 0.1
Notes
- Using Linux: please use putty only and set the keyboard to
- Backspace = Ctrl-?
- Home and End = Standard
- Function keys and keypad = Linux
- And then:
- Connection > Data > Terminal-type string = linux (This step must be done when first connecting through putty!)
- Guide for Using Borland 5.5
- Note that to change the cmd.exe window size, right click on the top bar -> Properties -> Layout Tab
Due Dates
- Wed, Feb 1st, 23:59
Help Needed
- How to submit?
- I will issue the submission instructions soon, for now, please wait. (Fardad)
- I have a problem with tester 4.17
- I have answered your question on my blog since yours is all in Chinese (I think..) I didn't know what button to press...
- Guys, where is the link to the right tester ? When I run that one from SVN - it shows me - cio_test.cpp(700): error C2065: 'CIO_TABSIZE' : undeclared identifier . Does somebody know what is the problem ?
- Did you add the #define CIO_TABSIZE 4 to the console.h header file?
- Yes you have to add this, you can also add it to bconsol.h and fardad hasn't yet updated the tester for submission... --Sezar 6:49pm Feb 01 2012
- Is anyone having the issue where after Test 10, the general test, once it's over and the console asks "Did everything work correctly?", no matter what key you hit, it simply crashes? I have never seen any message saying I've passed all tests or even to keep trying. I pass all tests but the final question, doesn't seem to take my answer. It just displays a 30 near the top area. To recreate what I'm saying, try pressing any other key other than "Y" when you're asked a question. That action is exactly what I'm getting. -- adsantokhi 6:58PM Feb 01.
- Yes, I'm stuck with the same problem and all the other tests passed fine. Just hope it's not the same with the final tester so we can actually submit. -- ktarpomanov 7:16 Feb 01
- please update the cio_test (v0.92) and the final one still not there yet... we have to wait for fardad to update the test for submission!! -- Sezar 7:28 01 Feb 2012
- I'm using v0.92. Still getting this problem. --adsantokhi 7:46PM Feb 01.
- well 30 is the last screen! so you are done all you have to do is just wait for the submission test thats what it says at the end of the test (screen 30).. -- sezar 7:57PM
- is anyone else having problems compiling on matrix? something about "cio_test.cpp:792: warning: deprecated conversion from string constant to 'char" and a billion similar errors on different lines? --apetrus 10:30PM Feb 01
- Those are just warnings for cio_test it's not on your end. It compiles fine just type a.out to run the compiled exe. --ktarpomanov 10:41 Feb 01
- Now it's telling me something about "The row and column of the terminal must be maximum of 30 by 100". Has anyone experienced this problem? Works fine on visual studio -- apetrus 11:35PM Feb 01
- You have to change the buffer size to be a width of 100 and height of 30. Are you sure this is matrix and not on your local pc binary created by borland? Right click on the top of the window (window header) and select properties. From there go to the layout tab and change the "Screen Buffer Size" accordingly. --btulchinsky 23:41 Feb 01
Console Line Editing Facility
As your first assignment, you are to upgrade the basic console input output class (BConsole) to include line-display and line-editing facilities and use of "<<" and ">>" operators for character I/O and string output.
Learning Outcome
Upon successful completion of this first assignment, you will have demonstrated the abilities to design and code
- functions that use the basic console input and output library
- a line editor
Specifications
Your submission consists of class called Console that is to be inherited from BConsole in a namespace called cio. Your application module is fully portable, accepts console input, and provides console output through the set of facilities available in your Console module.
The name of the library object to be created is console. The header file for the original version of this module is console.h and the implementation file for the original version is console.cpp. All of the identifiers for the library module and all upgrades to the module are defined in the cio namespace (short for console input output).
Your upgrade in this assignment consists of creating a class called Console, inherited from BConsole, implemented in two files; console.h and console.cpp:
In addition to all public methods of BConsole, Console must have the following two public methods:
display() method
void display(const char *str, int row, int col, int fieldLen=0);
This method outputs the C-style, null-terminated string pointed to by str starting at row row and column col of the screen in a field of fieldLen characters. Row value 0 refers to the top row, and column value 0 refers to the left-most column. If the string is longer than fieldLen, your function displays the first fieldLen characters. If the string is shorter than fieldLen, your function displays the portion of the entire string that fits on the screen, followed by enough trailing spaces to fill out the field completely. If fieldLen is 0, your function displays the portion of the entire string with no trailing spaces. Your function positions the cursor after the last character displayed. Your function does not flush the output buffer. The results are undefined if the starting position of the string is not within the dimensions of the screen.
edit() method
int edit(char *str, int row, int col, int fieldLength, int maxStrLength, bool* insertMode, int* strOffset, int* curPosition, bool IsTextEditor = false, bool ReadOnly = false);
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.
This shows the edit method function in a diagram below:
A slightly easier to read version of the above image:
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.
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.
Overloading "<<" and ">>" operators
operator>>
Console& operator>>(Console& cn, int& ch);
Get a key from keyboard using cn and store it in ch;
operator<<
Console& operator<<(Console& cn, char ch);
Print the character ch on the screen, where the cursor is located, using cn;
Console& operator<<(Console& cn, const char* str);
print the string str on the screen where the cursor is using cn
Tester Program
Grading
Submission
Compile and test your upgrade with your test main in the following three command-line environments:
Local PC: Borland 5.5
bcc32 bconsole.cpp console.cpp cio_test.cpp
Local PC: Microsoft .net
matrix: GNU (use -lncurses to link ncurses library)
g++ bconsole.cpp console.cpp cio_test.cpp -lncurses
For submission purposes, your solution must compile, link, and run without errors in each environment.
When your program passed all the tests, on matrix, create a direcotry and copy all the source files (console.cpp, console.h, bconsole.cpp, bconsole.h) into it. Then copy cio_test.o from "~fardad.soleimanloo" and then compile your code with your professors version of cio_test (i.e cio_test.o) and run it. If all the tests are passed successfully, an email will be sent to your professor automatically with your source code (console.h and console.cpp).
to copy the cio_test.o do the following.
From the direcotry containing all source files:
$cp ~fardad.soleimanloo/cio_test.o .
to compile the code:
$g++ bconsole.cpp console.cpp cio_test.o -lncurses
This should not generate any warnings.
To run the test (with automatic submission)
$a.out