OOP344 Assignment Two
OOP344 - OOP344 Student List - OOP344 Teams - OOP344 Assignment One - OOP344 Assignment Two
Under construction...
Contents
File Names
Save your work in separate files for each class. Name the files to the same name as the classes. Each class should have a header file and a code file.
For example for the class IOField, create iofield.h and iofield.cpp. The header file should hold the class declaration and any other possible declaration related to the class. the "cpp" file should hold the definition (implementation) of the class and its methods and possible functions.
Create a Make file to build your project with respect to dependencies of classes.
How to reuse your C code in C++ programs
Include your already existing C code into your C++ code as follows:
extern "C"{ #include "ciol.h" };
This tells to C++ compiler, the included header file contains C functions and should be complied and called as such. Remember, you do not need and should not rename your ciol.c to ciol.cpp, since the compiler is already aware of the C functions in ciol.c.
Team Project Wiki Pages
Add a link to your Team project Wiki pages here:
General Definition Header file
create a file called: io_def.h. This file will any nessecary definitions or inclusions for the project. ultimately, users (future programmers) will only include this header file to be able to use the IO Classes. for now add the following define statements in io_def.h
#define IO_NO_ACTION (0x1) #define IO_CLEAR (0x2) #define IO_SHOW_ALL (0x4) #define IO_SHOW_ERROR (0x8) #define IO_SHOW_HELP (0x16) #define _FRAME_CHARS "|+-+|+-+"
Mandatory Classes
As the first part of your project this semester, you are to create few classes to encapsulate Console Input Output Library
IO_Field
IO_Field is the base class for all different types of Fields on a Form.
class IO_Form; // forward declaration class IO_Field{ protected: void* _data; int _row; int _col; public: IO_Field(int row, int col); void* Data(); virtual void Display() = 0; virtual int Edit(IO_Form* Owner=NULL)= 0; virtual bool Editable() = 0; virtual void Set(const void *) = 0; virtual ~IO_Field(); };
IO_Field(int row, int col);
This constructor set the corresponding attributes to the values of incoming arguments and sets the data attribute to NULL.
void* Data();
Returns the value of the data attribute.
virtual ~IOField();
An empty destructor (the body of the method is blank)
virtual void Display() = 0;
virtual int Edit(Screen *Owner=NULL)= 0;
virtual bool Editable() = 0;
virtual void Set(const void *) = 0;
These are pure virtual methods enforcing the creation of the identical methods in the derived classes. This make the IO_Field class an abstract class.
Note: The purpose of passing a IO_Form pointer to the Edit method, is to make the future Edit methods capable of sending a message (errors and help messages)to the Screen they are being Edited on.
IO_Frame
IO_Frame class, encapsulates a frame. It Draws a frame at left top cornder of col and row with specified width and height.
A Frame can be instatiated as follows:
IO_Frame(int row, int col, int width, int height, const char* frameChars = (const char*)0);
the frameChars are characters used to draw the frame, charachters in order are:
- left side
- left top corner
- top side
- top right corner
- right side
- right buttom corner
- buttom side
- buttom left conrner
So to draw this:
/--------\ | | | | | | \--------/
frame chars should be:
"|/-\|/-\"
If however, the frameChars argument is missing (it is NULL) then a defaut, defined value in "io_def.h"; _FRAMW_CHARS should be used.
void Display(void);
Display(), displays the frame with the specified coordinates and size in its constructor
IO_Form
IO_Label
IO_Label class mostly, encapsulates the io_display() function. Inherit a new class called IO_Label from IO_Field to Display a text message on IO_Form. In addition to the attributes of its parent IO_Field, IO_Label has a private integer attribute called _len. _len is used to hold the length of Field in which the text is to be displayed. IO_Label could hold its data dynamically or simply point to an external one. Because of this IO_Label also has a boolean attribute called _dynamic that will hold the type of data within; being dynamic memory (value true), or external memory (value false) IO_Label can be created in two ways;
IO_Label(int row, int col, int len);
This constructor will create an empty (blank) IO_Label with capacity of len characters. In this case row and col are passed to the parent for initialisation and _len (the atterbute) is set to the incoming argument len.
Then IO_Field::_data will be set to the address of a newly allocated memory to the size of _len + 1 bytes which also will be set to an empty string.
Note that data is a void pointer; to use it here, you must cast it to a character pointer!
_dynamic attribute is set to true in this case.
IO_Label(char* str, int row, int col, int len = -1);
This constructor will create an IO_Label, with its IO_Field::_data pointing to where str is pointing to.
Like the previous constructor it will pass row and col to its parent and set the _len attribute to the incoming len argument. _dynamic attribute is set to false in this case, since the data of the class is external.
Public Methods
void Display(void);
Display() is a direct call to io_display() function printing _data, at _row and _col up to _len characters. If _len is less than zero, then _data will be printed to the end.
void Set(const void* str);
Set() will copy the content of str into IO_Field::_data up to _len characters, if _len is not negative.
bool IO_Label::Editable(void)const;
Editalbe() returns false!.
int Edit(IO_Form* Owner=(IO_Form*)0);
Edit(), Calls Display() and returns 0. This method ignores the Owner, IO_Form pointer.
~IO_Label(void);
The destructor, delete[]s the _data only if _dynamic is true.
IO_Label &operator=(const char* str);
operator=(), Calls Set() and returns itself.