Search

понедельник, 20 февраля 2012 г.

Console Resolved

YAAAYYY!! Console is fixed! What went wrong? I donno. Apparently, putty doesn't like cout when I use it in my display function, or something.
Before it was:

     std::cout<<tstr;
 I made it like this:
   console<<tstr;
Which is basically a "putchar" statement. I guess it has something to do with the internal putchar and cout differences, but might be wrong, as far as I know it works, and that's good!
I submitted 0.1, have about a week to make 0.2 are we're gonna split the functions between out group in a few days, so I might as well finish with the wiki and have a few hours of rest, on this last day of the long weekend!

Console

So, it's bern a while, since I bloged about something... (Note to self: Don't forget to upload thing on wiki)
Ok, new year, old (sort of) assignment. Everything should go fine... Not. The fist problem I encountered was right at the beginning.
The assignment starts with writing a "console.cpp", basically, a display and edit function for a string of text, noting major... And I did. And it worked... On Visual Studio. I'm not sure why, but in unix environment my function isn't showing the string and just doing all sots of illogical things with the string. Apparently it has something to do with memory handling in the unix.
So, teacher didn't answered my email about an appointment (I should talk with him about the   procedure of "successfully sending an email") I have my goldfish crackers, some water and a few hours of work!

I guess I should start with taking a regular console tester and checking if it works, next, I'm going to work on display function, until I at least will be able to see the sting... Yeah, that should do it.

воскресенье, 15 января 2012 г.

Happpy new OOP year!

   So... I failed C++ last semester. Why? Well, first of all I was a bit too lazy, and unlucky - all the staff I was preparing for some reason got completely useless on the exam and second test. So yeah, I barely made it through test one, failed test two, I guess I should've expected something like this on the exam.
This semester I'm planning to fix stuff I failed last time, let's see...
- Learn Templates
- Repeat Link lists
- Learn how they can work together
- Get a book (I'll probably work on it this week)
- Repeat files and binary
This should cower... most of the course, I will also try to make appointments with the teacher so I can insure that I know everything... Most of it.
   Ok, this looks right. I hope things will work out for me this time, I'm not sure about the team, but it will be alright. I guess I should go to sleep... Classes at 8 am is a fair "punishment" for my laziness.
Good luck for me and everyone who's reading!

суббота, 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.