Friday, 28 June 2013

Constructor in JAVA

Definition:
Constructor is a Method of the class that has the same name as the class name in which it is.
We don't need to call the constructor instead whenever we make the object of the Class Constructor of
this class is automatically called.
In JAVA we use constructor as we use in C++ ( in Object Oriented Programming) . Following
example will demonstrate that how can we use Constructor.

Example Program:

 

public class Test {

       Test()                                             // Constructor
       {
           System.out.println("Faraz");
           System.out.println("Awan");
       }
    public static void main(String[] args) {

                new Test();
    }
}


Allocating Memory Dynamically in C++

To allocate the memory  dynamically we use the keyword "malloc".

Dynamical Memory Allocation Example:
 For example if you want to take array size from user, we allocate memory dynamically. If we adopt following way it will generate error!!
int mem;
cout<<"Enter Array Size:";
cin>>mem;
int ar[mem];        // Constant Expression Require (Error)

Solution:

To resolve this issue we use "malloc" key word.
Following Program will help you to understand this.

#include<iostream.h>
#include<stdio.h>
#include<alloc.h>

void main(void)
{
  clrscr();

       int mem,*p;
      cout<<"Enter Array Size:";
      cin>>mem;
p=(int *) malloc (sizeof (int));

  for(int i=0;i<mem;i++)
   {
     
      cout<<"Enter Data:";
      cin>>p[i];
   }
getch();
}

Wednesday, 26 June 2013

Square Diagram (For Loop) in C++:

#include<iostream.h>
#include<conio.h>
#include<stdio.h>
#include<string.h>
void main()
{
clrscr();

   for(int i=1;i<=10;i++)
   {
     for(int k=1;k<=10;k++)
     {
 if(i==1||i==10)
 {
  cout<<"*";
 }
 else if(k==1||k==10)
 {
  cout<<"*";
 }
 else
 {
   cout<<" ";
 }
     }
     cout<<endl;
   }
getch();
}

Output:
**********
*          *
*          *
*          *
*          *
*          *
*          *
*          *
*          *
**********

Stair Design (For Loop) in C++:

#include<iostream.h>
#include<conio.h>
#include<stdio.h>
#include<string.h>
void main()
{
clrscr();
int sp1=10,sp2=0;
   for(int i=1;i<=10;i++)
   {
     for(int spac=1;spac<=sp1;spac++)
     {
       cout<<" ";
     }
      for(int k=1;k<=2;k++)
      {
cout<<"*";
for(int l=0;l<sp2;l++)
{
cout<<" ";
}
      }
      sp2++;
      sp1--;
      cout<<endl;
   }
getch();
}

Output:
          **
         * *
        *  *
       *   *
      *    *
     *     *
    *      *
   *       *
  *        *
*          *

Friday, 21 June 2013

GPA Calculator

You can Download GPA Calculator from Following Link.
Note: After installation , package will automatically start installing .NET Framework . If you already have installed .NET Framework quit that installation.
Download link:
GPA Calculator Download Link

About GPA Calculator:
Developed by: Faraz Awan
This Calculator is Valid for the students of COMSATS University of Science & Technology or for those who's Universities has Following Grades' Distribution.

        Marks                           Grades(GPA)
        >=90                                   4
       >= 85 &&<=89                   3.7
       >= 80 &&<=84                   3.3
       >= 75 &&<=79                    3
       >=70 &&<=74                    2.7
       >= 65 &&<=69                   2.3
       >= 60 &&<=64                    2
       >= 55 &&<=59                   1.7
       >= 50 &&<=54                   1.3

About blog:

This Blog is about Software solutions, Assignments e.t.c.
Tutorials of Programming Languages , e.g C, C++, Java, C# , will also available.
If you have any issue or problem regarding any Programming language you can contact via this blog to get help.