answersLogoWhite

0

📱

Computer Programming

A category for questions about computer programming and programming languages.

10,506 Questions

Mention the importance of subroutines in programming?

A subroutine is typically defined as being a function or procedure that can be invoked at any point in a program, causing the procedural execution to branch to the subroutine. This is not unlike a goto or jump statement, however subroutines also make use of the program's call stack to allow values (arguments or parameters) to be passed to the subroutine, including the address of the caller so that execution can return to the point of the call when the subroutine falls from scope. A subroutine can also (optionally) return a single value to the caller, known as the return value. Return values are temporary and will fall from scope when the expression that invoked the subroutine falls from scope. However, by assigning a subroutine to a variable, the return value can be stored in that variable and can then used in subsequent expressions. Subroutines pop their arguments from the stack and construct local variables or references from the argument values. Arguments passed by reference can therefore be used to return values through the referenced values. Values returned in this manner are known as output arguments. Subroutines that use output arguments often use the subroutine's temporary return value to indicate any errors that occurred within the subroutine, with zero indicating success (no error).

What is the difference between high level and low level programming?

High level languages are easier for humans to read and program in. They are usually machine independent, and most have a wide variety of programming libraries available for common functions.

Low level languages are usually machine specific, such as assembly languages. They lack programming libraries.

Design the logic code for program to print numbers in reverse order from 10 down to 1?

Enter values and end of the list enter -1 to see output. but execute it at command line.

<?php

function readData(){

fwrite(STDOUT, "Please enter your name\n");

// Read the input

$name = fgets(STDIN);

if($name != -1)

readData();

fwrite(STDOUT, "Hello $name");

return;

}

readData();

?>

start

num Sub

num Size = 10

index = 0

while index<10

index = index + 1

endwhile

while index > 0

index = index - 1

endwhile

print Sub

stop

What is a sparse matrix in c programming?

Sparse matirx can be represented 1-dimensionally, by creating a array of structures, that have members sumc as: Struct RM{int ROW,int COL, int non_zero}; struct RM SM[Number_non_Zeros +1]; then input row,col for each non-zero element of the sparse matrix. if still unclear please fell free to requestion or query on ikit.bbsr@gmail.com, specifying clearly the question in the subject. Chinmaya N. Padhy (IKIT)

I want to learn how to program?

Learning how to write computer programs - is similar to learning a new language. You need to learn the syntax of the programming language, in order to correctly write lines of code. For example - in BASIC, the syntax of an IF/THEN command is... IF {condition 1} THEN do (option 1);ELSE do (option 2).

Difference between third and Fourth-generation programming language?

If you're referring to genetic algorithms, it's a subset of what you may call "conventional programming"

Genetic algorithms are in a way similar to AI algorithms, in the sense that the solution to a given problem is not laid out programmatically or mathematically. Instead, a genetic algorithm provides the basis to solve a problem.

A genetic algorithm is based on the laws of natural selection. "Specimens" mutate and are then passed through a fitness function - the most elligible ones survive, while the rest are destroyed.

A genetic algorithm can be constructed with a "conventional" programming language.

What are the benefits of being a video game programmer or designer?

The benefits for video game programming is merely personal benefits. Video game programmers are over worked and generally underpaid (in comparison to those working in the corporate field). Some people who program video games mainly for the fact that they are video game fans themselves and want to contribute and work on projects themselves. A video game designers tend to get paid more and are the "main visionary" of the project. Their job is not as simple as think of an idea and create a game from it, they requite many artistic skills and really good writing skills. The designer must also be capable of changing many aspects of the project if demanded by the studio.

What is a compile- go loader?

One method of performing the loader functions is to have the assembler run in one part of memory and place the assembled machine instructions and data, as they are assembled, directly into their assigned memory locations (Figure). When the assembly is completed, the assembler causes a transfer to the starting instruction of the program. This is a simple solution, involving no extra procedures. It is used by the WATFOR FORTRAN compiler and several other language processors. Such a loading scheme is commonly called "compile-and-go" or "assemble and-go." It is relatively easy to implement. The assembler simply places the code into core, and the "loader" consists of one instruction that transfers to the starting instruction of the newly assembled program. However, there are several apparent disadvantages. First, a portion of memory is wasted because the core occupied by the assembler is unavailable to the object program. Second, it is necessary to retranslate (assemble) the user's program deck every time it is run. Third, it is very difficult to handle multiple segments, especially if the source programs are in different languages (e.g., one subroutine in assembly language and another subroutine FORTRAN or PL/I). This last disadvantage makes it very difficult to produce orderly modular pro­grams. we can say that here loader is not a separate prog.also the four important functions of loader as 1)allocation 2)linking 3)relocation 4)loading is not done independently byloader.

What are Different types of assembly language statements?

The three types of assembly language are:

1. Imperative: indicates an action to be performed.

2. Declaration

3. Assembler Directives

How do active margins differ from passive margins?

Passive continental margins are not areas of convergence. There is little volcanic and earthquake activity on passive margins. Active margins are areas of convergence where one plate is descending beneath another. They are associated with volcanic and earthquake activity.

What are the advantages of insertion sort?

It is less efficient on list containing more number of elements.

As the number of elements increases the performance of the program would be slow.

Insertion sort needs a large number of element shifts.

What has been strongest influence on programming language design?

The strongest influence will always be the need and the demand for it.

for instance, with regards to security, if there are so many virus or hack attacks

then definitely a new security program is needed.

another is if the current program cannot handle the growth of a company

then a new set of programs is in order.

and then there is the cost of maintaining a program.

why pay more when one can get it for a much cheaper program.

Program to find the size of the string in c?

int main (void) {

char buf[1024];

scanf ("Enter a string: %s", buf);

printf ("The length of the string is %d chars long.\n", strlen (buf));

return 0;

}

What translates a high level language into machine code?

An interpreter or a compiler. The former translates one line at a time and must be executed within the interpreter. The latter compiles the entire program into a standalone executable. For example, C++ is compiled to machine code but Java is compiled to byte code which is then interpreted by the Java Virtual Machine.

What are the advantages of dynamic memory allocation over static memory allocation?

Readers who are familiar with the concepts of dynamic memory and pointers may wish to skip to the next section of this chapter. In this one, the general concepts of static and dynamic memory is outlined. How these issues are specifically handled in Modula-2 is not taken up again until after the rest of the preliminary discussions are complete.

The distinction made in this section is based on the timing and manner for the setting aside of memory for the use of a program. Some memory use is predetermined by the compiler and will always be set aside for the program in exactly the same manner at the beginning of every run of a given program. Other memory is obtained by the program at various points during the time it is running. This memory may only be used by the program temporarily and then released for other uses.

How sparse matrix can be stored using array?

#include<stdio.h>

int main()

{

int a[20],min,max;

int n;

printf("\nEnter the num of elements: ");

scanf("%d",&n);

printf("Enter the elements\n");

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

{

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

if(i==0)

{

min=max=a[i];

}

if(a[i]<min)

min=a[i];

else if(a[i]>max)

max=a[i];

}

printf("The largest element is %d. The smallest element is %d.", max, min);

}

Write a C program using dynamic memory allocation to subtract two matrices?

The easiest way would be to write a function that accepts two arrays and returns one.

Lets say you are working with two 2-dimensional arrays.

array<int,2>^ SubtractMatrices(int arr1[][2], int arr2[][2]);

void main()

{

int arr1[2][2] = {0,1,2,3};

int arr2[2][2] = {0,1,2,4};

array<int,2>^ newarr;

// array<int^,2>^ newarr[2][2] = SubtractMatrices(arr1, arr2);

}

array<int,2>^ SubtractMatrices(int arr1[][2], int arr2[][2])

{

array<int,2>^ newarr;

//Insert subtraction algorithm here

return newarr;

}

In this scenario you must pass the function 2 matrices, and then return a pointer to a new matrix.

Hmm, still seems to be an error in there with the return type. I'm not sure if that's the correct way to do it, I did this in Visual Studio's managed C++. .

Why does graphical user interface programming often use event driven programming paradigm?

It's not a case of often, but always. Whenever your application is idle the application's idle loop is executed. By default, the idle loop simply processes system messages which may result in your application becoming active. For instance, as you pass the mouse over your application window, the operating system generates and posts hundreds of mouse movement messages which are passed to the message queue. The application's idle loop will process these messages and call the appropriate event handlers. Mouse movements may not be relevant to your application but they must be processed nonetheless. When the message queue is empty, the idle loop begins background processing. By default this does nothing except peak at the message queue looking for new messages for your application, but it can be overridden to perform any tasks that take your fancy (such as housekeeping tasks).

However, when the user clicks an object in your window (such as a command button), you would rightly expect your application to respond to that particular event. Thus the appropriate event handler is executed and control eventually returns to the idle loop again.

Problems occur when the event handler executes a highly-intensive task and therefore cannot yield control to the idle loop. This isn't a major problem if the task would only take a few seconds at most to complete, but if it takes any appreciable time this presents a serious problem. If your application does not process messages that are intended for it, then those messages will prevent other programs from gaining access to their messages. And as the message queue fills up, the system, grinds to a halt. Higher priority messages will still get through but the system will quickly become unresponsive.

To address this problem, your application must provide a user-defined message handler that can be periodically called by your intensive tasks, preferably two or more times every second to keep the system as responsive as possible. This message handler needn't be complex, but it must return a value to the caller to signal if the caller should abort or continue processing. For instance, if the user chooses to shut down the system mid-process, your intensive task must be able abort gracefully before the application itself can exit gracefully. This means your message handler must save and remove the message from the queue and signal the process to abort. The message handler may be called several times before the process finally aborts, but when it does control can pass to the idle loop which will finally deal with the message that caused the abort, thus permitting a graceful exit.

What is the difference between object oriented approach and procedure oriented approach?

Object oriented focuses on treating variables as objects that have the ability to perform certain tasks. Procedure oriented uses procedures (functions) to perform tasks on variables. For example, if you were writing a program for a DVD rental store:

Object Oriented:

thisdvd.assignTitle("Lethal Weapon");

thisdvd.rentTo("John Smith");

Procedure Oriented:

String thisdvdnumber = 123;

rentDvd(thisdvdnumber, "John Smith");

In the first case, you call functions that belong to object "thisdvd", like assignTitle(), rentTo(), etc. In the second case, you create a variable "thisdvdnumber", then call function "rentDvd()" and tell it which DVD to rent and to whom by passing those variables to it.

Disadvantages of the system development life cycle?

  • Adjusting scope during the life cycle can kill a project
  • No working software is produced until late during the life cycle.
  • High amounts of risk and uncertainty.
  • Poor model for complex and object-oriented projects.
  • Poor model for long and ongoing projects.
  • Poor model where requirements are at a moderate to high risk of changing.

from http://www.phonemania.com.pk/

Unix command to count how many users have logged on to the unix system?

The 'uptime' command will tell you exactly how many users are on the system. There are other variations of this, including counting the number of words from the 'users' command, etc., but this is the easiest.

What do you mean when you say Embed Video?

Embed video means to embed, or place, a video within the HTML code of the page you are posting on.

You can add video using HTML code - you will need more then basic HTML knowledge.

Embedding a video player plugin is much easier. You just need to embed simple code provided by plugin creator.

How do you implement a stack using two queues?

implementing stack using two queues

initially q1 is full and q2 empty

1] transfer elements from q1 to q2 till last element left in q1

2] loop till q2 is not empty

deque element from q2 and again push in q2 till last element is left in q2

transfer this last element in q1

reduce size of q2 by 1

3]finally q1 contains all elements in reverse order as in stack

eg

1]

q1 = 1 2 3 4

q2 =

2]

3 deques till last element left in q1

q1 = 4

q2 = 1 2 3

3]

deque and again queue q2 till last element left

q1 = 4

q2 = 3 1 2

4] deque q2 and queue q1

q1 = 4 3

q2 = 1 2

5] again

deque and queue q2 till last element left

q1= 4 3

q2= 2 1

6] queue q1

q1= 4 3 2

7] queue last element of q2 to q1

q1= 4 3 2 1