Difference between revisions of "Project R0.1 20132- OOP344"

From CDOT Wiki
Jump to: navigation, search
(Help Needed)
(How to submit)
 
(5 intermediate revisions by 2 users not shown)
Line 1: Line 1:
{{OOP344 Index | 20131}}
+
{{OOP344 Index | 20133}}
  
 
=Release=
 
=Release=
Line 10: Line 10:
 
*: And then:
 
*: And then:
 
*: Connection > Data > Terminal-type string = linux (This step must be done when first connecting through putty!)
 
*: Connection > Data > Terminal-type string = linux (This step must be done when first connecting through putty!)
*:: Or if you have already connected, type in (export TERM="linux") without brackets
+
<!--*:: Or if you have already connected, type in (export TERM="linux") without brackets
**: If you're still having problems do all of that AND (export TERM="linux") and it will allow you to use END and HOME, though the F keys still won't work.
+
** If you're still having problems do all of that AND (export TERM="linux") and it will allow you to use END and HOME, though the F keys still won't work. -->
 
* [https://cs.senecac.on.ca/~chris.szalwinski/resources/borland.html Guide for Using Borland 5.5]
 
* [https://cs.senecac.on.ca/~chris.szalwinski/resources/borland.html Guide for Using Borland 5.5]
 
*: Note that to change the cmd.exe window size, right click on the top bar -> Properties -> Layout Tab
 
*: Note that to change the cmd.exe window size, right click on the top bar -> Properties -> Layout Tab
  
 
=Due Dates=
 
=Due Dates=
Monday June 17th.
 
  
 
=Help=
 
=Help=
==Help Needed==
+
Please blog about your problems and notes and add the link with a proper title below.<br />
* <strike>Bug(?): The insert mode in our assignment works as it is supposed to but fails the test when running the test program. Has anyone else encountered this problem, or is this an error on my side?</strike>
+
Reply to others blogs to help and update the blog link to indicate you replied to them.  
 
 
I had the same problem. Try to replace the original code '''Console::_insertMode''' by just '''insertMode'''. It works for me. Otherwise it is local I guess. So it works within your application but does not react to parameter passed to the function.
 
 
 
Thank you.  I actually solved it by making insertMode=Console::_insertMode.
 
 
 
* Just noticed that the return string for the 4-6 test is wrong.  It checks to see if you've inserted 'ab' into the string, and not 'abc' like the dialog box asks for.  If you insert only 'ab' the test passes as it should.
 
 
 
* In test 4.9 (END button), the test gives the string which stays in the middle of the field, is that OK?! I see that kind of a weird situation. In that case it fails the END button test, because values for curPosition & strOffset are not right. Ideas?
 
 
 
You want to set the curPosition=size-*strOffset.  This will mean that it scrolls down the string to the end if the length of the string is longer than the field, but only move to the end of the string if it isn't, which allows for having the string stay in the middle of the field as in the test.  When you do this, though, don't forget that you need to make sure that, when the curPosition goes outside the field, the curPosition and offset are changed accordingly.
 
 
 
* Anyone know where/how to submit when it's complete?
 
 
 
If I'm not mistaking the test program should submit it in the end of the testing automatically.
 
 
 
No, once you reach the end it says "Wait for the final tester to submit the assignment".  Unless there's another program around that I'm not aware of.
 
 
 
 
==Blog Posts==
 
==Blog Posts==
  
Line 52: Line 34:
 
==Specifications==
 
==Specifications==
  
Your submission consists of a class called Console that is to be inherited from BConsole in a namespace called '''cui'''.  Your application module is fully portable across Borland C++5.5 on windows, Linux GNU C++, Viusual C++ on Windows and Mac C++ platforms which accepts console input, and provides console output through the set of facilities available in your Console module.  
+
Your submission consists of a class called Console that is to be inherited from BConsole in a namespace called '''cio'''.  Your application module is fully portable across Borland C++5.5 on windows, Linux GNU C++, Viusual C++ on Windows and Mac C++ platforms which 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 cui namespace (short for console input output).
+
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:
 
Your upgrade in this assignment consists of creating a class called Console, inherited from BConsole, implemented in two files; console.h and console.cpp:
Line 60: Line 42:
 
In addition to all public methods of BConsole, Console must have the following two public methods and overload "<<" and ">>" operators.
 
In addition to all public methods of BConsole, Console must have the following two public methods and overload "<<" and ">>" operators.
 
===external links===
 
===external links===
* instantiate Console, in an object called "console" in cui namespace and create an external linkage to in console.h
+
* instantiate Console, in an object called "console" in cio namespace and create an external linkage to in console.h
===strdsp() method===
+
===display() method===
 
  void display(const char* str, int row, int col, int fieldLen=0, int curpos = -1);  
 
  void display(const char* str, int row, int col, int fieldLen=0, int curpos = -1);  
  
Line 72: Line 54:
 
Your function positions the cursor after the last character displayed if curpos is less than zero otherwise it positions the cursor at "curpos" location relative to "col". The results are undefined if the starting position of the string is not within the dimensions of the screen.
 
Your function positions the cursor after the last character displayed if curpos is less than zero otherwise it positions the cursor at "curpos" location relative to "col". The results are undefined if the starting position of the string is not within the dimensions of the screen.
  
===lineedit() method===
+
===edit() method===
  
 
<big><pre>
 
<big><pre>
     int  lineedit(char *str, int row, int col, int fieldLength, int maxStrLength,  
+
     int  edit(char *str, int row, int col, int fieldLength, int maxStrLength,  
 
         int* strOffset=_stroff, int* curPosition=_curpos,   
 
         int* strOffset=_stroff, int* curPosition=_curpos,   
 
         bool InTextEditor = false, bool ReadOnly = false, bool& insertMode=_insertMode );
 
         bool InTextEditor = false, bool ReadOnly = false, bool& insertMode=_insertMode );
Line 124: Line 106:
  
 
====Step two====
 
====Step two====
''First run your program with cui_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:
+
''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:
  
 
=====InTextEditor=====
 
=====InTextEditor=====
Line 147: Line 129:
 
=Submission=
 
=Submission=
 
==Common Submission mistakes==
 
==Common Submission mistakes==
<!--* Submitting the assignment with old version of cui_text.o
+
TBA
 +
<!--* Submitting the assignment with old version of cio_text.o
 
*: ''Make sure you copy the latest version (currently 0.94.1) from my account : $cp ~fardad.soleimanloo/cio_test.o
 
*: ''Make sure you copy the latest version (currently 0.94.1) from my account : $cp ~fardad.soleimanloo/cio_test.o
 
* Using tab character''
 
* Using tab character''
 
*: ''As mentioned in class using tab character in your text editor makes the indentation of your code different in different editors, please make sure before submission you go to the settings of your development environment and make sure it uses spaces instead of tab character.'' -->
 
*: ''As mentioned in class using tab character in your text editor makes the indentation of your code different in different editors, please make sure before submission you go to the settings of your development environment and make sure it uses spaces instead of tab character.'' -->
 
==Tester Demo==
 
==Tester Demo==
 +
TBA
 
<!--To see how tester runs, you can run on Matrix (only use putty with the setting stated at [[#Notes|Notes]]) run:
 
<!--To see how tester runs, you can run on Matrix (only use putty with the setting stated at [[#Notes|Notes]]) run:
 
<big><pre>
 
<big><pre>
$ ~fardad.soleimanloo/cui_test
+
$ ~fardad.soleimanloo/cio_test
 
</pre></big> -->
 
</pre></big> -->
  
Line 161: Line 145:
  
 
Local PC: Borland 5.5     
 
Local PC: Borland 5.5     
  bcc32 bconsole.cpp console.cpp cui_test.cpp
+
  bcc32 bconsole.cpp console.cpp coi_test.cpp
  
 
Local Mac: (use -lcurses to link curses library)
 
Local Mac: (use -lcurses to link curses library)
  c++ bconsole.cpp console.cpp cui_test.cpp -lcurses -Wno-write-strings
+
  c++ bconsole.cpp console.cpp coi_test.cpp -lcurses -Wno-write-strings
  
 
matrix: GNU (use -lncurses to link ncurses library)
 
matrix: GNU (use -lncurses to link ncurses library)
  g++ bconsole.cpp console.cpp cui_test.cpp -lncurses -Wno-write-strings
+
  g++ bconsole.cpp console.cpp cio_test.cpp -lncurses -Wno-write-strings
  
 
Local PC: Visual Studio.net
 
Local PC: Visual Studio.net
 
=== Tester Program ===
 
=== Tester Program ===
*Tester program is at git://github.com/Seneca-OOP344/20132notes.git (Notes repository) in '''TesterPrograms''' directory.
+
<!--*Tester program is at git://github.com/Seneca-OOP344/20132notes.git (Notes repository) in '''TesterPrograms''' directory.
 
*repo path:<br/>
 
*repo path:<br/>
*:[https://github.com/Seneca-OOP344/20132notes.git 20132notes]/TesterPrograms/cui_test.cpp
+
*:[https://github.com/Seneca-OOP344/20132notes.git 20132notes]/TesterPrograms/cio_test.cpp -->
  
 
==How to submit==
 
==How to submit==
<!--For submission purposes, your solution must compile, link, and run without errors in each environment.  
+
TBA
 +
<!--
 +
For submission , your solution must compile, link, and run without errors in each environment.  
  
First pull the changes of the two files bconsole.cpp and bconsole.h to version 1.02 (Feb 1, 2013) from the console directory in notes repository of your section.
+
First pull the changes of the two files bconsole.cpp and bconsole.h to version 1.03 (jun 1, 2013) from the conui directory in notes repository of your section.
  
Test your program with cio_test.cpp from the same console directory stated above. When your program passed all the tests; on matrix, create a directory and copy all the source files (console.cpp, console.h, bconsole.cpp, bconsole.h) into it. Then copy cio_test.o '<big>''''V 0.94.1'''''</big> 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) attached to it.
+
Test your program with cio_test.cpp from the same conui directory stated above. When your program passed all the tests; on matrix, create a directory 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 Fardad's 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 Fardad automatically with your source code (console.h and console.cpp) attached to it.
  
to copy the cio_test.o do the following.<br />
+
to copy the cio_test.o execute the following on matrix.<br />
 
From the directory containing all source files:
 
From the directory containing all source files:
 
  $cp ~fardad.soleimanloo/cio_test.o .
 
  $cp ~fardad.soleimanloo/cio_test.o .
 
to compile the code:
 
to compile the code:
  $g++ bconsole.cpp console.cpp cio_test.o -lncurses
+
  $ g++ bconsole.cpp console.cpp cio_test.o -lncurses -Wno-write-strings<br />
 
This should not generate any warnings.<br />
 
This should not generate any warnings.<br />
 
To run the test (with automatic submission)
 
To run the test (with automatic submission)
  $ a.out your_student_number Your Full Name as on Student Card <ENTER>
+
  $ a.out TeamNameWithNoSpaces Team Member names separated with commas <ENTER>
 
Example:
 
Example:
  $ a.out 012345678 Home Jay Simpson <ENTER> -->
+
  $ a.out Team-X Fardad Soleimanloo, Joseph Hughes, Homer Simpson, Apu Nahasapeemapetilon <ENTER>
== Tasks Distribution Suggestion==
 
=== Team of 3 ===
 
* Programmer 1
 
*# Tab
 
*# Character Entry
 
*## Overstrike
 
*## Insert Mode
 
* Programmer 2
 
*# Intial Corrections
 
*# Home
 
*# End
 
*# Escape
 
*# Right
 
*# Left
 
*# Enter
 
* Programmer 3
 
*# BackSpace
 
*# Del
 
*# InTextEditor and ReadOnly
 
*# Function keys
 
*# operator>> int&
 
*# operator<< char
 
*# operator<< char*
 
*# Insert
 
 
 
=== Team of 4 ===
 
* Programmer 1
 
*# Character Entry
 
*## Overstrike
 
*## Insert Mode
 
*# End
 
*# Enter
 
* Programmer 2
 
*# Tab
 
*# Home
 
*# operator>> int&
 
*# operator<< char
 
*# operator<< char*
 
* Programmer 3
 
*# BackSpace
 
*# Right
 
*# Del
 
*# Function keys
 
* Programmer 4
 
*# Intial Corrections
 
*# IsTextEditor and ReadOnly
 
*# Escape
 
*# Left
 
*# Insert
 
 
 
 
 
<!--
 
Tab: 23
 
Function keys: 1
 
Overstrike: 15
 
operator>> int& 3
 
operator<< char 3
 
operator<< char* 4
 
Insert: 1
 
 
 
 
 
Intial Corrections: 18
 
Home: 4
 
End: 7
 
Escape: 5
 
Right:  10
 
Left:  4
 
Enter: 1
 
 
 
BackSpace: 23
 
Del: 3
 
Insert Mode: 14
 
IsTextEditor and ReadOnly 10
 
 
 
 
-->
 
-->

Latest revision as of 08:34, 24 September 2013


OOP344 | Weekly Schedule | Student List | Teams | Project | Student Resources

Release

  • 0.1

Notes

  • Using Matrix, from windows: 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

Help

Please blog about your problems and notes and add the link with a proper title below.
Reply to others blogs to help and update the blog link to indicate you replied to them.

Blog Posts

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
  • use of extern
  • operator overload
  • use of namespaces

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.

Specifications

Your submission consists of a class called Console that is to be inherited from BConsole in a namespace called cio. Your application module is fully portable across Borland C++5.5 on windows, Linux GNU C++, Viusual C++ on Windows and Mac C++ platforms which 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 and overload "<<" and ">>" operators.

external links

  • instantiate Console, in an object called "console" in cio namespace and create an external linkage to in console.h

display() method

void display(const char* str, int row, int col, int fieldLen=0, int curpos = -1); 

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) and positions the cursor at "curpos" location relative to "col", only if it is greater or equal to zero.

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 entire string, followed by enough trailing spaces to fill out the field completely.

If fieldLen is 0, your function displays the entire string with no trailing spaces.

Your function positions the cursor after the last character displayed if curpos is less than zero otherwise it positions the cursor at "curpos" location relative to "col". 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, 
        int* strOffset=_stroff, int* curPosition=_curpos,  
         bool InTextEditor = false, bool ReadOnly = false, bool& insertMode=_insertMode );

This method is to be written in two steps.

Step one

Ignore the two arguments (InTextEditor and ReadOnly) for now write the method as follows:

This method edits the C-style, null-terminated string pointed 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.

  • Initial Corrections
    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. (to do this have a local variable for the offset that holds zero to be pointed instead of an external variable)
    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.(like the offset, to do this have a local variable for the cursor position that holds zero to be pointed instead of an external variable)

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, ESCAPE, TAB, 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.

Edit Method Interface
Edit Method Function Diagram
Interface Diagram

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:

InTextEditor

If InTextEditor is true and the value of *strOffset is changed at any time, then terminate the edit function immediately and return 0;

TAB key

If InTextEditor is true and TAB key is hit, then instead of terminating the function, Console::_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.

Overload "<<" 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 and return the cn reference;

Console& operator<<(Console& cn, const char* str);

print the string str on the screen where the cursor is using cn and return the cn reference


Submission

Common Submission mistakes

TBA

Tester Demo

TBA

How to Compile

Compile and test your code with the test-main, in the following command-line environments and visual studio.

Local PC: Borland 5.5

bcc32 bconsole.cpp console.cpp coi_test.cpp

Local Mac: (use -lcurses to link curses library)

c++ bconsole.cpp console.cpp coi_test.cpp -lcurses -Wno-write-strings

matrix: GNU (use -lncurses to link ncurses library)

g++ bconsole.cpp console.cpp cio_test.cpp -lncurses -Wno-write-strings

Local PC: Visual Studio.net

Tester Program

How to submit

TBA