Monday, 26 November 2012

Another example of Hanoi Towers.

Find another example of Hanoi Towers on C++

================================
/**************************************************************************
  -> This C++ program is to solve the towers of hanoi problem.
  -> Implemented using recursion.
  -> Works in Microsoft VC++ 6.0 , windows xp.
  -> Header files used 1)iostream.h
***************************************************************************/
#include<iostream.h>
void move(int n,char *s,char *i,char *d)
// s stands for source tower
// d stands for destination tower
// i stands for intermediate tower
{
 if(n>0)
 {
  move(n-1,s,d,i);
  // move n-1 disks from source to intermediate tower
  cout<<”disk “<<n<<” is moved from “<<s<<” to “<<d<<endl;
  // move the disk from to source to destination
  move(n-1,i,s,d);
  // move n-1 disks from intermediate to destination
 }
}
void main()
{
 cout<<”\n**********************************************************\n”;
 cout<<”This C++ program is to solve the towers of hanoi problem”;
 cout<<”\n**********************************************************\n”;
 cout<<”Enter the no. of disks “;
 int n;
 cin>>n;
 move(n,”source tower”,”intermediate tower”,”destination tower”);
}
==============================================

sourse blog - http://ds4beginners.wordpress.com/2006/12/21/towers-of-hanoi/

Sunday, 30 September 2012

Dynamic allocation (example for myself)

// dynamic allocation and polymorphism
#include <iostream>
using namespace std;

class CPolygon {
  protected:
    int width, height;
  public:
    void set_values (int a, int b)
      { width=a; height=b; }
    virtual int area (void) =0;
    void printarea (void)
      { cout << this->area() << endl; }
  };

class CRectangle: public CPolygon {
  public:
    int area (void)
      { return (width * height); }
  };

class CTriangle: public CPolygon {
  public:
    int area (void)
      { return (width * height / 2); }
  };

int main () {
  CPolygon * ppoly1 = new CRectangle;
  CPolygon * ppoly2 = new CTriangle;
  ppoly1->set_values (4,5);
  ppoly2->set_values (4,5);
  ppoly1->printarea();
  ppoly2->printarea();
  delete ppoly1;
  delete ppoly2;
  return 0;
}
=======================================================
 
Example from website: http://www.cplusplus.com 

Friday, 14 September 2012

Git book languages.

I was surpriced that Pro-git Book has translations into different languages. Well it helps a lot for a students whose first language is not English.
Here is link for Russian Pro-Git Book. http://git-scm.com/book/ru
P.S.
You will find other languages in the left side, just click on link and you will get GitBook in language you need.


Sunday, 9 September 2012

OOP344 again...

Yep, I failed OOP344 last semester. More attention this time.

Wednesday, 14 March 2012

My functions...

For the first part of our team assignment I did this three functions...


 1.

void CDialog::draw(int fn = C_FULL_FRAME){
    if(fn == C_FULL_FRAME){                //If fn is C_FULL_FRAME
        CFrame::draw();                    //it will call its parent draw. Then It will draw all the Fields in the Dialog.
    }                                      // it will call its parent draw. Then It will draw all the Fields in the Dialog.
    if(fn != C_FULL_FRAME){                // If fn is not C_FULL_FRAME
        for (int i = 0; i < _fnum; i++){
        _fld[i]->draw;                     // then it will just draw all the Fields in the Dialog.
        }
    }
    if(fn > 0){                            // If fn is a non-zero positive value
        _fld[(fn-1)%_fnum]->draw();   // then it will only draw Field number fn in the dialog.
    }
}


2.


  CLabel::CLabel(const CLabel& L):CField(L){
      if(this!=&L){
            width(L.width());
            if(L._data){
                _data = new char[strlen((char*)L._data+1)];
                strcpy(_data,L._data);
            }
            else{
                _data = (char*)0;
            }
        }
  }


3.


void CLabel::set(const void* str){
      if(width() > 0){        //if width() is greater than zero
        strncpy((char*)_data, (char*)str, width());
        ((char*)_data)[width()] = 0;
      }
      if(width() == 0){
        delete [] _data;
        _data = new char[len+1];
        strcpy((char*)_data, (char*)str);
      }
 }



==========


Probably they have several few mistakes which were changed in final team project.

fail..

Well, I forgot about this blog... So let's start it over..

Sunday, 15 January 2012

First Post

First Post
TEST test TeSt

====================
Some programming staff would be here later...