answersLogoWhite

0

📱

Computer Programming

A category for questions about computer programming and programming languages.

10,506 Questions

Frame Sorting Program using C?

Frame Sort

Basically the frame are sent from the sender side by assigning a frame id,which could be a number.During the transmission of frames across the link the frames can be transmitted out of order w.r.t the frame id assigned to each of the frame.

The frames need to be in order to maintain integrity.

Even though the frames are sent in order,during the transmission the frames may experience delay or routing or any other event which can shuffle the order.

Thus frame sorting is done at the receiver side at the buffer at the DATA Link layer

before sending it to the higher layers.

The sorting can be done in many sorting techniques like bubble sort,merge sort etc.

Simple framesort code in C#include

#include

#include

#include

struct frame

{

char preamble[5];

char dest[48];

char src[48];

int length;

char data[256];

char crc[32];

int seqno;

};

struct frame f[50];

struct frame temp;

int number;

int i,j;

char inputstring[500];

int datasize=5;

void displayinformation()

{

int k=0;

for(k=0;k<=number;k++)

printf("%s",f[k].data);

printf("\n\n");

}

void read()

{

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

char dest[50],src[50];

printf("\nEnter src address : ");

gets(src);

printf("\nEnter dest address : ");

gets(dest);

printf("\nEnter the information : ");

gets(inputstring);

int inputlength=strlen(inputstring);

i=0;

j=0;

f[i].seqno=0;

strcpy(f[i].src,src);

strcpy(f[i].dest,dest);

while(k<=inputlength)

{

f[i].data[j]=inputstring[k++];

if(++j>=datasize)

{

i++;

f[i].seqno=i;

f[i-1].length=datasize;

strcpy(f[i].src,src);

strcpy(f[i].dest,dest);

j=0;

}

}

f[i].length=strlen(f[i].data);

number=i+1;

if(f[i].length==0)

number--;

}

void displayframes()

{

int j;

printf("\n");

for(j=0;j

{

if(j==0)

{

printf("Seq No\t\tDest\t\t\tSrc\t\t\tData\t\tLength\n");

printf("---------------------------------------------------------------------------------------\n");

}

printf("%d\t\t%s\t\t%s\t\t%s\t\t%d\n",f[j].seqno,f[j].dest,f[j].src,f[j].data,f[j].length);

}

}

void shuffle()

{

int i=0,l,p;

i=number;

while(--i>=0)

{

l=rand()%number;

p=rand()%number;

temp=f[l];

f[l]=f[p];

f[p]=temp;

}

}

void bubblesortframes()

{

for(i=0;i

{

for(j=0;j

{

if(f[j].seqno>f[j+1].seqno)

{

temp=f[j];

f[j]=f[j+1];

f[j+1]=temp;

}

}

}

}

int main()

{

read();

printf("\n\nInformation at sender\n");

printf("%s",inputstring);

printf("\nFrame at sender \n");

displayframes();

shuffle();

printf("\n---\nFrame at receiver\n");

displayframes();

printf("\nInformation received at reciever\n");

displayinformation();

bubblesortframes();

printf("\n---\nFrames at receiver after sorting\n");

displayframes();

printf("\nInformation at receiver after sorting\n");

displayinformation();

return 0;

OutputEnter src address : 176.16.1.12

Enter dest address : 176.16.1.44

Enter the information : Mysore boy rocks.

Information at sender

Mysore boy rocks.

Frame at sender

Seq No Dest Src Data Length

---------------------------------------------------------------------------------------

0 176.16.1.44 176.16.1.12 Mysor 5

1 176.16.1.44 176.16.1.12 e boy 5

2 176.16.1.44 176.16.1.12 rock 5

3 176.16.1.44 176.16.1.12 s. 2

---

Frame at receiver

Seq No Dest Src Data Length

---------------------------------------------------------------------------------------

3 176.16.1.44 176.16.1.12 s. 2

1 176.16.1.44 176.16.1.12 e boy 5

0 176.16.1.44 176.16.1.12 Mysor 5

2 176.16.1.44 176.16.1.12 rock 5

Information received at reciever

s.e boyMysor rock

---

Frames at receiver after sorting

Seq No Dest Src Data Length

---------------------------------------------------------------------------------------

0 176.16.1.44 176.16.1.12 Mysor 5

1 176.16.1.44 176.16.1.12 e boy 5

2 176.16.1.44 176.16.1.12 rock 5

3 176.16.1.44 176.16.1.12 s. 2

Information at receiver after sorting

Mysore boy rocks.

Frame Sorting Technique used in buffer.

#include

struct frame{

int num;

char str[20];

};

struct frame arr[10];

int n;

void sort() /*Bubble sort */

{

int i,j;

struct frame temp;

for(i=0;i

for(j=0;j

if(arr[j].num>arr[j+1].num)

{ temp=arr[j];

arr[j]=arr[j+1];

arr[j+1]=temp;

}

}

int main()

{

int i;

system("clear");

printf("Enter the number of frames\n");

scanf("%d",&n);

printf("Enter the frame sequence number and frame contents\n");

for(i=0;i

scanf("%d%s",&arr[i].num,&arr[i].str);

sort();

printf("The frame in sequences\n");

for(i=0;i

printf("%d\t%s\n",arr[i].num,arr[i].str);

}

Mr. Gauro

Nepal Engineering and Technical Science Academy

Birendranagar, Surkhet

Nepal

How many values can store a variable at a time?

The number of values a variable can store at a time depends on the data type of the variable. For example, a variable of type int (integer) in many programming languages can store a single integer value at a time. Similarly, a variable of type float (floating-point number) can store a single floating-point value. Other data types like arrays or lists can store multiple values at a time. The capacity of a variable to store values is determined by its data type and memory allocation.

The consequences if a connection fails Five devices arranged in a mesh topology?

If five devices arranged in a mesh topology so we will have 10 links and 4 I/O ports in each hardware device. If any link goes down from them so it will be easy to find out which one is down and it won't effect on other links. But a bulk of wires and can create problem in re-installation and re-configuration.

What is similarities between interface and classes?

The similarities are:

a. They are both java basic object types

b. They both can contain variables and methods (With difference being class methods have implementation code whereas the interface methods can only have declarations)

c. They can both be inherited using Inheritance (extends keyword for classes and implements keyword for interfaces)

W difference between a linear linked list and a circular linked list?

I would say that there is no such thing as a circular queue. The point of a circular data structure is to allow the end to loop around to the beginning. Since you can only remove items from the beginning of a queue or add them to the front, having these two items linked has no purpose nor benefit.

Advantages and disadvantages of pseudo-code?

Pseudocode Advantages

  1. Can be done easily on a word processor
  2. Easily modified
  3. Implements structured concepts well

Pseudocode Disadvantages

  1. It's not visual
  2. There is no accepted standard, so it varies widely from company to company

What is the name of kernel in Unix Linux and Windows Vista?

As Unix isn't any particular operating system, there is no distinct name for the kernel. Different versions of Unix may have vastly different kernel structures.

The Linux kernel is called, well, the Linux kernel.

The Vista kernel is a continuation of the "NT kernel" designed for Windows NT 3.1.

What are the different symbol use in flow chart?

Os fluxogramas utilizam uma variedade de símbolos padrão para representar diferentes tipos de atividades, processos, decisões e fluxos de informações. Esses símbolos facilitam a compreensão do fluxo de trabalho ou processo representado. Aqui estão os símbolos mais comuns usados em fluxogramas:

  1. Oval (Elipse ou Círculo)

Significado: Início ou Fim de um processo.

Uso: Indica onde o processo começa e onde termina.

Exemplo: "Iniciar" ou "Fim".

  1. Retângulo (Processo)

Significado: Representa uma etapa ou atividade do processo.

Uso: Descreve ações específicas que precisam ser executadas.

Exemplo: "Enviar e-mail", "Calcular valor".

  1. Losango (Decisão)

Significado: Ponto de decisão, geralmente com opções como "Sim" ou "Não".

Uso: Representa bifurcações no processo com base em condições ou perguntas.

Exemplo: "Pagamento aprovado?" → "Sim" ou "Não".

  1. Seta (Fluxo ou Conector)

Significado: Indica a direção e sequência do fluxo do processo.

Uso: Conecta os elementos do fluxograma para mostrar o caminho do processo.

Exemplo: Uma seta conectando "Início" a uma etapa seguinte.

  1. Paralelogramo (Entrada ou Saída de Dados)

Significado: Representa entrada ou saída de informações.

Uso: Para ações como receber ou fornecer dados.

Exemplo: "Inserir dados" ou "Exibir relatório".

  1. Círculo (Conector no mesmo fluxograma)

Significado: Conector dentro do mesmo fluxograma.

Uso: Para indicar a continuidade do fluxo em uma área diferente do diagrama.

Exemplo: Usado quando o fluxograma é muito longo e precisa ser segmentado.

  1. Pentágono ou Hexágono (Conector fora do fluxograma)

Significado: Conector para outra página ou outro fluxograma.

Uso: Quando o processo se conecta a outro sistema ou diagrama.

Exemplo: "Continuar no fluxograma B".

  1. Retângulo com Laterais Arredondadas (Subprocesso)

Significado: Representa uma etapa que é detalhada em um subprocesso separado.

Uso: Para simplificar fluxogramas complexos.

Exemplo: "Processar pedido" (detalhado em outro fluxograma).

Esses símbolos são padronizados por organizações como a ANSI (American National Standards Institute) e a ISO (International Organization for Standardization), garantindo que fluxogramas sejam consistentes e compreensíveis universalmente. Ferramentas de software, como Microsoft Visio, Lucidchart e até PowerPoint, geralmente seguem esses padrões.

How do you map the object oriented concept using non object oriented languages?

Object oriented programming doesn't strictly require an object-oriented programming language (although those are generally best suited for the job).

Object orientation, as a concept, means to create logical representations of physical or conceptual items: a vehicle, a person, a manager, etc. Each object type (commonly called a class) has a bundle of attributes (data items, properties) and verbs (methods, functions). These bundles, together, form the class.

It is thus possible to create constructs very close to modern classes as those known in C++ using structures in C. In fact, the first C++ compilers (~20 years ago) translated C++ into C, then used an existing C compiler to generate executable code.

In C, a structure can

  • contain variables (data members)
  • pointers to functions (member functions)
  • pointers to pointers of functions (virtual functions)

Among the many standard object-oriented techniques which can not be modeled in C are

  • privacy through visibility keywords (public, private, protected)
  • inheritance (but a "derived" class can embed the "superclass" for a similar effect)
  • polymorphism
  • contracts (interfaces)
  • operator overloading

That said, object orientation as a design concept does not require an object oriented language.

Write a c program to find out the prime numbers between 1 to 500?

Here is a simple program to generate prime numbers upto a given specific number

/*Prime No. from 1 to 50*/

/*By-Himanshu Rathee*/

#include<stdio.h>

#include<conio.h>

void main()

{

int i,j,n;

clrscr();

printf(" Enter the number upto which we have to find the prime number: ");

scanf("%d",&n);

printf("\n");

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

{

for(j=2;j<=i-1;j++)

if(i%j==0)

break;

/*Number is divisble by some other number. So break out*/

if(i==j)

printf("\t%d",i);

/*Number was divisible by itself (that is, i was same as j)*/

}

/*Continue loop upto nth number*/

getch();

}

What is a computer program written in English language called?

Pseudocode. However, pseudocode is not a programming language as such. It is a language that a programmer uses specifically to convey the concept of a specific algorithm to other programmers. The language is such that any programmer can easily translate the algorithm into their preferred language. Furthermore, pseudocode does not have to be written in English, it can be written in any language. However, English is the most widely-spoken language within the programming community and is therefore the most prevalent language used in programming.

Who is Delphi owned by?

The Delphi programming language is currently owned by Embarcadero.

Q2 Differentiate between formatted and unformatted you input and output functions?

Formatted I/P functions: These functions allow us to supply the input in a fixed format and let us obtain the output in the specified form. Formatted output converts the internal binary representation of the data to ASCII characters which are written to the output file. Formatted input reads characters from the input file and converts them to internal form.

Format specifications

Data type

Integer

short signed

short unsigned

long signed

long unsigned

unsigned hexadecimal

unsigned octal

%d or %l

%u

%ld

%lu

%x

%o

Real

float

double

%f

%lf

Character

signed character

unsigned character

%c

%c

String

%s

Unformatted I/O functions: There are several standard library functions available under this category-those that can deal with a string of characters. Unformatted Input/Output is the most basic form of input/output. Unformatted input/output transfers the internal binary representation of the data directly between memory and the file

What similarities between analog and digital signals?

ANALOG:continuous,rate of transmission is slow,less reliable 2 transmit,more noise,interference is more

DIGITAL:non continuous,rate of transmission is fast,more reliable 2 transmit,less noise,interference is less

Computer users who are not computer professionals are sometimes called?

Computer users who are not computer professionals are often referred to as "end users" or "casual users." They typically use computers for basic tasks like browsing the internet, using office applications, or consuming media, without having specialized technical skills. In some contexts, they may also be called "lay users" or "non-technical users."

Step form algorithm for making a telephone call to your friend?

Step1. Start procedure

Step 2. Pick up the phone

Step 3. Search for a friend phone number in the contact list

Step 4. Select the number and dail it by clicking the dail button

Step 5. Wiat for the network

Step 6. If connection is successful you will hear the dailer ring tone.

Distinguish between determinate error and indeterminate error?

Indeterminate errors are random errors that randomly fluctuate and cannot be eliminated.

Determinate errors

What is the advantages of orthographic projection?

1) Some training is necessary before you can draw or read a drawing.

2) Sometimes it's easier to draw the object in perspective view (pictorial view), especially for clients who have difficulties interpreting orthographic drawings.

What are the two types of peopleware?

Well honey, there are two types of peopleware: the ones who can't live without their morning coffee and the ones who are perpetually late to every meeting. Just kidding! In the world of software development, peopleware refers to both the users and the developers who create and maintain the software. So, to answer your question, the two types of peopleware are the end-users and the software development team.

Write an algorithm that can find the maximum of n numbers?

#include void main()
{
int a[10] = { 4, 55, 65, 73, 87, 99, 45, 454, 4353, 243}; int i, j, k, l; for ( j = 9, i = 1, k = 5, l = 6; i <= 2, k >= 3, l<= 7, j >= 8 ; i++, j--, k--, l++)
{

if (a[0] < a[i])
{
a[0] = a[i];
}
if (a[0] < a[j])
{
a[0] = a[j];
}
if (a[0] < a[k])
{
a[0] = a[k];
}
if (a[0] < a[l])
{
a[0] = a[l];
}
} printf("highest number = %d", a[0] );
}

How can techniques of representing and communicating algorithms be improved?

Techniques for representing and communicating algorithms can be improved by using standardized notations such as pseudocode or flowcharts to make them more easily understandable across different platforms and languages. Additionally, providing clear and concise explanations of the algorithm's purpose, inputs, outputs, and steps can enhance comprehension. Utilizing visual aids, such as diagrams or animations, can also help in illustrating complex algorithms in a more intuitive manner.

What are the advantages of a a compiler over an interpreter b an interpreter over a compiler?

Compilers and interpreters do similar jobs, but there are differences:


To run a program you've written, eg in JAVA, it must first be translated into machine code so the computer can read it. This is what compilers and interpreters do.

However, compilers convert the code all at once, save it, then run it; whereas interpreters translate the code one line at a time, as it is run.


Interpreters tend to result in faster translating of code so they are used mostly for debugging. This is because if you used a compiler, you'd have to re-compile your entire project every time you changed one little thing.

However, it's not very efficient to keep re-translating your code once you've finished writing it, because it would waste CPU time. Because of this, once code is done, it is normally compiled so that it runs faster and takes up less space. Another advantage of this is that your code is then much harder to copy without lengthy 'reverse engineering.'

What are overflow and underflow conditions in stack?

A stack overflow occurs when the on--chip stack capacity is exceeded. This can be detected by a comparison of the top-pointer, the last-pointer and the index specified for a create-frame operation ( for push). Initially the top-pointer is set to 1 and the last-pointer to 0, placing a dummy element on the stack.

If an index specified for a read access is greater than the number of valid on--chip stack elements, a stack underflowoccurs

Queue overflow results from trying to add an element onto a full queue and queue underflow happens when trying to remove an element from an empty queue.

What is the opposite of primitive?

The opposite of primitive is advanced or sophisticated. Primitive refers to something basic, undeveloped, or in its earliest stage of existence. In contrast, advanced denotes a higher level of complexity, refinement, or progress in a particular field or context.