Search

суббота, 17 декабря 2011 г.

Files C++

Ok, before the exam, I started repeating files, and now I want to post some of mine notes.

Basic steps to use files:
1. Declare an ofstream/ ifstream/ftream var.
2. Open a file with it.
3. Do stuff to the file (there are couple of ways.)
4. Close it.

ifstream              - open the file for input (reading)
ofstream             - open the file for output (writing)
fstream               - open the file for input/output/both


file. open ("test.txt", ios::in | ios::out | ios::app)
I got a bit confused here, why do I need open AND constructor? Wouldn't it be a lot easier to have just open, or just a constructor... Any way, I'll research it a bit later

flag value           means
ios::in                   open file for reading
ios::out                 open file for writing
ios::app                open for writing,add to end of file(append).
ios::binary             binary file
ios::nocreate         do not create the file,open only if it exists
ios::noreplace       open and create a new file if the specified file does not exist
ios::trunc              open a file and empty it.(Boom, all the data is gone,if any)
ios::ate                 goes to end of file instead of the beginning

Returns current position, if in the end, return length of file:
file.tellg ( );                       
 
Move courser:
seekg/seekp (pos, ios)               
pos – number of bites to move
ios – move from, beg, end, cur

value      means...
ios::beg    beginning of the stream buffer
ios::cur     current position in the stream buffer
ios::end    end of the stream buffer


file.read (buffer,size);
buffer – where to put text
size – how much, counting from seekg

size = sizeof("LOOOOL");
file.write ("LOOOOL",size);
This puts text inside a "file" document.I still need some time to figure out the way it adds, it should be based on seekp position, but I'll figure it out, I just need to make a few examples, I'm planning on making some kind of "holiday calendar" using a text file tomorrow.

eof()                     returns true if the end of the file has been reached

Other functions for reading:
1.seekg();           //move the read pointer in bytes
2.tellg();              //returns where the read pointer is in bytes

Other functions for writing:
1.seekp();           //move the write pointer in bytes
2.tellp();              //returns where the write pointer is in bytes

вторник, 18 октября 2011 г.

CLabel

Ok, it's been a while! Let's program something again! So, what do we have today? A kind of Idea of what is supposed to be in the end AND that I'm going write something for it... And eventually it will work... Or not... I hope it will.
But what I need to do today is write a bunch of small functions, constructors, and I just finished the destructor. It's funny and interesting how thing work - lot's of people come together and each and every one of them write a specific function, and possibly some of them don't even know what the purpose of their part is, but in the end, if everything is one by the plan - Program Works! It's like a small, micro, model of society... But, I got off the track a bit. What I'm planning to do today:
1. Write/Double-check the most basic functions (1-2 lines)
2. Update my knowledge on difference between "." and "->"
3. Walk though rest of the functions and see if I have any questions and, possibly, write them down, or remember.
So, let's start...


I just Love OOP - "editable() - always return false"
bool CLabel::editable()const {
return false;
The PERFECT function. I guess it's gonna be used in the future but seriously, why not just "return false;". And the best part is - there WILL be a place to use this function.

Ok, so, questions we have for today are:

Description: "CLabel(const char *Str, int Row, int Col, int Len = 0) - passes the Row and Col to the CField constructor and then.... etc"
Line: CField a (trow, tcol);
Problem: I got an Error "object of abstract class type "CFrame" is not allowed", so, how can I pass values to the constructor if it's object's creation is not allowed?


Description: "draw(int fn) - makes a direct call to console.display(), passing _data for the string to be printed and... etc"
Line: temp.display(_data, CFrame::absRow(), CFrame::absCol(), _length);
Problem: Don't know how to target an information where _data points, also, "a direct call" has a bit of a problem, since I can't use Console::draw, and I'm pretty sure, that Creating a temp class for the small task is a bit... Stupid wrong.


Description: "edit() - calls draw"
Line: draw();
Problem: Not sure if I should use "this->draw()", or just "draw()", I guess once tester is out I can check, but the problem still exists.



And that's it so far.

воскресенье, 25 сентября 2011 г.

Edit Function 3 - Finale

*14:00*
I will try to finish it today. I need to make and test those changes:
- Offset setting. 90% (Double check and testing)
- Cursor setting 90%  (Double check and testing)
- Cursor moving 90% (Double check and testing)
- Too many characters 40% (Writing and testing)
This shouldn't take too much time, but I'm pretty sure I'll miss something important and it won't be finished completely, but I tried at least. I also found that bag from backspace case I was talking about last time, so i need to fix it as well.

*15:00*
Everything so working.. except the INSERT part. I need to code it based to the conditions I have... That might take a while...

*16:40*
Aaaannnnddd.... Yes. I think it's done. I mean, I'm pretty sure, there are at least A Lot of thing I didn't test for, and somehow missed while reading the conditions for a few times, but it looks good, I didn't find any bugs and it at least meats Most of the conditions. So yeah... fingers crossed.

*16:47*
Nope! Wait. One last this.
- The user terminates editing cases. 0%
So, I'm going to Save everything into temp variables and then put everything back.

*17:15*
Ok, if the way I do it is the right way, I'm going die of laugh. On one hand it's logical - make separate cases for separate keys, but having same 4 lines in each and every case makes me giggle. I guess it will change in the future but I still have my doubts.
Any way... Fingers crossed... Again.

суббота, 24 сентября 2011 г.

Edit Function 2

*13:40*
Ok, so, where was I last time?
1. Fix DEL case. - 99%
2. Write BACKSPACE case.  - 80% (Needs testing + 1 or 2 small fixes)
3. Fix LEFT case. - 90% (Needs testing)
4. Write RIGHT case. - 99%
5. Write HOME and END cases. - 5%
6.
Work on INSERT mode. - 0%
Yep... Nothing major. Let's start.

*13:55*
Ok, one down, few to go.
BACKSPACE case. - 99%
Ok, so now... I had a problem with the display function... Or my Left function, but I think there is a problem with option "if fieldLen is less then a sting length". But this needs further investigation.

*14:00*
Boom! I'm Smoking today! Probably doing it in the least efficient way possible... But I don't know the other ways, OR not in position to rebuild it (Maybe after I'm done with the Edit function). So yeah... 
Fix LEFT case. - 99%
Ok, now the Home and End cases again... I think at least, even though I totally told the same last time.

*14:10*
Ok there is something wrong... I'll the other way - I'm gonna test every function one by one, removing all the others. The problem is that I'm not sure is the bugs I get are display problems, or Left Right problems... Also, as a last way out I will consider downloading the original code and staring from the beginning, even though I don't wont to do that at all.
 So, even though my print shows that Offset is 0, I stand on "F" and can't move further (what a brilliant metaphor...). I can only assume that this is a Display bug. I'll see what I can do with that...

*14:20*
A few tests later I decided that I will try to recode the display function. This will take some time, but if it will work, it might save me...

*15:00*
I rewrote the display function. And so far everything works fine I hope that it Stays that way. It looks like I'm back on the right track. It might be a mistake, somehow, but I did some progress:
DEL case. - 99%
BACKSPACE case.  - 99% 
LEFT case. - 99% (Needs testing)
RIGHT case. - 99%
HOME and END cases. - 99%
So now the tricky part - Writing case. I need to re-read the info again, and I think I have a good chance of finishing this part and the entire task today.  


*15:45*
YES! I'm Done! Everything Works! There is only one problem - ONCE, Somehow, I managed to bug out the BACKSPACE case (it went deleting all the way into the null), but I couldn't repeat this so I guess it will do. There is also a thing about the string itself- if you write something to re-write this "0" (teacher put it to cover second part of the string) the string shows fully, and I'm not sure if that's the way it's supposed to be.
But hey! I'm done! Yaaaayyyyy!!!

*15:50*
Oh... I forgot that there are additional conditions - offset, length something else... Ehh... And that's what I hate about this profession. But anyway, that might take some time, but I'll be done today.

*16:40*
Ehh... I just spend A Lot of time doing the most basic stuff...  I'll finish it tomorrow, or today at night, I just can't do anything for some time. So, so far, I'm done.

четверг, 22 сентября 2011 г.

Edit Function 1

Ok, so, the Edit function, I have enough information to complete it... Unless I get into some kind of small problem as I did in the display function.
Thing I need to do, possibly today:
1. Fix DEL case.
2. Write BACKSPACE case. 
3. Fix LEFT case.
4. Write RIGHT case.
5. Write HOME and END cases.
6. Work on INSERT mode.

*20:10*
Ok, I just finished fixing DEL case. That was easy - basically one line of code. It's not that hard, once you realize that you need to put a NULL in the right place. Then, the will appear a problem… Ok, not a problem, but a bag – if you push Delete continuously, eventually you will pass the cursor and keep deleting, even though I need it to Stop once it reaches the cursor. This bag was solved in about half an hour, I just needed to experiment a little.
Also, a Good line of code for testing, just put it in Left/Right cases:


display("Cursor"/"Set   ", 20, 0);       
//Displays the way you are moving (cursor or offset)
std::cout<<"                       "<<*curPosition<<"  "<<fieldLength; 
//Displays values you need for testing, can only be use with values that are passed to the Edit function and values in this function


I know there is a better debuggers out there, especially considering the fact that I use Visual Studio, but I’m not doing something too large or difficult to compile, so I’m using those lines, just because I feel more comfortable with them. 
Now I'll start working on a BACKSPACE case...  

*21:20*
Heh, documenting everything takes A Lot of Time.
 So, where was I? Oh yes, BACKSPACE. This is not that hard, the basic thing you need to understand while writing it – backspace is LEFT and DEL cases combined.

*21:40*
Well that was easy… Left and Right commands can be tricky, but it took me about half an hour to make them work the way they are supposed to. Now I just going to make the easiest (I think) ones – HOME and END. Let’s see what I can do.

*21:50*
That wasn’t that easy, but I also found out about a few more bags in the Left function. That might take some time, but that’s why I love this subject so much…

*22:22*
It took a while, but I got rid of one more bag – I tried to make it move a bit further if you hit left and if cursor  position is 0, and apparently without proper If statements it just went TOO far into space… I mean… String.
Ok, I need to wake up tomorrow around 8 am, I guess I’m done for today.

Solved Design

So, it took me a few hours, but I found out what the problem was. And obviously it wasn't compiler's fault.
Basically the error was:
 error LNK2019: unresolved external symbol "public: void __thiscall cio::Console::display(char const *,int,int,int)" (?display@Console@cio@@QAEXPBDHHH@Z)
And the code I wrote was:
void display (const char* str, int row, int col, int fieldLen) 
  After a few hours of looking at the screen I realized what a stupid mistake I made. The right line of the code was supposed to be:
  void Console::display (const char* str, int row, int col, int fieldLen) 
 Now this seems obvious but I spend A Lot of time on this bag, just looking in the wrong direction.
The rest wasn't that hard. I had tree situations:
1.  If fieldLen is 0 or less.
 Just one cout and everything works.

2.  If fieldLen more then sting length.
Make another string, and fill it with spaces and print after the str sting. (I'm also thinking about doing another version of it without creating another string of spaces)
3.  If fieldLen less then sting length.
Make another string, and copy str to it. And the Cut it with Null value, and print it.
I might also take some time and think about other ways  of writing it.

суббота, 17 сентября 2011 г.

Assignment Start

 *14:10*
Ok, so it's Sunday, weather is no the best I've seen, but I don't care since it pretty warm inside and I can start working in the first assignment in this Semester. Coke - here, snacks - here, music - playing. Goals for today:
- Download Console Files
- Double check the requirements
- Write the Display Function
- Check the Display Function
- Submit
- Do the other homeworks/labs so I can rest tomorrow
So, let's start...

*14:55*
Ok, so... I have some problems with the Console code, for some reason it won't create the Console object. I guess it's the problem of the Matrix, so I should download Visual Studio and try there.  The problem is - I've never used Visual Studio... This might take a while...
Or I could also Google and figure out how compile with cmd on Windows... That also might take a while...

*17:00*
Ok, the good new are - I actually got a working Visual Studio... The Problem is... The Error I have still isn't fixed... I need to think about it...

*17:10*
Ok, so I spend around... 3 hours doing almost nothing, there are still no Updates on the Wiki web-site, and the SVN version of the console file tells "Still Incomplete"... I guess I'll give it a rest, write a letter to the professor (I HOPE it will get thought). So yeah. Now I'm gonna check other Blogs and  sites for info, and probably will do other subject's home work... Too bad...

четверг, 8 сентября 2011 г.

First Post

  So, this is my first... "post", I guess. I'm not sure what I'm going to do here, I've never used blogs before but it's not that hard to figure out. Sooo... Yeah. I little test.
My name is Dzmitry Kavalchyk, I am from Belarus,  and I'm a student of Seneca Collage in Toronto. I study Computer Programming, this a very interesting and challenging course. If you're reading this, that means that you are my teacher... or one of my classmates... or you're far in the future where I'm a very famous and rich person and people want to find out how it all started. (I had to re-write this part Twice - "Undo" function doesn't work well, but nothing major)
Any way, welcome, and thank you for spending your time on reading this.
Also, random code: 
#include "main.h"
#include "getPosInt.h"


int main() {
int i;

i = getPosInt(MAX);
cout << "You entered " << i << endl;

I think that went well...