Menu BAR

FEEL FREE TO ASK ANY PROGRAM and please mention any error if you find it

5 Aug 2014

C++ CLASS EXAMPLE

Program to create a simple class in C++

#include<iostream.h>
class simple
{
  private:
  void you()
  {
    cout<<"Hi, i am private, you cannot access in main.";
   }
  public:
  void hello()
  {
     cout<<"Welcome to hello function.\n";
   }
   void world()
  {
    cout<<"You are now in world function.";
   }
};
void main()
{
  simple obj;  //creating object of class simple
  cout<<"Welcome to main function.\n";
  obj.hello();  //accessing the function hello using the object obj of class simple
  obj.world();
  //object.you();  //this will give error because the function is private
  getch();
}

==OUTPUT==
Welcome to main function.
Welcome to hello function.
You are now in world function.

30 Jul 2014

CALL BY VALUE PROGRAM IN C

Program of Call by value for swapping two values

#include<stdio.h>
void swap(int a, int b)
{
  int temp;
  temp=a;
  a=b;
  b=temp;
 }
void main()
{
   int a=5;
   int b=10;
   /*printf("c-programcodes.blogspot.in");*/
   swap(a,b);  /*the values goes out of scope  after the function is executed*/
   printf("values are not swapped");
   printf("a=%d\n",a);
   printf("b=%d",b)
}
==OUTPUT==

values are not swapped
a=5
b=10

7 Jul 2014

Java Program #2

Q) Write a Program to print STAR Pattern.
   *
   **
   ***
   ****
   *****

Sol)

class Stars {
  public static void main(String[] args) {
    int row, numberOfStars;

    for (row = 1; row <= 5; row++) {
      for(numberOfStars = 1; numberOfStars <= row; numberOfStars++) {
        System.out.print("*");
      }
      System.out.println(); // Go to next line
    }
  }
}

Java Program #1

Q) Write a Program to print " Hello World ".


Sol)

   public class HelloWorld {

    public static void main(String[] args) {
        
        System.out.println("Hello World");
        
    }

30 Jan 2014

LOWER TRIANGULAR MATRIX

Write a program to print lower triangular matrix in c++

#include<iostream.h>
#include<conio.h>
void main()
{   clrscr();
 int a[10][10],b[10][10],c[10][10];
 int i, j, n, m;
 int p,q;
 cout<<"enter no of rows of matrix\n";
 cin>>m;
 cout<<"enter no of colomns of matrix\n";
 cin>>n;
 cout<<"\n\nenter the elements of matrix\n";
  for(i=0;i<m;i++)
   {
    for(j=0;j<n;j++)
     {
      cout<<"a["<<i+1<<"]["<<j+1<<"]:= ";
      cin>>a[i][j];
     }
   }
  cout<<"\n\nmatrix u have entered is"<<endl;
  for(i=0;i<m;i++)
   {
    for(j=0;j<n;j++)
     {
      cout<<"\t"<<a[i][j];
     }
    cout<<endl;
   }
 cout<<"Lower tringular matrix is"<<endl;
  for(i=0;i<m;i++)
  {
   for(j=0;j<n;j++)
    {
     if(j<=i)
     {
      cout<<"\t"<<a[i][j];
     }
     else
     {
      cout<<"\t ";
     }
    }
    cout<<endl;
  }


getch();
}