Thursday, 20 August 2015

Concept Of Object Oriented Programming Class And Object[Part 1].

The Object Oriented Programming is a programming model, where we use Class and Object to write the program. Unlike the sequential programming model the variable and methods are contained in Classes and we use Object to use the variable and methods contained by a particular class.
   Apart from this OOPS provides many new features, Such as:

1. Inheritance
2. Polymorphism.
3. Encapsulation.
Etc.

Concept Of Class: If we think about Data used in programming we will find there are basically 3 types of data.
1. Primitive Data Type.
2. Derived Data Type.
3. User Defined Data Type.

Primitive Data Type: Primitive Data Types are the data type defined in programming language. For Example: int, char, float.

Derived Data Type: Derived Data Types are the data types derived from primitive data type. For Example: Array.

User Defined Data Type: The User Defined Data Types are such data type where user/programmer defines the data type according to requirement of the program and it will contain one or more primitive or derived data type.
For Example: If we want to represent a student in a program, the student data may contain various attributes. such as Roll No (int), Name(String/Array[Char]), Address(String/Array[Char]) Etc.
So the Student data will be combination of different Primitive and/or Derived Data Type.
This type of data type is called User Defined Data Type.

Example:
Struct, Class are user defined data type.

"So Classes in Object Oriented Programming is an User Defined Data Type defined by programmer or User according to  the program requirement, and Objects are the variable of this data type to use the features of the class."

Tuesday, 22 July 2014

How To Find Largest Among Few Number Without Using Array..

This Program Will Find Out The Largest Among Few user Given Number. The Numbers Entered By The User Must Be Positive.

#include<stdio.h>
#include<conio.h>
main()
      {
       int a,b,i,n;
       b=0;
       printf("\n\tEnter How Many Number You Want To Enter:==");
       scanf("%d",&n);
       for(i=0;i<n;i++)
                       {
                        input:
                              {
                               printf("\n\tEnter No[%d]:==",i+1);
                               scanf("%d",&a);           
                              }        
                        if(a<0)
                               {
                                printf("\n\tThe Input Was Wrong Number Must Be 0 Or Positive");
                                goto input;        
                               }
                        else
                            {
                             if(a>=b)
                                     {
                                      b=a;              
                                     }   
                            }
                       }
       printf("\n\tThe Largest Number You Have Entered:==%d",b);
       getch();
      }

How To Find Largest Number Among Two Number Without Using If-Else Construct Or Trinary Operator..

This Program Will Find The Largest Among Two Number Without Using If-Else Construct Or Trinary Operator ....


#include<stdio.h>
#include<conio.h>
main()
      {
       int a,b;
       float c;
       printf("\n\tEnter 1st Value:==");
       scanf("%d",&a);
       printf("\n\tEnter 2nd Value:==");
       scanf("%d",&b);
       c=(float)((a+b)/2)+(float)((a-b)/2);
       printf("\n\tThe Largest among %d and %d is %d..",a,b,c);
       getch();
      }

How To Interchange Two Variable Without Using Third Temporaty Variable

This Program Will Interchange The Value Of Two Variables Without Using The Third Temporary Variable..


#include<stdio.h>
#include<conio.h>
main()
      {
       int a,b;
       printf("\n\tEnter 1st Value:==");
       scanf("%d",&a);
       printf("\n\tEnter 2nd Value:==");
       scanf("%d",&b);
       printf("\n\t Before Interchange a=%d\tb=%d",a,b);

       a=a+b;
      b=a-b;
      a=a-b;

      printf("\n\t After Interchange a=%d\tb=%d",a,b);
      getch();
      }

How To Find Sum Of Two Numbers Without Any operator

This Program will add two numbers without using any binary arithmetic operator in c programming language..

#include<stdio.h>
#include<conio.h>
main()
      {
       int a,b;
       printf("\n\tEnter 1st Value:==");
       scanf("%d",&a);
       printf("\n\tEnter 2nd Value:==");
       scanf("%d",&b);
       if(b>=0)
               {
                while(b>0)
                          {
                          a++;
                          b--;
                          }
                }
       else
           {
             while(b<0)
                          {
                          a--;
                          b++;
                          }  
           }
       printf("\n\tThe Addition :==%d",a);
       getch();
      }

Monday, 21 July 2014

Write A Program That Use Multiple Processor In C#

using System;
using System.Collections.Generic;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
namespace time
{
    class Program
    {
        long sum = 0;
        void showTime()
        {
          Thread.Sleep(1000);
        }
        static void Main(string[] args)
        {

            var program = new Program();
           var startTime = DateTime.Now;
           for(int i=0;i<10;i++)
                  {
                    program.showTime();
                  }
            Parallel.For(0, 10, i =>
                {
                    program.sum += i;
                    program.showTime();
                }
                );         
            Console.Write("\n\tTotal Seconda Taken: "+DateTime.Now.Subtract(startTime).TotalSeconds);
            Console.ReadLine();
        }
    }
}

If  We execute this program using the normal for loop only then the program will take at least 10 secs. But by using Parallel.For() we can access multiple processor cores of our computer and in this program multiple processor is getting accessed by the program..

How To Print Something In C Without Semicolon

#include<stdio.h>
#include<conio.h>
main()
      {
        if(printf("\n\tHello Programmer"))
        getch();
      }