Sunday, January 26, 2014

C Program to Perform HeapSort

with 0 Comment
C Program to Perform HeapSort:

#include<stdio.h>
#include<conio.h>
void adjust(int b[],int i,int n)
{
int child,tmp;
for(tmp=b[i];i*2<=n;i=child)
{
child=i*2;
if(child!=n&&b[child+1]>b[child])
child++;
if(tmp<b[child])
b[i]=b[child];
else
break;
}
b[i]=tmp;
}
void heap(int b[],int n)
{
int i,t;
for(i=n/2;i>0;i--)
adjust(b,i,n);
for(i=n;i>0;i--)
{
t=b[i];
b[i]=b[1];
b[1]=t ;
adjust(b,1,i-1);
}}

void main()
{
int i,a[50],n;
clrscr();
printf("Heapsort\nEnter the no. of elements to be sorted\n");
scanf("%d",&n);
printf("Enter elements one by one\n");
for(i=1;i<=n;i++)
scanf("%d",&a[i]);
heap(a,n);
printf("Sorted array is:\n");
for(i=1;i<=n;i++)
printf("%d\n",a[i]);
getch();
}

C Program to Perform QuickSort

with 0 Comment
C Program to Perform QuickSort:

#include<stdio.h>
#include<conio.h>
void quicksort(int b[],int p,int q)
{
int j;
if(p<q)
{
j=partition(b,p,q+1);
quicksort(b,p,j-1);
quicksort(b,j+1,q);
}
}
int partition(int b[],int m,int p)
{
int v=b[m],i=m,j=p;
do
{
do
{
i++;
}while(b[i]<v);
do
{
j--;
}while(b[j]>v);
if(i<j)
{
p=b[i];
b[i]=b[j];
b[j]=p;
}}while(i<j);
b[m]=b[j];
b[j]=v;
return j;
}
main()
{
int i,a[50],n;
clrscr();
printf("Quicksort\nEnter the no. of elements to be sorted\n");
scanf("%d",&n);
printf("Enter elements one by one\n");
for(i=1;i<=n;i++)
scanf("%d",&a[i]);
i=0;
quicksort(a,i,n);
printf("Sorted array is:\n");
for(i=1;i<=n;i++)
printf("%d\n",a[i]);
getch();
}

C Program to illustrate Linked List Implementation of Stack

with 0 Comment
C Program to illustrate Linked List Implementation of Stack:

Main Program:

#include<stdio.h>
#include<conio.h>
#include<stdlib.h>
#include "c:\tc\bin\23llis.c "
void main()
{
int c,d;
clrscr();
while(1)
{
printf("\n1.Push\n2.Pop\n3.Display\n4.Exit\n");
printf("\nEnter your Choice");
scanf("%d",&c);
switch(c)
{
case 1:printf("Enter the element to be pushed");
scanf("%d",&d);
push(d);
break;
case 2:d=pop();
if(d!=1)
printf("The element popped is %d\n",d);else printf("stack is empty");
break;
case 3:display();break;
case 4:exit(0);break;
getch();
}
}
}

SubProgram: (Saved as '23llis.c')

struct node
{
char data;
struct node *next;
};
typedef struct node stack;
stack *top;
void create()
{
top=malloc(sizeof(stack));
top->next=NULL;
}
void display()
{
stack *t;
if(top->next==NULL)
printf("Stack is empty");
else
{
printf("top= ");
for(t=top->next;t!=NULL;t=t->next)
printf("%d\n",t->data);
}
}
int pop()
{
stack *temp,*t;
if(top->next==NULL)
return -1;
else
{
temp=top->next;
top->next=top->next->next;
t=temp;
free(temp);
return(t->data);
}            }
void push(int d)
{
stack *temp;
temp=malloc(sizeof(temp));
temp->data=d;
temp->next=top->next;
top->next=temp;
}

C Program to illustrate Linked List Implementation of List

with 0 Comment
C Program to illustrate Linked List Implementation of List:

Main Program:

#include<stdio.h>
#include<conio.h>
#include<malloc.h>
#include<alloc.h>
#include "c:\tc\bin\sublll.c"
void main()
{
int ch;
clrscr();
while(1)
{
printf("\n1.Create\n2.Insert\n3.Delete\n4.Transverse\n5.Search\n6.Exit\n");
printf("Enter your Choice:");
scanf("%d",&ch);
switch(ch)
{
case 1:create();
printf("After Creation");
display();
break;
case 2:insertion();
printf("After Insertion");
display(); break;
case 3:deletion();
printf("after deletion");
display();
break;
case 4:printf("Linked list is");
display();
break;
case 5:search();
break;
case 6:exit(0);
}
}
}

SubProgram: (Saved as 'sublll.c' )

struct list
{
int info;
struct list *next;
}*head,*p,*n;
typedef struct list node;
void create()
{
int no,x,i;
head=(node*)malloc(sizeof(node));
head->next=NULL;
p=head;
printf("\nEnter the No. of Elements");
scanf("%d",&no);
printf("\nEnter the Elements");
for(i=1;i<=no;i++)
{
n=(node*)malloc(sizeof(node));
scanf("%d",&x);
n->info=x;
p->next=n;
p=n;
}
p->next=NULL;
}
void insertion()
{
int x,pre;
node *n;
n=(node*)malloc(sizeof(node));
printf("\nEnter the element");
scanf("%d",&x);
printf("Enter the previous element");
scanf("%d",&pre);
if(pre==0)
{
n->info=x;
n->next=head->next;
head->next=n;
}
else
{
for(p=head->next;p!=NULL&&p->info!=pre;p=p->next);
n->info=x;
n->next=p->next;
p->next=n;
}
}
void deletion()
{
int x;
node *t;
printf("\nEnter the element to be deleted:");
scanf("%d",&x);
for(p=head->next;p!=NULL&&p->info!=x;p=p->next);
for(t=head;t->next!=NULL&&t->next!=p;t=t->next);
t->next=p->next;
free(p);
}
void display()
{
p=head->next;
while(p->next!=NULL)
{
printf("%d",p->info);
p=p->next;
}
printf("%d",p->info);
}
void search()
{
int x;
printf("\nEnter the element to be searched");
scanf("%d",&x);
for(p=head->next;p!=NULL&&p->info!=x;p=p->next);
if(p==NULL)
printf("\nData not present");
else
printf("\nData present");
}

C Program to Demonstrate Array Implementation of List

with 0 Comment
C Program to Demonstrate Array Implementation of List:

Main Program:

#include<stdio.h>
#include<conio.h>
#include "c:\tc\bin\subail.c"
void main()
{
int no,pos,s,c;
clrscr();
while(1)
{
printf("\n1.Append\n2.Printlist\n3.Insert\n4.Delete\n5.Search\n6.make Empty\n7.Exit\n");
scanf("%d",&c);
switch(c)
{
case 1:
printf("Enter the element to be append");
scanf("%d",&no);
append(no);
break;
case 2:
printlist();
break;
case 3:
printf("Enter the elment & Position of insertion\n");
scanf("%d%d",&no,&pos);
insert(no,pos);
break;
case 4:
printf("Enter the element to be deleted");
scanf("%d",&no);
delete(no);
break;
case 5:
printf("Enter the element to be found");
scanf("%d",&no);
s=find(no);
if(s==-1)
printf("Element is not Found");
else
printf("Element is at %d\n",s);
break;
case 6:
makeempty();
break;
case 7:exit(0);
default :printf("Enter a correct choice\n");
}
}
}

SubProgram: (Saved as 'subail.c' ) in the same folder of Main Program

#define size 10
int a[size];
int curpos=0;
void printlist()
{
int i;
if(curpos==0)
printf("No elements in array");
else
for(i=0;i<curpos;i++)
printf("Element in %d the position is %d\n",i,a[i]);
}
void append(int elem)
{
if(curpos<size)
{
a[curpos]=elem;
curpos++;
}
else
printf("List is full");
}
void insert(int elem,int pos)
{
int i;
if(curpos==size)
printf("Can`t do insertion");
else
{
for(i=curpos;i!=pos;i--)
a[i]=a[i-1];
a[pos]=elem;
curpos++;
}
}
int find(int elem)
{
int i,j=-1;
for(i=0;i<curpos;i++)
if(a[i]==elem)
return i;
if(i==curpos)
return j;
}
void delete(int elem)
{
int j;
int temp;
temp=find(elem);
if(temp==-1)
printf("Element %d is not found",temp);
else
{
for(j=temp;j<curpos;j++)
a[j]=a[j+1];
curpos--;
}
}
void makeempty()
{
int i;
for(i=0;i<curpos;i++)
a[i]=0;
curpos=0;
}

C Program to illustrate Array Implementation of Stack

with 0 Comment
C Program to illustrate Array Implementation of Stack:

Main Program:

#include<stdio.h>
#include<conio.h>
#include "c:\tc\bin\subais.c"
void main()
{
int c,d;
clrscr();
while(1)
{
printf("\nEnter your choice\n");
printf("\n1.Push\n2.Pop\n3.display\n4.Exit");
scanf("%d",&c);
switch(c)
{
case 1:printf("Enter the element to be pushed\n");
scanf("%d",&d);
push(d);
printstack();
break;
case 2:d=pop();
if(d!=-1)
{
printf("The element is Popped is %d\n",d);
printstack();
}
else
printf("The stack is Empty\n");
break;
case 3:printstack();
break;
case 4:exit(0);
}
}
}

Sub-Program: ( Saved as 'subais.c' ) in the same folder of Main Program

#define size 10
int a[size];
int top=-1;
void printstack()
{
int j;
if(top==-1)
printf("Stack is empty");
else
printf("\nAfter the operation stack is \n");
for(j=0;j<=top;j++)
printf("%d \t ",a[j]);
}

void push(int d)
{
if(top==size-1)
printf("\nStack is full");
else
{
top++;
a[top]=d ;
}
}
int pop()
{
int data;
if(top==-1)
data=-1;
else
{
data=a[top];
top--;
}
return(data);

}

C Program to illustrate Array Implementation of Queue

with 0 Comment
C Program to illustrate Array Implementation of Queue:

Main Program:

#include<stdio.h>
#include<conio.h>
#include"c:\tc\bin\subaiq.c"
void main()
{
int c,dat;
clrscr();
while(1)
{
printf("\nEnter your choice");
printf("\n1.Enqueue\n2.Dequeue \n3.Print enqueue\n4.Exit\n");
scanf("%d",&c);
switch(c)
{
case 1:printf("Enter the element to be inserted\n");
scanf("%d",&dat);
enqueue(dat);
printqueue();
break;
case 2:dequeue();
if(dat!=-1)
{
printf("The element deleted is %d\n",dat);
printqueue();
}
else
printf("Queue is Empty");
break;
case 3:printqueue();
break;
case 4:exit(0);

}
}
}

Sub Program: ( Saved as 'subaiq.c' )

#define size 100
int a[size];
int rear=-1;
int front=0;
void printqueue()
{
int j;
if(rear==-1)
printf("Queue is Empty");
else
{
printf("The element in the queue are\n");
for(j=0;j<=rear;j++)
printf("%d\t",a[j]);
}
}
void enqueue(int d)
{
if(rear==size-1)
printf("Queue is full");
else
{
rear++;
a[rear]=d;
}
}
int dequeue()
{
int d,i;
if(front>rear)
{
d=-1;
}
else
{
d=a[front];
for(i=front;i<=rear;i++)
a[i]=a[i+1];
rear=rear-1;
}
return d;
}

C++ Program to Demonstrate Hybrid Inheritance

with 0 Comment
C++ Program to Demonstrate Hybrid Inheritance:

#include<iostream.h>
#include<conio.h>
class student
{
protected:
int roll_number;
public:
void get_number(int a)
{
roll_number=a;
}
void put_number(void)
{
cout<<"Roll No: "<<roll_number<<"\n";
}
};

class test:public student
{
protected:
float part1,part2;
public:
void get_marks(float x,float y)
{
part1=x;
part2=y;
}
void put_marks(void)
{
cout<<"Marks Obtained: "<<"\n";
cout<<"Part1= "<<part1<<"\n";
cout<<"Part2= "<<part2<<"\n";
}
};
class sports
{
protected:
float score;
public:
void get_score(float s)
{
score=s;
}
void put_score(void)
{
cout<<"Sports wt: "<<score<<"\n\n";
}
};
class result:public test,public sports
{
float total;
public:
void display(void);
};
void result::display(void)
{
total=part1+part2+score;
put_number();
put_marks();
put_score();
cout<<"Total Score: "<<total<<"\n";
}
int main()
{
clrscr();
result student_1;
student_1.get_number(1234);
student_1.get_marks(27.5,33.0);
student_1.get_score(6.0);
student_1.display();
getch();
return 0;
}

C++ Program to Demonstrate Multiple Inheritance

with 0 Comment
C++ Program to Demonstrate Multiple Inheritance:

#include<iostream.h>
#include<conio.h>
class M
{
protected:
int m;
public:
void get_m(int);
};
class N
{
protected:
int n;
public:
void get_n(int);
};
class P:public M,public N
{
public:
void display(void);
};
void M::get_m(int x)
{
m=x;
}
void N::get_n(int y)
{
n=y;
};
void P::display(void)
{
cout<<"m= "<<m<<"\n";
cout<<"n= "<<n<<"\n";
cout<<"m*n= "<<m*n<<"\n";
}
int main()
{
P p;
clrscr();
p.get_m(10);
p.get_n(20);
p.display();
getch();
return 0;
}

C++ Program to Demonstrate Multi Level Inheritance

with 0 Comment
C++ Program to Demonstrate Multi Level Inheritance:

#include<iostream.h>
#include<conio.h>
class student
{
protected:
int roll_number;
public:
void get_number(int);
void put_number(void);
};
void student::get_number(int a)
{
roll_number=a;
}
void student::put_number()
{
cout<<"Roll Number: "<<roll_number<<"\n";
}
class test:public student
{
protected:
float sub1;
float sub2;
public:
void get_marks(float,float);
void put_marks(void);
};
void test::get_marks(float x,float y)
{
sub1=x;
sub2=y;
}
void test::put_marks()
{
cout<<"Marks in SUB1= "<<sub1<<"\n";
cout<<"Marks in SUB2= " <<sub2<<"\n";
}

class result:public test
{
float total;
public:
void display(void);
};
void result::display(void)
{
total=sub1+sub2;
put_number();
put_marks();
cout<<"Total= "<<total<<"\n";
}
int main()
{
clrscr();
result student1;
student1.get_number(111);
student1.get_marks(75.0,59.5);
student1.display();
getch();
return(0);
}

C++ Program to Demonstrate Single Inheritance

with 0 Comment
C++ Program to Demonstrate Single Inheritance:

#include<iostream.h>
#include<conio.h>
class B
{
int a;
public:
int b;
void get_ab();
int get_a(void);
void show_a(void);
};
class D::public B
{
int c;
public:
void mul(void);
void display(void);
};
void B::get_ab(void)
{
a=5;b=10;
}
int B::get_a()
{
return a;
}
void B::show_a()
{
cout<<"a="<<a<<"\n";
}
void D::mul()
{
c=b*get_a();
}
void D::display()
{
cout<<"a= "<<get_a()<<"\n";
cout<<"b="<<b<<"\n";
cout<<"c="<<c<<"\n\n";
}
int main()
{
D d;
clrscr();
d.get_ab();
d.mul();
d.show_a();
d.display();
d.b=20;
d.mul();
d.display();
getch();
return(0);
}

C++ Program to Explain the Concept of Data Conversion

with 0 Comment
C++ Program to Explain the Concept of Data Conversion:

#include<iostream.h>
#include<conio.h>
class invent2;
class invent1
{
int code;
int items;
float price;
public:
invent1(int a,int b,float c)
{
code=a;
items=b;
price=c;
}
void putdata()
{
cout<<"Code="<<code<<"\n";
cout<<"Item="<<items<<"\n";
cout<<"Value="<<price<<"\n";
}
int getcode()
{
return code;
}
int getitems()
{
return items;
}
float getprice()
{
return price;
}
operator float()
{
return(items*price);
}
};
class invent2
{
int code;
float value;
 public:
invent2()
{
code=0;
value=0;
}
invent2(int x,float y)
{
code=x;
value=y;
}
void putdata()
{
cout<<"Code="<<code<<"\n";
cout<<"value="<<value<<"\n";
}
invent2(invent1 p)
{
code=p.getcode();
value=p.getitems()*p.getprice();
}
};
int main()
{
clrscr();
invent1 s1(100,5,140.0);
invent2 d1;
float total_value;
total_value=s1;
d1=s1;
cout<<"Product Details-invent1 type" <<"\n";
s1.putdata();
cout<<"\nStock Value\n";
cout<<"Value="<<total_value<<"\n\n";
cout<<"Product Details-invent2 Type"<<"\n\n";
d1.putdata();
getch();
return 0;
}

C++ Program to Demonstrate Overloading Binary Operator

with 0 Comment
C++ Program to Demonstrate Overloading Binary Operator:

#include<iostream.h>
#include<conio.h>
class complex
{
float x;
float y;
public:
complex()
{
}
complex(float real,float imag)
{
x=real;
y=imag;
}
complex operator+(complex);
void display(void);
};
complex complex::operator+(complex c)
{
complex temp;
temp.x=x+c.x;
temp.y=y+c.y;
return(temp);
}
void complex::display(void)
{
cout<<x<<"+j"<<y<<"\n";
}
int main()
{
clrscr();
complex C1,C2,C3;
C1=complex(2.5,3.5);
C2=complex(1.6,2.7);
C3=C1+C2;
cout<<"C1= "; C1.display();
cout<<"C2= "; C2.display();
cout<<"C3= "; C3.display();
getch();
return 0;
}

C++ Program to Demonstrate Overloading Unary Operator

with 0 Comment
C++ Program to Demonstrate Overloading Unary Operator:

#include<iostream.h>
#include<conio.h>
class space
{
int x;
int z;
int y;
public:
void getdata(int a,int b,int c);
void display(void);
void operator-();
};
void space::getdata(int a,int b,int c)
{
x=a;
y=b;
z=c;
}
void space::display(void)
{
cout<<x<<"\t";
cout<<y<<"\t";
cout<<z<<"\n";
}
void space::operator-()
{
x=-x;
y=-y;
z=-z;
}
int main()
{
clrscr();
space s;
s.getdata(10,-20,30);
cout<<"s= ";
s.display();
-s;
cout<<"s= ";
s.display();
getch();
return 0;
}

C++ Program to demonstrate the Destructor Function

with 0 Comment
C++ Program to demonstrate the Destructor Function:

#include<iostream.h>
#include<conio.h>
int count=0;
class alpha
{
public:
alpha()
{
count++;
cout<<"\n No of Objects created"<<count;
}
~alpha()
{
cout<<"\n No of Objects Destroyed"<<count;
count--;
}
};
int main()
{
clrscr();
cout<<"\n Enter main\n";
alpha A1,A2,A3,A4;
{
cout<<"\n Enter Block 1\n";
alpha A5;
}
{
cout<<"\n Enter Block 2\n";
alpha A6;
}
cout<<"\n\n Re-Enter main\n\n";
getch();
}

C++ Program using Copy Constructor

with 0 Comment
C++ Program using Copy Constructor:

#include<iostream.h>
#include<conio.h>
#include<stdio.h>
class code
{
int id;
public:
code()
{
}
code(int a)
{
id=a;
}
code(code &x)
{
id=x.id;
}
void display(void)
{
cout<<id;
}
};

void main()
{
code A(100);
code B(A);
code C=A;
code D;
D=A;
clrscr();
cout<<"\n id of A ";A.display();
cout<<"\n id of B ";B.display();
cout<<"\n id of C ";C.display();
cout<<"\n id of D ";D.display();
getch();
}

C++ Program using Class with Constructor

with 0 Comment
C++ Program using Class with Constructor:

#include<iostream.h>
#include<stdio.h>
#include<conio.h>
class integer
{
int m,n;
public:
integer(int,int);
void display(void)
{
cout<<"m="<<m<<"\n";
cout<<"n="<<n<<"\n";
}
};
integer::integer(int x,int y)
{
m=x;
n=y;
}
void main()
{
integer int1(0,100);
integer int2=integer(25,75);
clrscr();
cout<<"\n OBJECT 1"<<"\n";
int1.display();
cout<<"\n OBJECT 2"<<"\n";
int2.display();
getch();
}

C++ Program using Friend Function

with 0 Comment
C++ Program using Friend Function:

#include<iostream.h>
#include<stdio.h>
#include<conio.h>
class sample
{
int a;
int b;
public:
void setvalue()
{
a=25;
b=45;
}
friend float mean(sample s);
};
float mean(sample s)
{
return float(s.a+s.b)/2.0;
}
void main()
{
sample x;
clrscr();
x.setvalue();
cout<<"Mean value"<<mean(x)<<"\n";
getch();
}

C++ Program using Static Class Member

with 0 Comment
C++ Program using Static Class Member:

#include<iostream.h>
#include<stdio.h>
#include<conio.h>
class item
{
static int count;
int number;
public:
void getdata(int a)
{
number=a;
count++;
}
void getcount(void)
{
cout<<"Count=";
cout<<count<<"\n";
}
};
int item::count;
void main()
{
item a,b,c;
clrscr();
a.getcount();
b.getcount();
c.getcount();
a.getdata(100);
b.getdata(200);
c.getdata(300);
cout<<"After reading data"<<"\n";
a.getcount();
b.getcount();
c.getcount();
getch();
}

C++ Program to demonstrate Function Overloading

with 0 Comment
C++ Program to demonstrate Function Overloading:

#include<iostream.h>
#include<stdio.h>
#include<conio.h>
int volume(int);
double volume(double,int);
long volume(long,int,int);
int main()
{
clrscr();
cout<<"\nVolume of Cube "<<volume(10)<<"\n";
cout<<"\nVolume of Cylinder "<<volume(2.5,8)<<"\n";
cout<<"\nVolume of Rectangle "<<volume(100,75,15)<<"\n";
getch();
return(0);
}
int volume(int s)
{
return(s*s*s);
}
double volume(double r,int h)
{
return(3.14*r*r*h);
}
long volume(long l,int b,int h)
{
return(l*b*h);
}

C++ Program to illustrate Class Implementation

with 0 Comment
C++ Program to illustrate Class Implementation:

#include<iostream.h>
#include<stdio.h>
#include<conio.h>
class item
{
int number;
float cost;
public:
void getdata(int a,float b);
void putdata(void)
{
cout<<"Number:"<<number<<"\n";
cout<<"cost:"<<cost<<"\n";
}
};
void item::getdata(int a,float b)
{
number=a;
cost=b;
}
int main()
{
item x;
clrscr();
cout<<"\n Object x"<<"\n";
x.getdata(100,299.75);
x.putdata();
item y;
cout<<"\n Object y"<<"\n";
y.getdata(200,175.5);
y.putdata();
getch();
return(0);
}

C++ Program to Swap Values of Two Variables Using Call by Value and Call by Reference Method

with 0 Comment
C++ Program to Swap Values of Two Variables Using Call by Value Method:

#include<iostream.h>
#include<stdio.h>
#include<conio.h>
void swap(int a,int b)
{
int t;
t=a;
a=b;
b=t;
}
void main()
{
int x=13,y=3;
clrscr();
cout<<"\nValues before invoking swap"<<x<<"\t"<<y;
swap(x,y);
cout<<"\nValues after invoking swap"<<x<<"\t"<<y;
getch();
}

C++ Program to Swap Values of Two Variables Using Call by Reference Method:

#include<iostream.h>
#include<stdio.h>
#include<conio.h>
void swap(int &a,int &b)
{
int t;
t=a;
a=b;
b=t;
}void main()
{
int x=13,y=2;
clrscr();
cout<<"\nValues before invoking swap"<<x<<"\t"<<y;
swap(x,y);
cout<<"\nValues after invoking Swap"<<x<<"\t"<<y;
getch();

}

C++ Program to illustrate Scope Resolution Operator

with 0 Comment
C++ Program to illustrate Scope Resolution Operator:

#include<stdio.h>
#include<iostream.h>
#include<conio.h>
int m=10;
int main()
{
int k,m;
m=30;
k=20;
clrscr();
cout<<"k="<<k<<endl;
cout<<"m="<<m<<endl;
cout<<"::m="<<::m<<endl;
getch();
return(0);
}

C++ Program to Find the Average of Two Numbers

with 0 Comment
C++ Program to Find the Average of Two Numbers:

#include<iostream.h>
#include<conio.h>
#include<stdio.h>
int main()
{
float a,b,c;
float avg;
clrscr();
cout<<"Enter the Value of a"<<endl;
cin>>a;
cout<<"Enter the value of b"<<endl;
cin>>b;
c=a+b;
avg=c/2;
cout<<"Average is:"<<avg;
getch();
return(0);
}

Linear Convolution Using TMS320C50 DSP Processor

with 0 Comment
Linear Convolution Using TMS320C50 DSP Processor:

C000 LDP #100H
C001 LAR 0,#8004
C003 LAR 1,#8050
C005 LAR 2,#07
C006 ZAP
C007 MAR *,0
C008 RPT #05
C009 MAC C050,*,-
C00B ADR #07
C00C MAR *,1
C00D SACL *+,0,2
C00E MAR *-
C00F BANZ C006,0
C011 B C011


     x(n)                 h(n)
8000-0000     C050-0001
8001-0000     C051-0001
8002-0000     C052-0001
8003-0000     C053-0001
8004-0001     C054-0001
8005-0002     C055-0000
8006-0003     C056-0000
8007-0000
8008-0000
8009-0000
800A-0000

OUTPUT:
8050-0001
8051-0003
8052-0006
8053-0006
8054-0006
8055-0005
8056-0003

Basic Arithmetic Operation Using TMS320L50 DSP Processor

with 0 Comment
Basic Arithmetic Operation Using TMS320L50 DSP Processor:

ADDITION:
C000 LDP #100H
C001 LACC #05,0
C003 ADD #02
C004 SACL 0010,0
C005 SACH 0011,0
C006 B C006


   INPUT                      OUTPUT
ACCUMULATOR-05              8010 - 0007
IMMEDIATE DATA-02           8011 - 0000


SUBTRACTION:
C000 LDP #100H
C001 LACC #07,0
C003 SUB #03
C004 SACL 0010,0
C005 SACH 0011,0
C006 B C006

   INPUT                      OUTPUT
ACCUMULATOR-07              8010 - 0004
IMMEDIATE DATA-03           8011 - 0000



AND OPERATION:
C000 LDP #100
C001 LACC #06,0
C003 AND #05
C004 SACL 0010,0
C005 SACH 0011,0
C006 B C006

    INPUT                      OUTPUT
ACCUMULATOR-06              8020 - 0004
IMMEDIATE DATA-05           8021 - 0000


OR OPERATION:
C000 LDP #100
C001 LACC #08,0
C003 OR #03
C004 SACL 0010,0
C005 SACH 0011,0
C006 B C006

    INPUT                      OUTPUT
ACCUMULATOR-08              8020 - 000B
IMMEDIATE DATA-03           8021 - 0000


XOR OPERATION:
C000 LDP #100
C001 LACC #04,0
C003 XOR #09
C004 SACL 0010,0
C005 SACH 0011,0
C006 B C006

    INPUT                      OUTPUT
ACCUMULATOR-04              8020 - 000D
IMMEDIATE DATA-09           8021 - 0000


INDIRECT ADDRESSING MODES:
LDP #100
LAR 0,#8001
LAR 1,#8010
MAR *,0
LACC *+
ADD *,0,1
SACL *+
SACH *


MULTIPLICATION:

LDP #100
LACC #037A,0
SACL 0000,0
LACC #012E,0
SACL 0001,0
LT 0000
MPY 0001
PAC
SACL 0002,0
SACH 0003,0


   INPUT                      OUTPUT
ACCUMULATOR-05              8020 - 0050
IMMEDIATE DATA-10           8021 - 0000

C Program to Perform Circular Convolution Using CCstudio and C Compiler

with 0 Comment
%C Program to Perform Circular Convolution Using CCstudio and C Compiler

#include<stdio.h>
#include<conio.h>
int m,n,x[30],h[30],y[30],i,j,temp[30],k,x2[30],a[30];
void main()
{
printf("Enter the length of the first sequence\n");
scanf("%d",&m);
printf("Enter the length of the second sequence\n");
scanf("%d",&n);
printf("Enter the first sequence\n");
for(i=0;i<m;i++)
scanf("%d",&x[i]);
printf("Enter the Second sequence\n");
for(j=0;j<n;j++)
scanf("%d",&h[j]);
if(m-n!=0)
{
if(m>n)
{
for(i=n;i<m;i++)
h[i]=0;
n=m;
}
for(i=m;i<n;i++)
x[i]=0;
m=n;
}
y[0]=0;
a[0]=h[0];
for(j=1;j<n;j++)
a[j]=h[n-j];
for(i=0;i<n;i++)
y[0]+=x[j]*a[i];
for(k=1;k<n;k++)
{
y[k]=0;
for(j=1;j<n;j++)
x2[j]=a[j-1];
x2[0]=a[n-1];
for(i=0;i<n;i++)
{
a[i]=x2[i];
y[k]+=x[i]*x2[i];
}
}
printf("The Resultant Sequence is \n");
for(i=0;i<n;i++)
printf("%d\t",y[i]);
}

C Program to Perform Linear Convolution Using CCstudio and C Compiler

with 0 Comment
%Program to Perform Linear Convolution in CCstudio and Turbo C++ Compiler.

#include<stdio.h>
#include<conio.h>
void main()
{
int x[15]={0},y[15]={0},h[15]={0},n1,n2,n,i,j;
printf("Enter the No.of Samples of x(n)");
scanf("%d",&n1);
for(i=0;i<n1;i++)
{
printf("Enter the %d th sample",i+1);
scanf("%d",&x[i]);
}
printf("Enter the No.of Samples of h(n)");
scanf("%d",&n2);
for(i=0;i<n2;i++)
{
printf("Enter the %d th sample",i+1);
scanf("%d",&h[i]);
}
n=n1+n2-1;
printf("The Resultant Sequence is");
for(i=0;i<n;i++)
{
for(j=0;j<=i;j++)
y[i]=y[i]+x[j]*h[i-j];
printf("%d",y[i]);
}
}

Matlab Program to Perform Magnitude Spectrum

with 0 Comment
%Matlab Program to perform Magnitude Spectrum

clc;
close all;
clear all;
x=[1 2 3 4];
xk=fft(x,8);
xm=abs(xk);
disp(xm);
subplot(2,2,1);
stem(xm);
grid on
title('8 Point Sequence');
xk1=fft(x,16);
xm1=abs(xk1);
disp(xm1);
subplot(2,2,2);
stem(xm1);
grid on
title('16 Point Sequence');
xk2=fft(x,32);
xm2=abs(xk2);
disp(xm2);
subplot(2,2,3);
stem(xm2);
grid on
title('32 Point Sequence');
xk3=fft(x,64);
xm3=abs(xk3);
disp(xm3);
subplot(2,2,4);
stem(xm3);
title('64 Point Sequence');

Matlab Program to Perform Sampling and Aliasing

with 0 Comment
Matlab Program to Perform Sampling and Aliasing:

clc
close all
clear all

t=0:0.01:1;
f1=10;
xt=sin(2*pi*f1*t);
subplot(2,2,1);
plot(t,xt);
 grid on
title('Sine wave at 10Hz');
xlabel('Time(sec)');
ylabel('Amplitude');

n1=linspace(0,1,20)
xn1=sin(2*pi*f1*n1);
subplot(2,2,2);
plot(t,xt,'g');
hold on
subplot(2,2,2);
stem(n1,xn1);
grid on
title('fs=2f1');
xlabel('n');
ylabel('Amplitude');

n2=linspace(0,1,16)
xn2=sin(2*pi*f1*n2);
subplot(2,2,3);
plot(t,xt,'g');
hold on
subplot(2,2,3);
stem(n2,xn2);
grid on
title('fs<2f1');
xlabel('n');
ylabel('Amplitude');

n3=linspace(0,1,41)
xn3=sin(2*pi*f1*n3);
subplot(2,2,4);
plot(t,xt,'g');
hold on
subplot(2,2,4);
stem(n3,xn3);
grid on
title('fs>2f1');
xlabel('n');
ylabel('Amplitude');

figure(2)
xk=fft(xt)
subplot(2,2,1);
stem(abs(xk));
grid on
title('Magnitude spectrum of xt');
xlabel('k');
ylabel('X(K)');


xk1=fft(xn1)
subplot(2,2,2);
stem(abs(xk1));
grid on
title('Magnitude spectrum of fs=2fm');
xlabel('k');
ylabel('X(K)');

xk2=fft(xn2)
subplot(2,2,3);
stem(abs(xk2));
grid on
title('Magnitude spectrum of fs<2f1');
xlabel('k');
ylabel('X(K)');

xk3=fft(xn3)
subplot(2,2,4);
stem(abs(xk3));
grid on
title('Magnitude spectrum of fs>2f1');
xlabel('k');
ylabel('X(K)');

Matlab Program for Linear Convolution

with 0 Comment
Matlab Program for Linear Convolution:

Program 1: ( Program assigned Input )

clc
close all
clear all
x=[1 2 3 4]
subplot(2,2,1);
stem(x);
title('x(n) sequence');
xlabel('n');
ylabel('Amplitude');
grid on

h=[1 2 1 2];
subplot(2,2,2);
stem(h);
title('h(n) sequence');
xlabel('n');
ylabel('Amplitude');
grid on

y=conv(x,h);
subplot(2,2,3);
stem(y);
grid on
title('y(n) sequence');
xlabel('n');
ylabel('Amplitude');

Program 2: ( User Assigned Input )

clc
clear
x=input('Enter the x(n) sequence');
c=length(x);
t=0:c-1;
subplot(2,2,1);
stem(t,x);
title('x(n) Sequence');
xlabel('n');
ylabel('x(n)');

h=input('Enter the h(n) sequence');
c=length(h);
t=0:c-1;
subplot(2,2,2);
stem(t,h);
title('h(n) Sequence');
xlabel('n');
ylabel('h(n)');

y=conv(x,h);
c=length(y);
t=0:c-1;
subplot(2,2,3);
stem(t,y);
disp('The y(n)Convolution sequence is');
disp(y);
title('Linear Convolution');
xlabel('n');
ylabel('y(n)');

Matlab Program for Generation of Basic Signals

with 0 Comment
Maltab Program for Generation of Basic Signals like Unit Step Function,Unit Ramp Function,Unit Impulse Function,Sinusoidal Function,Cosine Signal,Exponential Signal Increasing,Exponential Signal Decreasing,Square Signal:

clc
clear all
close all
t=-1:0.1:1;
x=[0,0,0,0,0,0,0,0,0,0,1,1,1,1,1,1,1,1,1,1,1];
subplot(4,4,1);
plot(t,x,'k');
gridon
ylabel('amplitude');
xlabel('time');
title('Unit Step');
subplot(4,4,2);
stem(t,x,'k');
gridon
ylabel('amplitude');
xlabel('time');
title('Unit Step');

t=-1:0.1:1;
x=[0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0];
subplot(4,4,3);
plot(t,x,'k');
gridon
ylabel('amplitude');
xlabel('time');
title(' Unit Impulse');
subplot(4,4,4);
stem(t,x,'k');
gridon
ylabel('amplitude');
xlabel('time');
title(' Unit Impulse');

t=0:1:5;
x=[0,1,2,3,4,5];
subplot(4,4,5);
plot(t,x,'k');
gridon
axis([0 5 0 5]);
ylabel('amplitude');
xlabel('time');
title(' Unit Ramp');
subplot(4,4,6);
stem(t,x,'k');
gridon
axis([0 5 0 5]);
ylabel('amplitude');
xlabel('time');
title(' Unit Ramp');

t=-2*pi:pi/5:2*pi;
x=sin(t);
subplot(4,4,7);
plot(t,x,'k');
gridon
axis([-2*pi 2*pi -1 1])
ylabel('amplitude');
xlabel('time');
title(' Sine Signal');
subplot(4,4,8);
stem(t,x,'k');
gridon
axis([-2*pi 2*pi -1 1])
ylabel('amplitude');
xlabel('time');
title(' Sine Signal');

t=-6.28:0.5:6.28;
x=cos(t);
subplot(4,4,9);
plot(t,x,'k');
gridon
axis([-6.28 6.28 -1 1])
ylabel('amplitude');
xlabel('time');
title(' Cosine signal');
subplot(4,4,10);
stem(t,x,'k');
gridon
axis([-6.28 6.28 -1 1])
ylabel('amplitude');
xlabel('time');
title(' Cosine signal');

t=0:0.5:5;
x=exp(t);
subplot(4,4,11);
plot(t,x,'k');
gridon
axis([0 5 0 150]);
ylabel('amplitude');
xlabel('time');
title(' Exponential Signal Increasing');
subplot(4,4,12);
stem(t,x,'k');
gridon
axis([0 5 0 150]);
ylabel('amplitude');
xlabel('time');
title(' Exponential Signal Increasing');

t=0:0.5:5;
x=exp(-t);
subplot(4,4,13);
plot(t,x,'k');
gridon
axis([0 5 0 1]);
ylabel('amplitude');
xlabel('time');
title(' Exponential Signal Decreasing');
subplot(4,4,14);
stem(t,x,'k');
gridon
axis([0 5 0 1]);
ylabel('amplitude');
xlabel('time');
title(' Exponential Signal Decreasing');

t=-10:1:10;
x=square(t);
subplot(4,4,15);
plot(t,x,'k');
gridon
axis([-10 10 -1.5 1.5]);
ylabel('amplitude');
xlabel('time');
title(' Square Signal');
subplot(4,4,16);
stem(t,x,'k');
gridon
axis([-10 10 -1.5 1.5]);
ylabel('amplitude');
xlabel('time');
title(' Square Signal');

AnnaUniversity EC66 Computer Networks Lab - Implementation of Virtual Local Area Network(VLAN) using Packet Tracer

with 0 Comment
Implementation of Virtual Local Area Network VLAN using Packet Tracer:
S1>enable
S1#Configure terminal
S1(config)#interface vlan 1
S1(config-if)#ip address 192.168.1.10 255.255.255.0
S1(config-if)#no shutdown
S1(config-if)#exit

S2>enable
S2#Configure terminal
S2(config)#interface vlan 1
S2(config-if)#ip address 192.168.1.11 255.255.255.0
S2(config-if)#no shutdown
S2(config-if)#exit

S3>enable
S3#Configure terminal
S3(config)#interface vlan 1
S3(config-if)#ip address 192.168.1.12 255.255.255.0
S3(config-if)#no shutdown
S3(config-if)#exit

S1>enable
S1#Configure terminal
S1(config)#interface Fa0/1
S1(config-if)#switchport mode trunk
S1(config-if)#exit

S1>enable
S1#Configure terminal
S1(config)#interface Fa0/2
S1(config-if)#switchport mode trunk
S1(config-if)#exit

S2>enable
S2#Configure terminal
S2(config)#interface Fa0/1
S2(config-if)#switchport mode trunk
S2(config-if)#exit

S2>enable
S2#Configure terminal
S2(config)#interface range Fa0/2 - 4
S2(config-if)#switchport mode access
S2(config-if)#exit

S3>enable
S3#Configure terminal
S3(config)#interface range Fa0/1
S3(config-if)#switchport mode trunk
S3config-if)#exit

S3>enable
S3#Configure terminal
S3(config)#interface range Fa0/2 - 4
S3(config-if)#switchport mode access
S3(config-if)#exit

CONFIGURING VLAN TRUNKING PROTOCOL (VTP):

S1>enable
S1#Configure terminal
S1(config)#vtp domain NEC
S1(config)#exit

CONFIGURING VLAN 10,20 & 30
S1>enable
S1#Configure terminal
S1(config)#vlan 10
S1(config-vlan)#name ECE
S1(config)#exit

S1>enable
S1#Configure terminal
S1(config)#vlan 20
S1(config-vlan)#name CSE
S1(config)#exit

S1>enable
S1#Configure terminal
S1(config)#vlan 30
S1(config-vlan)#name EEE
S1(config)#exit


S1>enable
S1#Configure terminal
S1(config)#interface vlan 10
S1(config-vlan)#ip address 192.168.20.1 255.255.255.0
S1(config)#exit

S1>enable
S1#Configure terminal
S1(config)#interface vlan 20
S1(config-vlan)#ip address 192.168.30.1 255.255.255.0
S1(config)#exit

S1>enable
S1#Configure terminal
S1(config)#interface vlan 30
S1(config-vlan)#ip address 192.168.40.1 255.255.255.0
S1(config)#exit

S1>enable
S1#Configure terminal
S1(config)#interface vlan 10
S1(config-vlan)#ip address 192.168.20.1 255.255.255.0
S1(config)#exit

S1>enable
S1#Configure terminal
S1(config)#interface vlan 20
S1(config-vlan)#ip address 192.168.30.1 255.255.255.0
S1(config)#exit

S1>enable
S1#Configure terminal
S1(config)#interface vlan 30
S1(config-vlan)#ip address 192.168.40.1 255.255.255.0
S1(config)#exit


CONFIGURING VLAN  TO PC’S:

PC1 – VLAN 10 - 192.168.20.20
PC2 – VLAN 20 - 192.168.30.20
PC3 – VLAN 30 - 192.168.40.20

PC4 – VLAN 10 - 192.168.20.21
PC5 – VLAN 20 - 192.168.30.21
PC6 – VLAN 30 - 192.168.40.21

AnnaUniversity EC66 Computer Networks Lab - Simulation of Wireless Environment Using NS-2

with 0 Comment
Simulation of Wireless Environment Using NS-2:


# Define options set val(chan)           Channel/WirelessChannel    ;# channel type set val(prop)           Propagation/TwoRayGround   ;# radio-propagation model set val(netif)           Phy/WirelessPhy            ;# network interface type set val(mac)           Mac/802_11                 ;# MAC type set val(ifq)             Queue/DropTail/PriQueue    ;# interface queue type set val(ll)                LL                         ;# link layer type set val(ant)            Antenna/OmniAntenna        ;# antenna model set val(ifqlen)         50                         ;# max packet in ifq set val(nn)              3                          ;# number of mobilenodes set val(rp)             AODV                       ;# routing protocol set val(x)               500     ;# X dimension of topography set val(y)               400     ;# Y dimension of topography   set val(stop) 150   ;# time of simulation end
#=====================================================================
# Main Program
#======================================================================
#
# Initialize Global Variables
#
# create simulator instance
set ns_ [new Simulator]
# setup topography object
set topo [new Topography]
# define topology
$topo load_flatgrid $val(x) $val(y)
# create trace object for ns and nam
set tracefd [open out.tr w]
$ns_ trace-all $tracefd
$ns_ use-newtrace
set namtrace    [open out.nam w]
$ns_ namtrace-all-wireless $namtrace $val(x) $val(y)

#
# Create God
#
set god_ [create-god $val(nn)]
#
# define how node should be created
#
# configure the nodes         $ns_ node-config -adhocRouting $val(rp) \ -llType $val(ll) \ -macType $val(mac) \ -ifqType $val(ifq) \ -ifqLen $val(ifqlen) \ -antType $val(ant) \ -propType $val(prop) \ -phyType $val(netif) \ -channelType $val(chan) \ -topoInstance $topo \ -agentTrace ON \ -routerTrace ON \ -macTrace OFF \ -movementTrace ON   for {set i 0} {$i < $val(nn) } { incr i } { set node_($i) [$ns_ node] }
# Provide initial location of mobilenodes $node_(0) set X_ 5.0 $node_(0) set Y_ 5.0 $node_(0) set Z_ 0.0 $node_(1) set X_ 490.0 $node_(1) set Y_ 285.0 $node_(1) set Z_ 0.0 $node_(2) set X_ 150.0 $node_(2) set Y_ 240.0 $node_(2) set Z_ 0.0  # Generation of movements $ns_ at 10.0 "$node_(0) setdest 250.0 250.0 3.0" $ns_ at 15.0 "$node_(1) setdest 45.0 285.0 5.0" $ns_ at 110.0 "$node_(0) setdest 480.0 300.0 5.0"
# Set a TCP connection between node_(0) and node_(1) set tcp [new Agent/TCP/Newreno] set sink [new Agent/TCPSink] $ns_ attach-agent $node_(0) $tcp $ns_ attach-agent $node_(1) $sink $ns_ connect $tcp $sink set ftp [new Application/FTP] $ftp attach-agent $tcp

#Application start & stop time
$ns_ at 60.0 "$ftp start"
$ns_ at 90.0 "$ftp stop"

# Define node initial position in nam
for {set i 0} {$i < $val(nn)} { incr i } { # 30 defines the node size for nam $ns_ initial_node_pos $node_($i) 30 }
# Telling nodes when the simulation ends
for {set i 0} {$i < $val(nn) } { incr i } {    $ns_ at $val(stop) "$node_($i) reset"; }  $ns_ run

AnnaUniversity EC66 Computer Networks Lab - Simulation of Wired Environment Using NS-2

with 0 Comment
Simulation of Wired Environment Using NS-2:

set ns [new Simulator]
set tr [open out.tr w]
$ns trace-all $tr
set namtr [open out.nam w]
$ns namtrace-all $namtr
set n0 [$ns node]
set n1 [$ns node]
set n2 [$ns node]
set n3 [$ns node]
set n4 [$ns node]
set n5 [$ns node]
$ns color 1 black
$ns color 2 green
$ns duplex-link $n0 $n1 10Mb 5ms DropTail
$ns duplex-link $n2 $n0 10Mb 5ms DropTail
$ns duplex-link $n3 $n0 10Mb 5ms DropTail
$ns duplex-link $n1 $n4 10Mb 5ms DropTail
$ns duplex-link $n1 $n5 10Mb 5ms DropTail
$ns duplex-link-op $n0 $n1 orient right
$ns duplex-link-op $n0 $n2 orient left-up
$ns duplex-link-op $n0 $n3 orient left-down
$ns duplex-link-op $n1 $n4 orient right-up
$ns duplex-link-op $n1 $n5 orient right-down
$ns at 10.0 "$ns halt"
set udp0 [new Agent /UDP]
set tcp1 [new Agent /TCP]
$ns attach-agent $n0 $udp0
$ns attach-agent $n0 $tcp1
set null0 [new Agent /NULL]
set null1 [new Agent /TCPSink]
$ns attach-agent $n4 $null0
$ns attach-agent $n5 $null1
$ns connect $udp0 $null0
$udp0 set fid_ 1
$ns connect $tcp1 $null1
$tcp1 set fid_ 2
set cbr0 [new Application /Traffic /CBR]
set cbr1 [new Application /Traffic /CBR]
$cbr0 attach-agent $udp0
$cbr1 attach-agent $tcp1
$cbr0 set packetsize_ 512
$cbr1 set packetsize_ 512
$cbr0 set interval_ 0.01
$cbr1 set interval_ 0.01
$ns at 1.0 "$cbr0 start"
$ns at 5.0 "$cbr0 stop"
$ns at 2.0 "$cbr1 start"
$ns at 7.0 "$cbr1 stop"
$ns run


AnnaUniversity EC66 Computer Networks Lab - Implementation of Link State Routing Protocol(LSRP) on Router

with 0 Comment
Link  State Routing  Protocol:

Router 0

ss>en
ss#conf t
Enter configuration commands, one per line.  End with CNTL/Z.
ss(config)#hostname ss
ss(config)#nt s2/0
                 ^
% Invalid input detected at '^' marker.
               
ss(config)#int s2/0
ss(config-if)#ip address 192.168.5.1 255.255.255.252
ss(config-if)#clock rate 64000
ss(config-if)#no shutdown
ss(config-if)#exit
ss(config)#int fo/0
                     ^
% Invalid input detected at '^' marker.
               
ss(config)#int f0/0
ss(config-if)#ip address 192.168.5.129 255.255.255.192
ss(config-if)#no shutdown
ss(config-if)#exit
ss(config)#en
% Ambiguous command: "en"
ss(config)#exit
%SYS-5-CONFIG_I: Configured from console by console
ss#conf t
Enter configuration commands, one per line.  End with CNTL/Z.
ss(config)#router OSPF 1
ss(config-router)#network 192.168.5.0 0.0.0.3 area 0
ss(config-router)#network 192.168.5.128 0.0.0.63 area0
                                                          ^
% Invalid input detected at '^' marker.
               
ss(config-router)#network 192.168.5.0 0.0.0.3 area 0
ss(config-router)#exit
ss(config)#exit
%SYS-5-CONFIG_I: Configured from console by console
ss#en
ss#copy ru st
Destination filename [startup-config]?
Building configuration...
[OK]
ss#show ip route
Codes: C - connected, S - static, I - IGRP, R - RIP, M - mobile, B - BGP
       D - EIGRP, EX - EIGRP external, O - OSPF, IA - OSPF inter area
       N1 - OSPF NSSA external type 1, N2 - OSPF NSSA external type 2
       E1 - OSPF external type 1, E2 - OSPF external type 2, E - EGP
       i - IS-IS, L1 - IS-IS level-1, L2 - IS-IS level-2, ia - IS-IS inter area
       * - candidate default, U - per-user static route, o - ODR
       P - periodic downloaded static route

Gateway of last resort is not set

     192.168.5.0/24 is variably subnetted, 2 subnets, 2 masks
C       192.168.5.0/30 is directly connected, Serial2/0
C       192.168.5.128/26 is directly connected, FastEthernet0/0
Router 1
ss1>en
ss1#conf t
Enter configuration commands, one per line.  End with CNTL/Z.
ss1(config)#hostname ss1
ss1(config)#int s2/0
ss1(config-if)#ip address 192.168.5.1 255.255.255.252
ss1(config-if)#clock rate 64000
ss1(config-if)#no shutdown
ss1(config-if)#exit
ss1(config)#int f0/0
ss1(config-if)#ip address 192.168.5.129 255.255.192
                                             ^
% Invalid input detected at '^' marker.
               
ss1(config-if)#ip address 192.168.5.129 255.255.255.192
ss1(config-if)#no shutdown
ss1(config-if)#exit
ss1(config)#exit
%SYS-5-CONFIG_I: Configured from console by console
ss1#conf t
Enter configuration commands, one per line.  End with CNTL/Z.
ss1(config)#router OSPF 1
ss1(config-router)#network 192.168.5.0 0.0.0.3 area 0
ss1(config-router)#network 192.168.6.1 0.0.0.255 area 0
ss1(config-router)#exit
ss1(config)#exit
%SYS-5-CONFIG_I: Configured from console by console
ss1#copy ru st
Destination filename [startup-config]?
Building configuration...
[OK]
ss1#show ip route
Codes: C - connected, S - static, I - IGRP, R - RIP, M - mobile, B - BGP
       D - EIGRP, EX - EIGRP external, O - OSPF, IA - OSPF inter area
       N1 - OSPF NSSA external type 1, N2 - OSPF NSSA external type 2
       E1 - OSPF external type 1, E2 - OSPF external type 2, E - EGP
       i - IS-IS, L1 - IS-IS level-1, L2 - IS-IS level-2, ia - IS-IS inter area
       * - candidate default, U - per-user static route, o - ODR
       P - periodic downloaded static route

Gateway of last resort is not set

          192.168.5.0/24 is variably subnetted, 2 subnets, 2 masks
C       192.168.5.0/30 is directly connected, Serial2/0
C       192.168.5.128/26 is directly connected, FastEthernet0/0

ss1#ss#

AnnaUniversity EC66 Computer Networks Lab - Implementation of Distance Vector Routing Protocol(DVRP) on Router

with 0 Comment
System Bootstrap, Version 12.1(3r)T2, RELEASE SOFTWARE (fc1)
Copyright (c) 2000 by cisco Systems, Inc.
PT 1001 (PTSC2005) processor (revision 0x200) with 60416K/5120K bytes of memory

Self decompressing the image :
########################################################################## [OK]

              Restricted Rights Legend

Use, duplication, or disclosure by the Government is
subject to restrictions as set forth in subparagraph
(c) of the Commercial Computer Software - Restricted
Rights clause at FAR sec. 52.227-19 and subparagraph
(c) (1) (ii) of the Rights in Technical Data and Computer
Software clause at DFARS sec. 252.227-7013.

           cisco Systems, Inc.
           170 West Tasman Drive
           San Jose, California 95134-1706

Cisco Internetwork Operating System Software
IOS (tm) PT1000 Software (PT1000-I-M), Version 12.2(28), RELEASE SOFTWARE (fc5)
Technical Support: http://www.cisco.com/techsupport
Copyright (c) 1986-2005 by cisco Systems, Inc.
Compiled Wed 27-Apr-04 19:01 by miwang

PT 1001 (PTSC2005) processor (revision 0x200) with 60416K/5120K bytes of memory
.
Processor board ID PT0123 (0123)
PT2005 processor: part number 0, mask 01
Bridging software.
X.25 software, Version 3.0.0.
4 FastEthernet/IEEE 802.3 interface(s)
2 Low-speed serial(sync/async) network interface(s)
32K bytes of non-volatile configuration memory.
16384K bytes of processor board System flash (Read/Write)

         --- System Configuration Dialog ---

Continue with configuration dialog? [yes/no]: no

Press RETURN to get started!

Router>enable
Router#config t
Enter configuration commands, one per line.  End with CNTL/Z.
Router(config)#host name ss
                         ^
% Invalid input detected at '^' marker.

Router(config)#hostname ss
ss(config)#interface s2/0
ss(config-if)#ip address 172.17.0.1 255.0.0.0
ss(config-if)#clock rate 64000
ss(config-if)#no shutdown

%LINK-5-CHANGED: Interface Serial2/0, changed state to down
ss(config-if)#exit
ss(config)#interface f0/0
ss(config-if)#ip address 14.0.0.1 255.0.0.0
ss(config-if)#no shutdown

%LINK-5-CHANGED: Interface FastEthernet0/0, changed state to up
%LINEPROTO-5-UPDOWN: Line protocol on Interface FastEthernet0/0, changed state to up
ss(config-if)#exit
ss(config)#router rip
ss(config-router)#network 172.160.0.0
ss(config-router)#exit
ss(config)#exit
%SYS-5-CONFIG_I: Configured from console by console
ss#copy ru st
Destination filename [startup-config]?
Building configuration...
[OK]
ss#

for router 2
System Bootstrap, Version 12.1(3r)T2, RELEASE SOFTWARE (fc1)
Copyright (c) 2000 by cisco Systems, Inc.
PT 1001 (PTSC2005) processor (revision 0x200) with 60416K/5120K bytes of memory

Self decompressing the image :
########################################################################## [OK]

              Restricted Rights Legend

Use, duplication, or disclosure by the Government is
subject to restrictions as set forth in subparagraph
(c) of the Commercial Computer Software - Restricted
Rights clause at FAR sec. 52.227-19 and subparagraph
(c) (1) (ii) of the Rights in Technical Data and Computer
Software clause at DFARS sec. 252.227-7013.

           cisco Systems, Inc.
           170 West Tasman Drive
           San Jose, California 95134-1706

Cisco Internetwork Operating System Software
IOS (tm) PT1000 Software (PT1000-I-M), Version 12.2(28), RELEASE SOFTWARE (fc5)
Technical Support: http://www.cisco.com/techsupport
Copyright (c) 1986-2005 by cisco Systems, Inc.
Compiled Wed 27-Apr-04 19:01 by miwang

PT 1001 (PTSC2005) processor (revision 0x200) with 60416K/5120K bytes of memory
.
Processor board ID PT0123 (0123)
PT2005 processor: part number 0, mask 01
Bridging software.
X.25 software, Version 3.0.0.
4 FastEthernet/IEEE 802.3 interface(s)
2 Low-speed serial(sync/async) network interface(s)
32K bytes of non-volatile configuration memory.
16384K bytes of processor board System flash (Read/Write)

         --- System Configuration Dialog ---

Continue with configuration dialog? [yes/no]: no

Press RETURN to get started!

Router>enable
Router#config t
Enter configuration commands, one per line.  End with CNTL/Z.
Router(config)#host name ss
                         ^
% Invalid input detected at '^' marker.

Router(config)#hostname ss
sss(config)#interface s2/0
sss(config-if)#ip address 172.17.0.1 255.0.0.0
sss(config-if)#clock rate 64000
sss(config-if)#no shutdown

%LINK-5-CHANGED: Interface Serial2/0, changed state to down
sss(config-if)#exit
sss(config)#interface f0/0
sss(config-if)#ip address 14.0.0.1 255.0.0.0
sss(config-if)#no shutdown

%LINK-5-CHANGED: Interface FastEthernet0/0, changed state to up
%LINEPROTO-5-UPDOWN: Line protocol on Interface FastEthernet0/0, changed state to up
sss(config-if)#exit
sss(config)#router rip
sss(config-router)#network 172.160.0.0
sss(config-router)#exit
sss(config)#exit
%SYS-5-CONFIG_I: Configured from console by console
ss#copy ru st
Destination filename [startup-config]?
Building configuration...
[OK]
ss#

AnnaUniversity EC66 Computer Networks Lab - C Program to Compute Utilization of Token Ring Protocol for Normal Token Release(NTR) and Early Token Release(ETR)

with 0 Comment
Study and Implementation of Token Ring Protocol:

#include<stdio.h>
#include<conio.h>
#include<stdlib.h>
#include<math.h>
#define v 2.0e8
void main(void)
{
char instring[80];
double d,r,a,u;
long int l,n,releasetype;
clrscr();
printf("....................");
printf("\n Program to Compute Utiliation of Token Ring Protocol\n");
printf("\n.....................\n");
printf("\n Length of the link in m:");
scanf("%s",instring);
d=atof(instring);
printf("\n Data rate of the link in bits per sec");
scanf("%s",instring);
r=atof(instring);
printf("\n Size of frame in byte:");
scanf("%s",instring);
l=8*atoi(instring);
printf("\n no of stations");
scanf("%s",instring);
n=atoi(instring);
printf("token ring release type1=ntr,type2=etr");
printf("\n Enter the value for ntr,etr");
scanf("%s",instring);
releasetype=atoi(instring);
a=((double)r*d)/((double)v*l);
if(releasetype==1);
{
printf("Normal token release");
if(a<=1.0)
u=1.0/(1.0+(a/n));
else
u=1.0/(a*(1.0+(a/n)));
}
if(releasetype==2)
{
printf("Early token release");
u=1.0/(1.0+(a/n));
}
printf(".........a=%f\n",a);
printf(".........u=%f%f\n",100.00*u);
printf(".............");
getch();
}

OUTPUT:

a<1 :

a>1:

AnnaUniversity EC66 Computer Networks Lab - C Program to Calculate the Link Utilization for Selective Repeat or Selective Reject ARQ Protocol

with 0 Comment
C Program to Calculate the Link Utilization for Selective Repeat or Selective Reject ARQ Protocol:

#include<stdio.h>
#include<conio.h>
#include<stdlib.h>
#include<math.h>
#define v 2.0e8
void main(void)
{
char instring[80];
double d,r,pr,p,a,u;
long int l,n;
clrscr();
printf("....................");
printf("\n Program to Compute Utiliation of Selective Repeat N ARQ protocol\n");
printf("\n.....................\n");
printf("\n Length of the link in m:");
scanf("%s",instring);
d=atof(instring);
printf("\n Data rate of the link in bits per sec");
scanf("%s",instring);
r=atof(instring);
printf("\n Size of frame in byte:");
scanf("%s",instring);
l=8*atoi(instring);
printf("\n pr[biterror](0.0to1.0):");
scanf("%s",instring);
pr=atof(instring);
printf("\n size of window");
scanf("%s",instring);
n=atoi(instring);
p=1-pow((1-pr),(double)l);
a=((double)(r*d))/((double)v*l);
if(n>=((2*a)+1))
u=(1-p);
else
u=(n*(1-p))/(1+(2*a));
printf("\n.................\n");
printf("\n Protocol is Selective Repeat or Selective Reject N ARQ\n");
printf("\n......a=%f.....\n",a);
printf("\n......pr[frameloss]=%f......\n",p);
printf("\n......u=%f.......\n",100.0*u);
printf("\n.................\n");
getch();
}

OUTPUT:


AnnaUniversity EC66 Computer Networks Lab - C Program to Calculate the Link Utilization for GO BACK N ARQ Protocol

with 0 Comment
C Program to Calculate the Link Utilization for GO BACK N ARQ Protocol:

#include<stdio.h>
#include<conio.h>
#include<stdlib.h>
#include<math.h>
#define v 2.0e8
void main(void)
{
char instring[80];
double d,r,pr,p,a,u;
long int l,n;
clrscr();
printf("....................");
printf("\n Program to Compute Utiliation of GO BACK N ARQ Protocol\n");
printf("\n.....................\n");
printf("\n Length of the link in m:");
scanf("%s",instring);
d=atof(instring);
printf("\n Data rate of the link in bits per sec");
scanf("%s",instring);
r=atof(instring);
printf("\n Size of frame in byte:");
scanf("%s",instring);
l=8*atoi(instring);
printf("\n pr[biterror](0.0to1.0):");
scanf("%s",instring);
pr=atof(instring);
printf("\n size of window");
scanf("%s",instring);
n=atoi(instring);
p=1-pow((1-pr),(double)l);
a=((double)(r*d)/((double)v*l));
if(n>=((2*a)+1))
u=(1-p)/(1+(2*a*p));
else
u=(n*(1-p))/(((2*a)+1)*(1-p+n*p));
printf("\n.................\n");
printf("\n Protocol is Sliding Window GO BACK N ARQ\n");
printf("\n......a=%f.....\n",a);
printf("\n......pr[frameloss]=%f......\n",p);
printf("\n......u=%f.......\n",100.0*u);
printf("\n.................\n");
getch();
}

OUTPUT:


AnnaUniversity EC66 Computer Networks Lab - C Program to Calculate the Link Utilization for Stop and Wait ARQ Protocol

with 0 Comment
C Program to Calculate the Link Utilization for Stop and Wait ARQ Protocol:

#include<stdio.h>
#include<conio.h>
#include<stdlib.h>
#include<math.h>
#define v 2.0e8
void main(void)
{
char instring[80];
double d,r,pr,p,a,u,u1;
long int l;
clrscr();
printf("....................");
printf("\n Program to Compute Utiliation of Stop and Wait Protocol\n");
printf("\n.....................\n");
printf("\n Length of the link in m:");
scanf("%s",instring);
d=atof(instring);
printf("\n Data rate of the link in bits per sec");
scanf("%s",instring);
r=atof(instring);
printf("\n Size of frame in byte:");
scanf("%s",instring);
l=8*atoi(instring);
printf("\n pr[biterror](0.0to1.0):");
scanf("%s",instring);
pr=atof(instring);
p=1-pow((1-pr),(double)l);
a=((double)r*d)/((double)v*l);
u=(1-p)/(1+(2*a));
u1=(1)/(1+(2*a));
printf("\n...................\n");
printf("\n.....Protocol is Stop and Wait....\n");
printf("......a=%f.........\n",a);
printf("......pr[frameloss]=%f....\n",p);
printf(".....Utilisation Factor with Error=%f....\n",100.0*u);
printf(".....Utilisation Factor without Error=%f....\n",100.0*u1);
printf("................\n");
getch();
}

OUTPUT:


AnnaUniversity EC66 Computer Networks Lab - PC to PC Serial Communication

with 0 Comment
PC to PC Serial Communication:

#include <bios.h>
#include <conio.h>

#define COM1       0
#define DATA_READY 0x100
#define TRUE       1
#define FALSE      0

#define SETTINGS ( 0x80 | 0x02 | 0x00 | 0x00)

int main(void)
{
   int in, out, status, DONE = FALSE;

   bioscom(0, SETTINGS, COM1);
   cprintf("... BIOSCOM [ESC] to exit ...\n");
   while (!DONE)
   {
      status = bioscom(3, 0, COM1);
      if (status & DATA_READY)
         if ((out = bioscom(2, 0, COM1) & 0x7F) != 0)
            putch(out);
         if (kbhit())
         {
            if ((in = getch()) == '\x1B')
               DONE = TRUE;
            bioscom(1, in, COM1);
         }
   }
   return 0;
}

Matlab Program to Perform Time Shifting

with 0 Comment
Matlab Program to Perform Time Shifting:     
                      
clc
clear all
disp('x(n) Sequence');
x=[1 2 1 2];
disp(x);
y=circshift(x,[0 1]);
disp('Time shifted x(n) seq');
disp(y);
z=fft(y);
disp('FFT of Time shifted x(n) seq');
disp(z);
s=fft(x);
disp('FFT of x(n)');
disp(s);
N=4;
k=0:1:N-1;
p=exp(-j*2*pi*1*k/N);
x2(k+1)=p;
t=s.*x2;
disp('x(n).x2=');
disp(t);

Output:

Matlab Program to Perform Parseval's Theorem

with 0 Comment
Matlab Program to Perform Parseval's Theorem:     

clc
clear;
disp('xn sequence')
xn=[4 3 2 1]
disp('yn sequence')
yn=[1 2 3 4]
N=4;
n=0:1:N-1;
s=xn.*yn;
t=sum(s);
disp('sum(xn.yn)');
disp(t);
h=fft(t);
disp('fft of t');
disp(h);
x=fft(xn);
y=fft(yn);
s=conj(y);
T=x.*s;
Z=sum(T)
u=Z/N;
disp('Sum(x*k.y*k)/N=')
disp(u);

Output:          
                                        

Matlab Program to Perform Frequency Shifting

with 0 Comment
Matlab Program to Perform Frequency Shifting:
                     
clc
clear
disp('x(n) seq');
x=[1 2 1 2];
disp(x);
z=fft(x);
disp('fft of x(n)');
disp(z);
N=4;
n=0:1:N-1;
p=exp(j*2*pi*n/N);
x2(n+1)=p;
t=x.*x2;
disp('x(n)-x2=');
disp(t);
s=fft(t);
disp('fft of x(n)=');
disp(s);
y=circshift(z,[0 1]);
disp('Freq Shift x(n) seq');
disp(y);


Output:

Matlab Program for Finite Impulse Response(FIR) Filter Design

with 0 Comment
Matlab Program for Finite Impulse Response(FIR) Filter Design:

clc;
close all;
clear all;
n = input('enter the order of filter :');
wc = input('enter the cut off frequency:');
ws=input('enter the sampling frequency:');
disp('1 for low pass');disp('2 for high pass');disp('3 for bandpass');disp('4 for bandstop');
disp('enter the filter type');
filtertype=input('filter type');
switch (filtertype)
    case 1
        ft ='low';
    case 2
        ft='high';
    case 3
        ft='pass';
    case 4
        ft='stop';
    otherwise
        disp('error');
end
disp('1 for rectwin');disp('2 for hamming');disp('3 for hanning');disp('4 for blackman');
disp('enter the window type');
windowtype=input('window type');
switch (windowtype)
    case 1
        wt=rectwin(n+1);
    case 2
        wt=hamming(n+1);
    case 3
        wt=hanning(n+1);
    case 4
        wt=blackman(n+1);
  
 otherwise
        disp('error');
end
figure(1)
b = fir1(n,wc/ws,ft,wt);
freqz(b,1,ws);
n=linspace(0,1,ws);
f1=input('enter the passband frequency:');
f2=input('enter the stopband frenquency:');
x=sin(2*pi*f1*n)+sin(2*pi*f2*n);
xk=fft(x);
figure(2)
subplot(2,2,1);stem(abs(xk));title('spectrum of input signal');xlabel('k');yalabel('X(K)');
y=filter(b,1,x);
yk=fft(y);
subplot(2,2,2);stem(abs(yk));title('spectrum of filtered output signal');xlabel('k');yalabel('y(K) ');
  
OUTPUT:

LOW PASS FILTER:

enter the order of filter :50
enter the cut off frequency:2000
enter the sampling frequency:8000
1 for low pass
2 for high pass
3 for bandpass
4 for bandstop
enter the filter type
filter type1
1 for rectwin
2 for hamming
3 for hanning
4 for blackman
enter the window type
window type1
enter the passband frequency:1200
enter the stopband frenquency:2400 
    
HIGH PASS FILTER:

enter the order of filter :50
enter the cut off frequency:2000
enter the sampling frequency:8000
1 for low pass
2 for high pass
3 for bandpass
4 for bandstop
enter the filter type
filter type2
1 for rectwin
2 for hamming
3 for hanning
4 for blackman
enter the window type
window type2
enter the passband frequency:1300
enter the stopband frenquency:2500
                                                                           
BAND PASS FILTER:

 enter the order of filter :50
enter the cut off frequency:[1500 3000]
enter the sampling frequency:8000
1 for low pass
2 for high pass
3 for bandpass
4 for bandstop
enter the filter type
filter type3
1 for rectwin
2 for hamming
3 for hanning
4 for blackman
enter the window type
window type3
enter the passband frequency:2000
enter the stopband frenquency:3500

BAND STOP FILTER:

enter the order of filter :50
enter the cut off frequency:[1500 3000]
enter the sampling frequency:8000
1 for low pass
2 for high pass
3 for bandpass
4 for bandstop
enter the filter type
filter type4
1 for rectwin
2 for hamming
3 for hanning
4 for blackman
enter the window type
window type4
enter the passband frequency:2000
enter the stopband frenquency:3500
              
Powered by Blogger.

Blog Archive