MENU











Sunday, 27 October 2013

Week 6 Programs

Week 6

6c) Write a C++ program that writes out the Fibonacci series. Find the largest Fibonacci number that fits in an int.

Aim::To display fibonacci series and to print the largest fibonacci number that fits in an int

Program::

#include< iostream>
using namespace std;
int main()
{
       int i=0,n;
       int fib[100]={0};
       int temp[40],t=-1;
       cout<<"Enter the range to print the fibonacci serries \n";
       cin>>n;
       for(i=0;i<100;i++)
       {
           if(i<2)
          fib[i]=i;
           else
          fib[i]=fib[i-1]+fib[i-2];
          if(fib[i]<0)
            {
            t++;
            temp[t]=i-1;    
            }
       }
       cout<<"The fibonacci series is \n";
       for(i=0;i< n;i++)
       {
            cout<< fib[i]<<"\t";
       }
cout<<"The largest fibonacci number that fits in an intis f[ " << temp[0]<<"]="<< fib[temp[0]];
   
}

Output::

Enter the range to print the fibonacci serries 
10
The fibonacci series is 
0	1	1	2	3	5	8	13	21	34 
The largest fibonacci number that fits in an int is f[46]=1836311903

Ds week3 Programs

Exercise 3

b) Consider a payment counter at which the customer pays for the items purchased. Every time a customer finished paying for their items, he/she leaves the queue from the front. Every time another customer enters the line to wait, they join the end of the line. Implement the application for this problem.

Aim::/*To implement queue at payment counter*/

Program::

#include< stdio.h> //Standard i/p,o/p header file
voidfill();     //prototype of function enque
void delete();   
void display();  
int queue[20],remv[20],temp[20];   //Declaration of array
int  f=-1,r=-1;     //f-front,r-rear intialisation
int int h,i,n,t,j;       //h-for switch case,n-for size of queue
int  main()      //main function 
{
 printf("Enter the size of queue : ");
 scanf("%d",&n);
 while(h!=4)
 {
  printf(" 1-for insert\n 2-for delete \n 3-for display \n 4-for exit \n Enter ur choice: ");
  scanf("%d",&h);
  switch(h)
  {
   case 1:fill(); //calling function
   break;
   case 2:delete();
   break;
   case 3:display();
   break;
   case 4:
   break;
   default:printf("Invalid entry \n");
  }
 }
}
void fill()
{
      j=0;
      if(r==n-1)
      {
            printf("Queue is full \n");
            display();
            printf("wait for sometime to send another person \n");
      }
 else
 {
            r++;
            if(f< 0||queue[r-1]< n)
            queue[r]=queue[r-1]+1;
            else if(queue[r-1]>=n ||queue[r-2]>=n)
            {
                 queue[r]=remv[j];
                 j++; 
                 f--;
            }
            printf("Filled position is %d \n",queue[r]);
 }
}
void  delete()
{
            if(r==-1)
            printf("Queue is empty deletion not possible\n");
            else
            {
                 f++;
                 remv[f]=queue[0];
                 printf("The removed position is %d \n",remv[f]);
                // printf("%d \t %d",f,remv[f]);
                 t=r;
            } 
            for(i=0;i<=t;i++)
            {
                  queue[i]=queue[i+1];
            }
              r--;
}
void  display()
{ 
 
            printf("\n The filled positions  in the queue are \n");
            if(r==-1)
            printf(" Null \n");
            else
            {
                   t=r;
                   for(i=0;i<=t;i++)
                   printf("%d \t",queue[i]);
                   printf("\n");
            }
             printf("\n Th1e vacant positions  in the queue are \n");
             if(r==n-1)
             printf(" Null \n");
  
             else
             {
                   temp[0]=queue[r];
                   i=-1;
                   for(j=1;j< n-r;j++)
                   {
                          temp[j]=temp[j-1]+1;
                          if(temp[j]>n)
                          {
                             i++;
                             printf("%d \t",remv[i]);
                          }
                          if(temp[j-1]<=n-1)   
                          {
                             printf("%d\t ",temp[j]=temp[j-1]+1);
    
                          }
                  }
             }
 printf("\n");  
}

output::

Enter the size of queue : 7
 1-for insert
 2-for delete 
 3-for display 
 4-for exit 
 Enter ur choice: 1
Filled position is 1 
 1-for insert
 2-for delete 
 3-for display 
 4-for exit 
 Enter ur choice: 1
Filled position is 2 
 1-for insert
 2-for delete 
 3-for display 
 4-for exit 
 Enter ur choice: 1
Filled position is 3 
 1-for insert
 2-for delete 
 3-for display 
 4-for exit 
 Enter ur choice: 1
Filled position is 4 
 1-for insert
 2-for delete 
 3-for display 
 4-for exit 
 Enter ur choice: 3

 The filled positions  in the queue are 
1 	2 	3 	4 	

 Th1e vacant positions  in the queue are 
5	 6	 7	 
 1-for insert
 2-for delete 
 3-for display 
 4-for exit 
 Enter ur choice: 2
The removed position is 1 
1-for insert
 2-for delete 
 3-for display 
 4-for exit 
 Enter ur choice: 2
The removed position is 2 
1-for insert
 2-for delete 
 3-for display 
 4-for exit 
 Enter ur choice: 2
The removed position is 3 
1-for insert
 2-for delete 
 3-for display 
 4-for exit 
 Enter ur choice: 2
The removed position is 4 
1-for insert
 2-for delete 
 3-for display 
 4-for exit 
 Enter ur choice: 3

 The filled positions  in the queue are 
 Null 

 Th1e vacant positions  in the queue are 
1	 2	 3	 4	 5	 6	 7	 
 1-for insert
 2-for delete 
 3-for display 
 4-for exit 
 Enter ur choice:4


Ds Week2 programs

Exercise 3

Implement stack operations using pointers

Aim::/*To implement stacks using pointers*/

Program::

#include< stdio.h> //Standard i/p,o/p header file
#define max 100
int  arr[max],top=-1; 
int  *stack=arr; 
 
/*Inserting the elements using push function*/ 
void  push(int  ele) 
{ 
     *stack=ele; 
    printf("\n\nElement %d is pushed......\n\n",ele); 
    stack++; 
    top++; 
} 
 
/*Removing the elements using pop function*/ 
void  pop() 
{ 
    if(top==-1) 
    { 
        print f("\n\nStack is empty....."); 
       
    } 
    else 
    { 
 
        printf("\n\nPoped element : %d",*(stack-1)); 
        stack--; 
        top--; 
    } 
} 
 
/*Displaying the elements */ 
void  display() 
{ 
     int  t; 
     if(top==-1) 
        printf("\n\nStack is empty....."); 
    else 
    { 
        printf("\n\nStack elements are : "); 
        for(t=top;t>=0;t--) 
        { 
                printf("%d ",*(stack-(t+1))); 
        } 
    } 
      
} 
int  main() 
{ 
    int  num1=0,num2=0,i,ch; 
    while(1) 
    { 
            printf("\n\t\t MENU "); 
            printf("\n[1]Push Function\n[2] Pop Function\n[3] Elements present in Stack\n[4] Exit\n"); 
            printf("\n\tEnter your choice: "); 
         
            scanf("%d",&ch); 
        switch(ch) 
        {  
                       case  1: printf("\n\tEnter the element to be pushed:"); 
                              scanf("%d",&num1); 
                             push(num1); 
                                  break; ; 
                       case  2: pop(); 
                                  break; ; 
                       case  3: display(); 
                                 break; ; 
                       case  4:    break; ; 
                  default:   printf("\nYour choice is invalid.\n"); 
                                      break; ; 
        } 
     
   } 
}

output::

gcc pointers.c -o pointers
./pointers

   MENU 
[1]Push Function
[2] Pop Function
[3] Elements present in Stack
[4] Exit

 Enter your choice: 1

 Enter the element to be pushed:8


Element 8 is pushed......


   MENU 
[1]Push Function
[2] Pop Function
[3] Elements present in Stack
[4] Exit

 Enter your choice: 1

 Enter the element to be pushed:2


Element 2 is pushed......


   MENU 
[1]Push Function
[2] Pop Function
[3] Elements present in Stack
[4] Exit

 Enter your choice: 1

 Enter the element to be pushed:17


Element 17 is pushed......


   MENU 
[1]Push Function
[2] Pop Function
[3] Elements present in Stack
[4] Exit

 Enter your choice: 3


Stack elements are : 8 2 17 
   MENU 
[1]Push Function
[2] Pop Function
[3] Elements present in Stack
[4] Exit

 Enter your choice: 4



Wednesday, 16 October 2013

Week 6 programs

Week 6

6b) Write a C++ program that reads a series of numbers and stores them in a vector. After the user inputs all the numbers he wishes to, ask how many of the numbers the user wants to sum. For an answer N, print the sum of the first N elements of the vector. For example “Please enter some numbers (press "0" at prompt to stop):” 12 23 13 24 15 “Please enter how many of the numbers you wish to sum, starting from the first:” 3 “The sum of the first 3 numbers : 12 23 and 13 is 48”

Aim::To find the sum of first "n" numbers in vector

Program::

#include< iostream>
#include< vector>
using namespace std;
int main()
{
       
	vector< int>vector;
        int myint=1;
        int i,n,sum=0;
   	cout<<"Please enter some numbers(enter 0 to stop) \n";
        while(myint!=0)
        {
             cin >>myint;
             if(myint!=0)
             vector.push_back(myint);
        }   
  	cout<<"Enter how many numbers you wish to sum \n";
    	cin>>n;
    	cout<<"The sum of first "<< n<< " numbers:";
    	for(i=0;i< n;i++)
    	{
        	sum+=vector[i];
        	cout<< vector[i] <<"\t";
    	}
    	cout<< " is "<< sum;

}

Output::

Please enter some numbers(enter 0 to stop) 
12 23 13 24 15 0
Enter how many numbers you wish to sum 
3
The sum of first 3 numbers:12	23  13  is 48

It assignment 1

Information Theory

Assignment-1

1)What is entropy ?give an example and what are the properties of entropy ?

Ans::

Entropy::

		The average amount of information conveyed is called as entropy
			H(X) = 
		where p(x) is probability of particular random variable in a random space x and
log p(x) is the self information for that paricular random variable.

Properties of entropy::

2)What is chain rule ?explain with relative entropy,entropy and mutual information ?


Ans::

friends answer is there in our facebook group

/Click here for the ans

3)State and prove krafts inequality theorem and explain optimal codes ?

Ans::

Kraft inequality: 
			For any instantaneous code (prefix code) over an alphabet of size D, the
codeword lengths *** must satisfy the inequality

Conversely, 
	given a set of codeword lengths that satisfy this inequality, there exists an instantaneous
 code with these word lengths. 
Proof::
	Consider a D-ary tree in which each node has D children. 

Let the branches of the tree represent the symbols of the codeword. 

The prefix condition on the codewords implies that no codeword is an ancestor 
of any other codeword on the tree. Hence, each codeword eliminates its descendants
as possible codewords. 

Let lmax be the length of the longest codeword of the set of codewords. 

Consider all nodes of the tree at level lmax.

Some of them are codewords, some are descendants of codewords, and some are neither. 

A codeword at level li has **** descendants at level lmax Each of these descendant sets must be disjoint.

Also,the total number of nodes in these sets must be less than or equal to Dlmax. 

Hence, summing over all the codewords, we have 

{
**************
}

Conversely,
given any set of codeword lengths ***** which satisfy the Kraft inequality,
we can always construct a tree and we have instantaneous code at each level


Optimal codes ::

4)Explain arithmetic code with an example ?

5)What is shannon fano elias code ?

Wednesday, 9 October 2013

Week 6 programs

Week 6
6a) Write a C++ program that uses functions.

I) to swap two integers II) to swap characters III) to swap two reals

Aim::To implement the swap functions by integer,character,real

Program::

#include< iostream >
using namespace std;
void swap(int a,int b)
{
   	cout<<"\nBefore swapping of integers:\nA="<< a<<"\nB="<< b;
	int c=a;
	a=b;
	b=c;
	cout<<"\nAfter swapping of integers:\nA="<< a<<"\nB="<< b;
}
	
voidswap(char a,char b)
{
	cout<<"\nBefore swapping of characters:\nA="<< a<<"\nB="<< b;
	char c=a;
	a=b;
	b=c;
	cout<<"\nAfter swapping of characters:\nA="<< a<<"\nB="<< b;
}

voidswap(float a,float b)
{
	cout<<"\nBefore swapping of reals:\nA="<< a<<"\nB="<< b;
	float c=a;
	a=b;
	b=c;
	cout<<"\nAfter swapping of realss:\nA="<< a<<"\nB="<< b;
}


int main()
{
	int a,b;
	cout<<"Enter two integers :";
	cin>>a>>b;
	swap(a,b);
	char c1,c2;
	cout<<"\nEnter two characters :";
	cin>>c1>>c2;
	swap(c1,c2);
	float f1,f2;
	cout<<"\nEnter two real numbers :";
	cin>>f1>>f2;
	swap(f1,f2);
}

Output::


Enter two integers :
7 17
Before swapping of integers:
A=7
B=17
After swapping of integers:
A=17
B=7

Enter two characters :
h n
Before swapping of characters:
A=h
B=n
After swapping of characters:
A=n
B=h

Enter two real numbers :
7.7 8.8
Before swapping of reals:
A=7.7
B=8.8
After swapping of reals:
A=8.8
B=7.7

Sunday, 6 October 2013

Week 2 Programs

Week 2

a) Write a C++ program to convert centigrade into Fahrenheit. Formula:C=(F-32)/1.8

AIM:To convert temperature into centigrade

Program::

#include< iostream >
using namespace std;
int main()
{
    float c,f;
   cout<<"Enter the temperature in fahrenheit"<< endl;
    cin>>f;
    c=(f-32)/1.8; //c=5(f-32)/9;
   cout<< "Temperature in centigrade is " << c;
}

Output::

Enter the temperature in fahrenheit
212
Temperature in centigrade is 100

Wednesday, 2 October 2013

Week 1 Programs

Week 1

1a) Write a C++ program to display “Hello, Welcome to C++ Programing”

AIM:To display “Hello, Welcome to C++ Programing

Program::

#include < iostream.h >
#include < string.h >
int main()
{
cout<< "\"Hello,welcome to c++ programming\"\n";
}

Output::

Hello,welcome to c++ programming

1b) Write a C++ program to print details name, rollnumber in a single and two lines.

AIM:To display name, rollnumber in a single and two lines

#include < iostream >
#include < cstring >
using namespace std ;
int main()
{
char Name[20];
int roll;
cout << "Enter Your name:\n ";
cin>>Name;
cout << "Enter Your roll number:\n ";
cin>>roll;
cout <<"Name:" << Name;
cout<<"Roll Number:" << roll;
cout<<"Name:" << Name << endl;
cout<<"Name:" << Name << endl <<"Roll Number:" < }

1c) Write a C++ program to print name by reading, assigning and initializing to a variable with an appropriate prompt

AIM:To display name by reading and assigning

#include < iostream >
#include < cstring >
using namespace std ;
int main()
{
char Name[20];
char Name1[20]=programmer007; cout << "Enter Your name:\n ";
cin>>Name;
cout <<"Name:" << Name < cout<<"Name1:" << Name << endl;
}

Output::

Enter your name
Programmer
Name:Programmer
Name1:Programmer 007


1d) Write a C++ program to print your personal details name, surname(single character), totalmarks, gender(M/F), result(P/F) by taking input from the user

AIM:To display personal details

#include < iostream >
#include < cstring >
using namespace std ;
int main()
{
char Name[20];
char s;
int m;
char g;
char r;
cout << "Enter Your name:\n ";
cin>>Name;
cout << "Enter Your Sur name:\n ";
cin>>s;
cout << "Enter your total marks:\n ";
cin>>m;
cout << "Enter Your gender (M/F):\n ";
cin>>g;
cout << "Enter your result(P/F):\n ";
cin>>r;
cout <<"Name:" << Name << endl;
cout <<"SurName:" << s << endl;
cout <<"Total marks:" << m << endl;
cout <<"Gender:" << g << endl;
cout <<"Result:" << r << endl;
}

Output::

Enter your name
Programmer
Enter your Surname name
C
Enter your Total marks
77
Enter your Gender
M
Enter your result
P
Name:Programmer
Sur Name:C
Total marks:77
Gender:M
Result:P