Thursday, June 26, 2008

I invented XML

Just curious what if xml wasn't invented till today? I have used the same technique to store data. When I was learning PHP files i wanted to sav data I kinda made a forum using files (but it was so messed up. I dont want to look at it). And to separate data i used TAGS the same technique XML uses so :(

Tuesday, November 20, 2007

planing and implementing logic

The most essential and basic thing before learning any programming language is the way the solutions are solved in programming. Unlike other courses you red or you may read in the university you will find cp more close to real world problem solving, method comes into your mind and you divide it as you are instructing the computer line by line.


a statement as below
c++ style..............................

a=a+b;

.................................

is an instruction to the computer, to first take the value from a and then take the value from b add them and save the result again in a.

When programming you have to feel like you are instructing the computer.

Now below is a very simple and basic guide on howto solve a problem. Any ways you have been doing the same thing in ITC during your first semster.

  1. The first part is to understand the problem. You really have to get the idea behind the problem. I suggest you read it five times with fully focused mind and you will get it.
  2. Now the second part is to divide your problem into small parts so that when you solve them and put them together you get the required result (i.e solution).
  3. Third part is implementing you have to compile all you have done so far into programming language (like c++ syntax). I suggest you consider this step with the second one.

I suggest you implement the problem in second part when you divide problem into problems. Take first problem solve it on a paper then code it on c++ editor. Take a look at the following example.

  • Write a program that inputs a string of keyboard characters and outputs the characters in reverse order.
  1. PROBLEM UNDERSTANDING
    First what we are going to do is understand the problem. First I need to have a string and then i have to invert it or reverse it like if user inputs "ALI" I have to print (infact i will not the program will :) ) "ILA". It is a very simple and easy problem.
  2. DIVIDING
    There are two possible divisions of the problem. 1st part is taking a string (that will be an input) and second part is reversing it.
  3. IMPLEMENTING
    Now impelmenting the first part . The following code does it all

    c++ style........................................................................
    #include
    #include
    using namespace std;
    // this all is necessary so you cant divide it :) //
    void main()
    {

    string str;

    cin.getline(str, 50);

    ......................................................................................

    It was really very simple as you can see. I included the files as I ever have to so dont ever think about dividing that part. What i did was declared a string not yet intialized it after that I used a method for string "cin.getline(str, 50); " cin.getline takes a string and saves it in the first argument you pass (in this case it was 'str') and the second argument should be number of characters in the string. The output of the code till here is a cursor will blink and will take input of not more than 50 characters.
    Now we come to the second part of the problem that is reversing the string.

    c++ style........above example cont.....................

    for(int i=str.length; i(grter-thn)=0; i--)
    {
    cout str[i];
    }
    }

    .............................................................................


If you still don't get anything write in the comment or any better way of solving a problem please discuss in the comment section. :)

Thursday, November 15, 2007

Arrays

Understanding arrays isnt difficult if you are fimiliar with variables and their manipulation.

Take a look at the following points carefully

  • Variable is a short term memory space that can be changed manipulated during the program run-time and after the program ends.. it is lost.

c++ style ..........................................

int a,b ; // variable with the name 'a' and 'b' is set in memory (temprary) .


..................... .....................

Now that you have told the compiler to reserver momery (4 bits in integer case) for these variables you can manipulate them where ever you want in the program. Use them overwrite them do wateva you want. Please never hesitate to do whatever u think with variables computer will never crash. Our university's student have fear of something i dont know of what. But they really hesitate to write the code. I will definetly write another post about planning and implenting a program.

  • Array is a group of variables with the same name (not exactly). You have to actually understand where you need a group of variables with same name so that you can manipulate (use) them, easily and use all of them at once.

    Now suppose you need ten different variables of same datatype. A programmer who doesn't know about arrays is off course gonna do the following
    int var1, var2, var3, var4, ... till ... var10;
    Now if you observe the above you can still see the index i.e var "1" and "2" and goes till "10". Arrays are handled by the compiler the same way. Compiler makes a stack of variables but you have to tell the compiler the size of variable stack.
  • Note: Size is different thing and index (unique ID of the variable in the stack) is different thing.

c++ style ....................................................

int ar[10]; //This is the size of the array i. e how many variables the stack will contain

................................................

c++ style ....................................................

ar[0]=1;
ar[1]=4;
ar[2]=5;
.
.
.

//'[0]' this is the index (unique id here is '0') infact ar[0] is a varaible that has nothing to do with ar[1] or rest of the ar[]S.

.............................................

Last but not the least donnot forget that array is a group of variables.