Saturday, February 24, 2024

17. Given two ordered arrays of integers, write a program to merge the two-arrays to get an ordered array.

 #include <stdio.h>

int main()

{

    int n1,n2,n3;            

    int a[20], b[20], c[40];

    printf("Enter the size of first array: ");

    scanf("%d",&n1);

    printf("Enter the array elements: ");

    for(int i = 0; i < n1; i++)      

       scanf("%d", &a[i]);

    printf("Enter the size of second array: ");

    scanf("%d",&n2);

    printf("Enter the array elements: ");

    for(int i = 0; i < n2; i++)      

       scanf("%d", &b[i]);

    n3 = n1 + n2;

    int i = 0, j = 0, k = 0;


    while (i < n1 && j < n2)    

    {

        if (a[i] < b[j])

            c[k++] = a[i++];    

        else

            c[k++] = b[j++];

    }

  

    while (i < n1)    

        c[k++] = a[i++];

  

    while (j < n2)    

        c[k++] = b[j++];

    

    printf("Final array after merging: ");

    for(int i = 0; i < n3 ; i++)       

        printf(" %d ",c[i]);

    return 0;   

}

15. Write a program to find sum of n elements entered by the user. To write this program, allocate memory dynamically using malloc() / calloc() functions or new operator.

 #include <stdio.h>

#include <stdlib.h>


int main()

{

    int* ptr; 

    int limit; 

    int i; 

    int sum; 


    printf("Enter limit of the array: ");

    scanf("%d", &limit);

    ptr = (int*)malloc(limit * sizeof(int));


      for (i = 0; i < limit; i++) {

        printf("Enter element %02d: ", i + 1);

        scanf("%d", (ptr + i));

    }

    

    printf("\nEntered array elements are:\n");

    for (i = 0; i < limit; i++) {

        printf("%d\n", *(ptr + i));

    }

    sum = 0; //assign 0 to replace garbage value

    for (i = 0; i < limit; i++) {

        sum += *(ptr + i);

    }

    printf("Sum of array elements is: %d\n", sum);

        free(ptr); 

    return 0;

}

14. Write a program which takes the radius of a circle as input from the user, passes it to another function that computes the area and the circumference of the circle and displays the value of area and circumference from the main() function.

 #include<stdio.h>

const float PI = 3.1415927;

float area(float radius);

float circum(float radius);

void main() {

 float radius;


 printf("Enter radius: ");

 scanf("%f", &radius);

 printf("Area : %.3f\n", area(radius));

 printf("Circumference: %.3f\n", circum(radius));


}


float area(float radius) {

  return PI * radius * radius;

}


float circum(float radius) {

  return 2 * PI * radius;

}


12. Write a program that swaps two numbers using pointers.

 #include <stdio.h>


void swap(int *a, int *b) {

    int temp;

    temp = *a;

    *a = *b;

    *b = temp;

}


int main() {

    int num1, num2;

    int *ptr1, *ptr2;

    printf("Enter two numbers:\n");

    scanf("%d%d", &num1, &num2);

    ptr1 = &num1;

    ptr2 = &num2;

    printf("before swapping:\n");

    printf("Number 1 = %d\n", num1);

    printf("Number 2 = %d\n", num2);

    swap(ptr1, ptr2);

    printf("After swapping:\n");

    printf("Number 1 = %d\n", num1);

    printf("Number 2 = %d\n", num2);


    return 0;

}

8. Write a macro that swaps two numbers. WAP to use it.

 #include <stdio.h>


#define SWAP(x, y) (x ^= y ^= x ^= y)


int main()

{

    int num1, num2;


    

    printf("Enter any two number to swap: ");

    scanf("%d%d", &num1, &num2);


    printf("Values before swapping\n");

    printf("num1 = %d, num2 = %d\n\n", num1, num2);


    SWAP(num1, num2);


    printf("Values after swapping\n");

    printf("num1 = %d, num2 = %d\n", num1, num2);


    return 0;

}

7.WAP to compute the factors of a given number.

 #include <stdio.h> 


int main() 

int num, i;

    printf("Enter a positive integer: ");

    scanf("%d", &num);

    printf("Factors of %d are: ", num);

    for (i = 1; i <= num; ++i) {

        if (num % i == 0) {

            printf("%d ", i);

        }

    }

return 0;

}


6. Write a function to find whether a given no. is prime or not. Use the same to generate the prime numbers less than 100.

 #include <stdio.h> 

int checkPrime(int N) 

int flag = 1; 

for (int i = 2; i <= N / 2; i++) { 

if (N % i == 0) { 

flag = 0; 

break; 

return flag ; 



int main() 

for(int i=1;i<=100;i++)

if(checkPrime(i)&&i!=1)

    printf("%d ",i);


return 0;

}


Friday, February 23, 2024

5. Write a function that checks whether a given string is Palindrome or not. Use this function to find whether the string entered by user is Palindrome or not.

 #include <stdio.h>

#include <string.h>



void Lower_case(char str[]) {

    int i = 0;

    while (str[i] != '\0') {

        if (str[i] > 64 && str[i] < 91) 

            str[i] += 32; 


        i++; 

    } 


void CheckPalindrome(char str[]) 


    

    int left = 0; 

    int right = strlen(str) - 1; 


    while (right > left) 

    {

        if (str[left++] != str[right--]) {

            printf("The String %s is not a palindrome", str);

            return;

        }

    }

    printf("The String %s is palindrome", str);

}

int main() 

{

    char str1[50];

    printf("enter a string");

    gets(str1);

    Lower_case(str1);

    CheckPalindrome(str1);

    

    return 0;

}

4. WAP to compute the sum of the first n terms of the following series S =1-2+3-4+5…………….

 #include <stdio.h>


int main()

{

    int n;

    int sum=0,i;

    printf("Enter the range of number:");

    scanf("%d",&n);


    for(i=1;i<=n;i++)

    {

        if(i%2==0)

            sum-=i;

        else

            sum+=i;

    }


    printf("The sum of the series = %d",sum);

    return 0;

}


3. WAP to compute the sum of the first n terms of the following series S = 1+1/2+1/3+1/4+……

 #include <stdio.h>


int main()

{

    double number, sum = 0, i;

 

    printf("\n enter the number ");

    scanf("%lf", &number);

    for (i = 1; i <= number; i++)

    {

        sum = sum + (1 / i);

        if (i == 1)

            printf("\n 1 +");

        else if (i == number)

            printf(" (1 / %lf)", i);

        else

            printf(" (1 / %lf) + ", i);

    }

    printf("\n The sum of the given series is %.2lf", sum);


    return 0;

}


2. WAP to reverse a number.

 #include <stdio.h>


int main()

{

    int n, reverse = 0, remainder;


  printf("Enter an integer: ");

  scanf("%d", &n);


  while (n != 0) {

    remainder = n % 10;

    reverse = reverse * 10 + remainder;

    n /= 10;

  }


  printf("Reversed number = %d", reverse);


    return 0;

}


1. WAP to print the sum and product of digits of an integer.

 #include <stdio.h>


int main()

{

    int n;

    int dig, sum,pro;

     

    printf("\nEnter an integer number :");

    scanf("%d",&n);

  

    /*Calculating Sum and Product*/

    sum=0;

    pro=1;

     

    while(n>0)

    {

        dig=n%10; /*get digit*/

        sum+=dig;

        pro*=dig;

        n=n/10;

    }

     

    printf("\nSUM of all Digits is : %d",sum);

    printf("\nPRODUCT of all digits: %d",pro);

    return 0;

}


WEST BENGAL STATE UNIVERSITY computer science NEP Syllabus

 WEST BENGAL STATE UNIVERSITY computer sciecne NEP Syllabus 


SEMESTER 2 computer sciecne NEP Syllabus 



COMJPUTER SCIECNE NEP SYLLABUS WBSU SEM2
MAJOR THEORYData Structures using C++ CLICK HERE
MAJOR PRACTICALData Structures using C++ CLICK HERE
SECPython ProgrammingCLICK HERE
MDC

WEST BENGAL STATE UNIVERSITY NEP Syllabus for B.Sc. Computer Science Major, Minor and Interdisciplinary

CMSACOR02T: Data Structures using C++ 
Theory: 45 Lectures

 Introduction (5 Lectures) 
Data Object, Abstract Data Type, Data Structures and Data Types. Types of Data Structures – Linear and non-linear Data Structures.Single and Multi-dimensional Arrays, Address Calculations, Sparse Matrices (Array Representation). 

Linked Lists (7 Lectures) 
Singly, Doubly and Circular Lists (Array and Linked representation); Operations on Lists. Sparse Matrices (Linked Representation). 

Stacks and Queues (9 Lectures) 
Implementing single / multiple stack/s in an Array; Prefix, Infix and Postfix expressions, Utility and conversion of these expressions from one to another; Applications of stack; Limitations of Array representation of stack. Array and Linked representation of Queue, De-queue, Priority Queues

 Recursion (5 lectures)
Developing Recursive Definition of Simple Problems and their implementation; Advantages and Limitations of Recursion; Understanding what goes behind Recursion (Internal Stack Implementation)

 Binary Trees (10 Lectures) 
Introduction; Properties, Binary Trees Traversals (Recursive and Non-Recursive), Binary Search Trees (Insertion, Deletion), Recursive and Iterative Traversals on Binary Search Trees; Threaded Binary Trees (Concept only); Height-Balanced Trees (Concept only). Searching, 

Sorting and Hashing (9 Lectures)
Linear Search, Binary Search, Comparison of Linear and Binary Search, Selection Sort, Insertion Sort, Bubble Sort, Comparison of Sorting Techniques. Introduction to Hashing, Resolving collusion by Open Addressing, Coalesced Hashing, Separate Chaining and simple examples.

WEST BENGAL STATE UNIVERSITY computer science NEP Syllabus

 SEMESTER 1

WEST BENGAL STATE UNIVERSITY computer sciecne NEP Syllabus 


SEMESTER 1 computer sciecne NEP Syllabus 



COMJPUTER SCIECNE NEP SYLLABUS WBSU SEM1
MAJOR THEORYComputer Fundamentals and programming with CCLICK HERE
MAJOR PRACTICALComputer Fundamentals and programming with CCLICK HERE
SECR ProgrammingCLICK HERE
MDCComputer Fundamentals

Wednesday, February 21, 2024

WAP to calculate GCD of 2 number (i) with recursion (ii) without recursion

 #include <iostream>

using namespace std;


class cl

{

private:

int n1,n2;

public:

void input()

{

cout<<"\nEnter 2 nunbers: ";

cin>>n1>>n2;

}

void gcd()


{

int g;

for(int i=1;i<=n1 && i<=n2;i++)

{

if(n1%i==0 && n2%i==0)

g=i;

}

cout<<"GCD= "<<g;

}

int gcd(int a, int b)

{

// Everything divides 0

if (a == 0)

return b;

if (b == 0)

return a;


// base case

if (a == b)

return a;


// a is greater

if (a > b)

return gcd(a-b, b);

return gcd(a, b-a);

}

};

int main()

{

cl ob;

int ch,m,n;



do

{

    cout<<"**GCD of 2 numbers**\n\n1.using Recursion \n2. Not using Recursion\n3.Exit";

cout<<"\n\nEnter ur Choice: ";

cin>>ch;

switch(ch)

{

case 1:

cout<<"\nEnter 2 numbers: ";

cin>>m>>n;

cout<<"GCD= "<<ob.gcd(m,n);

break;


case 2:

ob.input();

ob.gcd();

break;


case 3:

cout<<"\nEXIT";

break;


default:

cout<<"\nSorry! Invalid Choice";

}

}

while(ch!=3);

return 0;

}

WAP to display Fibonacci series (i)using recursion, (ii) using iteration

 #include<iostream>

using namespace std;


class cl

{


public:

int a=0,b=1,l;

void input()

{


cout<<"\nEnter the Length of Fibonacci series: ";

cin>>l;

}

void fib()

{


for(int i=0;i<l;i++)

{

int c=a+b;

cout<<" "<<a;

a=b;

b=c;

}

}

int fib(int x)

{

if((x==1)||(x==0))

{

return(x);

}

else

{

return(fib(x-1)+fib(x-2));

}

}

};

int main()

{

cl ob;

int ch,n,i=0;



do

{

  cout<<"\nFibonacci series \n\n1.using Iteration \n2.using Recursion\n3.Exit";  

cout<<"\nEnter ur Choice: ";

cin>>ch;

switch(ch)

{

case 1:

ob.input();

ob.fib();

break;


case 2:

ob.input();

cout << "\nFibonnaci Series : ";

i=0;

while(i<ob.l)

{

cout << " "<<ob.fib(i);

i++;

}

break;


case 3:

cout<<"\nEXIT";

break;


default:

cout<<"\nSorry! Invalid Choice";

}

}

while(ch!=3);


return 0;

}

WAP to implement Diagonal Matrix using one-dimensional array.

 // C++ Program to print the Diagonals of a Matrix


#include <bits/stdc++.h>

using namespace std;

#define MAX 20




// Function to print the Principal Diagonal

void printPrincipalDiagonal(int mat[][MAX], int n)

{

cout << "Principal Diagonal: ";


for (int i = 0; i < n; i++) {

for (int j = 0; j < n; j++) {


// Condition for principal diagonal

if (i == j)

cout << mat[i][j] << ", ";

}

}

cout << endl;

}


// Function to print the Secondary Diagonal

void printSecondaryDiagonal(int mat[][MAX], int n)

{

cout << "Secondary Diagonal: ";


for (int i = 0; i < n; i++) {

for (int j = 0; j < n; j++) {


// Condition for secondary diagonal

if ((i + j) == (n - 1))

cout << mat[i][j] << ", ";

}

}

cout << endl;

}


// Driver code

int main()

{

int n ;

int a[20][20]; 

cin>>n;

cout<<"enter eleents";

for (int i = 0; i < n; i++) {

for (int j = 0; j < n; j++) {


cin>> a[i][j] ;

}

}


printPrincipalDiagonal(a, n);

printSecondaryDiagonal(a, n);

return 0;

}


WAP to reverse the order of the elements in the stack using additional Queue.

 #include<stdio.h> 

#include<stdlib.h> 


#define MAX_SIZE 100


struct Queue

{

  int items[MAX_SIZE];

  int front;

  int rear;

};


struct Stack

{

  int items[MAX_SIZE];

  int top;

};


void enqueue (struct Queue *q, int item)

{

  if (q->rear == MAX_SIZE - 1)

    {

      printf ("Queue overflow\n");

      return;

    }


  if (q->front == -1)

    {

      q->front = 0;

    }


  q->rear++;

  q->items[q->rear] = item;

}


int dequeue (struct Queue *q)

{

  if (q->front == -1)

    {

      printf ("Queue underflow\n");

      return -1;

    }


  int item = q->items[q->front];

  q->front++;


  if (q->front > q->rear)

    {

      q->front = q->rear = -1;

    }


  return item;

}


void display (struct Queue *q)

{

  if (q->rear == -1)

    {

      printf ("Queue is empty\n");

      return;

    }


  for (int i = q->front; i <= q->rear; i++)

    {

      printf ("%d ", q->items[i]);

    }

  printf ("\n");

}


void push (struct Stack *s, int item)

{

  if (s->top == MAX_SIZE - 1)

    {

      printf ("Stack overflow\n");

      return;

    }


  s->top++;

  s->items[s->top] = item;

}


int pop (struct Stack *s)

{

  if (s->top == -1)

    {

      printf ("Stack underflow\n");

      return -1;

    }


  int item = s->items[s->top];

  s->top--;


  return item;

}


int main ()

{

  struct Queue q;

  q.front = -1;

  q.rear = -1;


  struct Stack s;

  s.top = -1;


  enqueue (&q, 1);

  enqueue (&q, 2);

  enqueue (&q, 3);

  enqueue (&q, 4);


  printf ("Queue before reversing:\n");

  display (&q);


  while (q.front != -1)

    {

      push (&s, dequeue (&q));

    }


  while (s.top != -1)

    {

      enqueue (&q, pop (&s));

    }


  printf ("Queue after reversing:\n");

  display (&q);


  return 0;

}

WAP to reverse the order of the elements in the stack using additional stack

 #include <stdio.h>  

 #define MAXSIZE 10  


 struct Stack {  

    int top;  

    int array[MAXSIZE];  

} st;  

  


 void initialize() {  

 st.top = -1;  

}  


int isFull() {     

    if(st.top >= MAXSIZE-1)  

        return 1;  

    else  

        return 0;  

}  

  

int isEmpty() {  

 if(st.top == -1)  

     return 1;  

 else  

     return 0;  

}  

   


void push(int num) {  

    if (isFull())  

        printf("Stack is Full...\n");  

    else {  

        st.array[st.top + 1] = num;  

        st.top++;  

    }  

}  

   


int pop() {  

    if (isEmpty())  

        printf("Stack is Empty...\n");  

    else {  

     st.top = st.top - 1;  

        return st.array[st.top+1];  

    }  

}  

   


void printStack(){  


 if(!isEmpty())  

{  

     int temp = pop();  

     printStack();  

     printf(" %d ", temp);  

     push(temp);  

    }  

}  


void insertAtBottom(int item) {  

    if (isEmpty()) {  

        push(item);  

    } else {  

       int top = pop();  

        insertAtBottom(item);  

        push(top);  

    }  

}  

 

void reverse() {  

    if (!isEmpty()) {  

         int top = pop();  

        reverse();  

        insertAtBottom(top);  

    }  

}  

  

int getSize(){  

 return st.top+1;  

}  


 int main() {  

 initialize(st);    

  push(1);     

    push(2);    

    push(3);  

    push(4);      

    push(5);    

    printf("Original Stack\n");  

    printStack();  

    reverse();  

    printf("\nReversed Stack\n");  

    printStack();  

    return 0;  

}  

Find out whether a list is a palindrome.

 

Find out whether a list is a palindrome.

my_reverse(L1,L2) :- my_rev(L1,L2,[]).


my_rev([],L2,L2) :- !.

my_rev([X|Xs],L2,Acc) :- my_rev(Xs,L2,[X|Acc]).

is_palindrome(L) :- reverse(L,L).

Reverse a list.

 

Reverse a list.

my_reverse(L1,L2) :- my_rev(L1,L2,[]).


my_rev([],L2,L2) :- !.

my_rev([X|Xs],L2,Acc) :- my_rev(Xs,L2,[X|Acc]).



Find the number of elements of a list.

 

Find the number of elements of a list.

my_length([],0).

my_length([_|L],N) :- my_length(L,N1), N is N1 + 1.

Find the K'th element of a list in prolog

 

Find the K'th element of a list in prolog

element_at(X,[X|_],1).

element_at(X,[_|L],K) :- K > 1, K1 is K - 1, element_at(X,L,K1).


Find the last element of a lis in prolog

 Find the last element of a list in prolog

my_last(X,[X]).

my_last(X,[_|L]) :- my_last(X,L).


Determining if a term is a list.

 Determining if a term is a list.


list([]).
list([X|Xs]) :- list(Xs).



?- list([a,b,c]).

yes

?- list(abc).

no

LIST PROGRAM IN LIST

 


Determining if a term is a list.  click

 Find the last element of a list in prolog  click

Find the K'th element of a list in prolog click

Find the number of elements of a list.

Reverse a list.

Find out whether a list is a palindrome.


prolog 1

 Permutation:



insert(X,L,[X|L]).


insert(X,[H|T],[H|U]) :-

  insert(X,T,U).




permute([],[]).


permute([H|T],L) :-

  permute(T,U),

  insert(H,U,L).

Sunday, February 18, 2024

basic command

 

ADDITION:

set x 5

set y 10

expr $x + $y

set z [ expr $x + $y]

puts "sum=$z"

output:

15

sum=15


LOOP:

set i 0

while{$i <10}{

puts $i

set i [ expr $i + 1]

}


ORIENTATION

 The optional orientation values may be defined in degrees or by text like :



                                                                        right (0)



                                                                       right-up (45)

                                                            right-down (-45),

 left (180), left-up (135), left-down (-135), up (90), down (-90).

Wednesday, February 14, 2024

NS2

 

Introduction  click

BASIC COMMAND-

NODE CREATE  CLICK

TCP CLICK

UDP  CLICK

4.Packet tracing: 

DUPLEX LINK CLICK

 QUEUER TYPE -CLICK

LARGE TOPOLOGY USING LOOP CLICK

DIFFERENT COLOR NODE:   CLICK

TOPOLOGY  CLICK

ORIENTATION -CLICK


QUEUE TYPE

 

Queue Management is defined as the algorithm that manages the length of the packet queues by dropping packets when necessary. 

Passive Queue Management: In Passive Queue Management the packet drop occurs only when the buffer gets full. Ex: Drop Tail.
Active Queue Management: Active Queue Management employs preventive packet drops. It provides an implicit feedback mechanism to notify senders of the onset of congestion. Arriving packets are randomly dropped. Ex: RED.



Droptail: In Droptail, the router accepts and forwards all the packets that arrive as long as its buffer space is available for the incoming packets. If a packet arrives and the queue is full, the incoming packet will be dropped. The sender eventually detects the packet lost and shrinks its sending window. Drop-tail queues have a tendency to penalize bursty flows, and to cause global synchronization between flows.

RED: RED is a type of active queue management technique used for congestion avoidance. RED monitors the average queue size and drops (or marks when used in conjunction with ECN) packets based on statistical probabilities. If the buffer is almost empty, all incoming packets are accepted. As the queue grows, the probability for dropping an incoming packet grows too. When the buffer is full, the probability has reached 1 and all incoming packets are dropped


REM: REM is an active queue management scheme that measures congestion not by performance measure such as loss or delay, but by quantity. REM can achieve high utilization, small queue length, and low buffer overflow probability. Many works have used control theory to provide the stable condition of REM without considering the feedback delay. In case of (Random Exponential Marking) REM, the key idea is to decouple congestion measure from performance measure (loss, queue length or delay).

Fair Queuing In fair queuing every flow gets the bandwidth propositional to its demand. The main goal of fair queuing is to allocate resources fairly to keep separate queue for each flow currently flowing via a router. Every queue gets equal bandwidth when the packets are in same size and non-empty queue follows a round robin fashion like FIFO. But if the packets are in different size the flow of large size packets gets more bandwidth than small size packets and these problems are overcome by weighted fair queuing algorithm, etc. Maintaining a separate queue for each flow requires a gateway or router to map from source to destination address pair for the related queue on a per packet basis. 


Stochastic Fair Queuing Stochastic Fair Queuing uses a hash algorithm to divide the traffic over a limited number of queues. Due to the hashing in SFQ multiple sessions might end up into the same bucket. SFQ changes its hashing algorithm so that any two colliding sessions will only work for a small number of seconds. Stochastic Fair Queuing algorithm is the best algorithm among all algorithms in case of providing satisfactory bandwidth to the legitimate users (TCP and UDP) in network. It is called Stochastic due to the reason that it does not actually assign a queue for every session; it has an algorithm which divides traffic over a restricted number of queues using a hashing algorithm.SFQ assigns a pretty large number of FIFO queues. Stochastic Fair Queuing (SFQ) ensures fair access to network resources and prevents a busty flow from consuming more than its fair share.SFQ has a minimum average loss ratio and maximum throughput compared to RED. 

DIFFERENT COLOR NODE

 

Add the following two lines to your CBR agent definitions.

$udp0 set class_ 1
$udp1 set class_ 2


$ns color 1 Blue
$ns color 2 Red

This code allows you to set different colors for each flow id.

Nam snap shot

LARGE TOPOLOGY

 

for {set i 0} {$i < 7} {incr i} {
  set n($i) [$ns node]
}


for {set i 0} {$i < 7} {incr i} {
  $ns duplex-link $n($i) $n([expr ($i+1)%7]) 1Mb 10ms DropTail
}

Nam snap shot

TOPOLOGY

 


set n0 [$ns node]
set n1 [$ns node]
set n2 [$ns node]
set n3 [$ns node]

The following piece of Tcl code creates three duplex links between the nodes.

$ns duplex-link $n0 $n2 1Mb 10ms DropTail
$ns duplex-link $n1 $n2 1Mb 10ms DropTail
$ns duplex-link $n3 $n2 1Mb 10ms DropTail

You can save and start the script now. You might notice that the topology looks a bit awkward in nam. You can hit the 're-layout' button to make it look better, but it would be nice to have some more control over the layout. Add the next three lines to your Tcl script and start it again.

$ns duplex-link-op $n0 $n2 orient right-down      
$ns duplex-link-op $n1 $n2 orient right-up 
$ns duplex-link-op $n2 $n3 orient right 

You will probably understand what this code does when you look at the topology in the nam window now. It should look like the picture below.

Nam snap shot

DUPLEX LINK

 $ns duplex-link node1 node2 bandwidth delay queue-type



set n0 [$ns node]
set n1 [$ns node]

A new node object is created with the command '$ns node'. The above code creates two nodes and assigns them to the handles 'n0' and 'n1'.

The next line connects the two nodes.

$ns duplex-link $n0 $n1 1Mb 10ms DropTail

This line tells the simulator object to connect the nodes n0 and n1 with a duplex link with the bandwidth 1Megabit, a delay of 10ms and a DropTail queue.

NODE CREATION

#Create four nodes
set n0 [$ns node]
set n1 [$ns node]
set n2 [$ns node]
set n3 [$ns node]

$ns color 1 blue: is to set color of the packets for a flow specified by the flow id (fid). 


$n3 shape "square"
$n3 color "black"

$n0 shape "square"
$n0 color "blue"

PACKET TRACING

 




UDP

 #Setup a UDP connection

set udp [new Agent/UDP]
$ns attach-agent $n1 $udp
set null [new Agent/Null]
$ns attach-agent $n3 $null
$ns connect $udp $null
$udp set fid_ 2

#Setup a CBR over UDP connection
set cbr [new Application/Traffic/CBR]
$cbr attach-agent $udp
$cbr set type_ CBR
$cbr set packet_size_ 1000
$cbr set rate_ 1mb
$cbr set random_ false

TCP

1. #Setup a TCP connection(ftp)

set tcp [new Agent/TCP]
$tcp set class_ 3
$ns attach-agent $n0 $tcp
set sink [new Agent/TCPSink]
$ns attach-agent $n3 $sink
$ns connect $tcp $sink
$tcp set fid_ 1

#Setup a FTP over TCP connection
set ftp [new Application/FTP]
$ftp attach-agent $tcp
$ftp set type_ FTP


2.#Setup a TCP connection(cbr)

Introduction to ns2

 1.Network protocol stack written in C++

 2.Tcl (Tool Command Language) used for

specifying scenarios and events.


3. Simulates both wired and wireless networks.


4.Ns, the simulator itself

 5.Nam, the network animator--Nam editor: GUI interface to generate ns scripts


NAM (NETWORK ANIMATOR)

-> PROVIDES A VISUAL INTERPRETATION OF THE NETWORK CREATED

-> CONTROLS PLAY,FAST FORWARD,REWIND,PAUSE

X-GRAPH

->INTERACTIVE PLOTTING,GRAPHING ANIMATED AND DERIVATIVES

->SIZE 800x400




Tuesday, February 13, 2024

21. WAP to implement Symmetric Matrix using one-dimensional array.

 21. WAP to implement Symmetric Matrix using one-dimensional array.


PROGRAME CODE

#include<stdio.h>

#include<iostream>

using namespace std;

class symmetric{

                int arr[50][50],row,col,arr1[50][50],arr2[100];

                public:

                                symmetric(){

                                                row=0;

                                                col=0;

                                }

                                void getdata(){

                                                cout<<"ENTER THE VALUE OF THE ROW ......."<<endl;

                                                cin>>row;

                                                cout<<"ENTER THE VALUE OF THE COLOM ......."<<endl;

                                                cin>>col;

                                                cout<<"ENTER THE ELEMENTS OF THE MATRIX ......."<<endl;

                                                for(int i=0;i<row;i++){

                                                                for(int j=0;j<col;j++)

                                                                                cin>>arr[i][j];

                                                }

                                                if(check())

                                                                cout<<"THE MATRIX IS A SYMMETRIC MATRIX ....."<<endl;

                                                else

                                                                cout<<"THE MATRIX IS A ASYMMETRIC MATRIX....."<<endl;

                                }

                                int check(){

                                                int m=0,n=0,r=0,q=0;

                                                for(int i=0;i<row;i++){

                                                                for(int j=0;j<col;j++)

                                                                                                arr1[j][i]=arr[i][j];

                                                }

                                                for(int k=0;k<row;k++){

                                                                for(int l=0;l<col;l++){

                                                                                if(arr[k][l]!=arr1[k][l])

                                                                                                return 0;

                                                                }

                                                }

                                                return 1;

                                }

                                void dispaly(){

                                                for(int i=0;i<row;i++){

                                                                for(int j=0;j<col;j++)

                                                                                cout<<arr[i][j]<<"  ";

                                                                cout<<endl;

                                                }                                             

                                }

                                void present_sym(){

                                                int k=0;

                                                for(int i=0;i<row;i++){

                                                                for(int j=0;j<col;j++){

                                                                                arr2[k]=arr[i][j];

                                                                                k++;

                                                                }

                                                }

                                                cout<<"THE SYMMETRIC ELEMENTS ARE ->"<<endl;

                                                for(int p=0;p<(row*col);p++)

                                                                cout<<arr2[p]<<"  ";

                                                cout<<endl;

                                }

};

int main(){

                symmetric ob;

                int opt=0;

                do{

                                cout<<"\nPRESS 0 TO EXIT ........"<<endl;

                                cout<<"PRESS 1 TO ENTER DATA ......."<<endl;

                                cout<<"PRESS 2 TO DISPLAY MATRIX ....."<<endl;

                                cout<<"PRESS 3 TO DISPLAY ALL SYMMETRIC ELEMENTS ......"<<endl;

                                cin>>opt;

                                switch(opt){

                                                case 0:

                                                                break;

                                                case 1:

                                                                ob.getdata();

                                                                break;

                                                case 2:

                                                                ob.dispaly();

                                                                break;

                                                case 3:

                                                                ob.present_sym();

                                                                break;

                                                default:

                                                                cout<<"ERROR CHOICE ........."<<endl;

                                }

                }while(opt!=0);

                return 0;

}