answersLogoWhite

0

📱

Computer Programming

A category for questions about computer programming and programming languages.

10,506 Questions

What is vector and array processing?

An important part of IDL is the ability to work with data that is organized as vectors and arrays. We will first describe vectors and arrays and then show some tools for constructing them. Finally, we will demonstrate some of their uses. In addition to arrays of numbers, which we will describe here, there are also arrays of strings, structures and objects. You can look up information about them in IDL help if you are eager to find out about them now.

Arrays are especially important in signal image processing. We will find that images are just arrays of values with one value for each pixel. Vectors are important in the representation of one-dimensional functions such as functions of time or one spatial dimension.

Vectors

A vector is a list of data items, and can be constructed with an assignment statement like

A=[1.2, 3.1, 4.6, 5.7]

Note that square brackets are used to contain the list. Try typing a list like that shown above and then using HELP,A to get information about the vector.

Vectors can contain any of the number types that are accepted by IDL. When the assignment is made all of the numbers are converted to one type. The type that is used is determined by the data type hierarchy. Try typing

A=[1, 3B, 4L, 5.7] & HELP,A

IDL responds that A is an array of type FLOAT of length 4. If you were to type

A=[1, 3B, 4L, 5] & HELP,A

you would find that A is now of type LONG. The rule is to convert all of the numbers to the highest number type.

Arrays

We can think of a vector as a list that has one dimension. It is a row of data. An array is a list that is arranged in multiple dimensions. A two-dimensional array is a vector of vectors that are all of the same length.

C=[[1,2,3,4],[5,6,7,8],[7,6,5,4]] & PRINT,C

1 2 3 4

5 6 7 8

7 6 5 4

We see that A has three rows and four columns and that each row is one of the vectors in the list. An array can contain any of the IDL data types. When it is created all of the numbers are converted to the highest number type. We will describe a number of IDL functions for the construction of arrays. By using these functions one can construct arrays of up to eight dimensions.

Indexing

Column and Row Index

It is important to be able to refer to particular elements of an array. An element in column 1 and row 2 can be referred to by C[1,2]. In the above array we would find that C[1,2]=6. In IDL the column index comes before the row index.

Rows and columns are indexed beginning with the number 0. The column indexes of C are 0, 1, 2, 3 and the row indexes are 0, 1, 2. Zero-referenced indexing is a convention that may seem strange at first, but it has programming advantages.

One can refer to an entire row by using an asterisk in the column position. C[*,r] refers to the vector in row r. Try the command PRINT,C[*,2].

One can refer to an entire column by using an asterisk in the row position. C[col,*] refers to the vector in column col. Try the command PRINT,C[3,*].

A part of a row or column can be indexed by providing a list of the elements that are wanted. Try the following

row =[0,1,2] & col = [3,2,1] & PRINT,C[col,row]

Can you explain what is printed?

A contiguous segment of column or row elements can be referred to with the notation a:b. For example, C[0:2,2] refers to the elements in positions 0,1,2 in row 2. Try the command PRINT,C[0:2,2]

Array Index

Every element in an array has an array index. The array index is found by counting each element from the beginning of the array to the end row by row. An array that has four columns and three rows would have the indexes as shown below.

0 1 2 3

4 5 6 7

8 9 10 11

Any element in the array can be referred to by its array index. A list of elements in positions 0, 6 and 8 can be printed by

k=[0,6,8] & C[k]

One can find the value of array index from the row and column indexes. The number of columns, n, has to be known. Then k is simply

k = col + row*n

If k is given then the column and row indexes can be found by integer operations:

row = k/n

col = k - row*n

For an array with n=4 columns, C[6]=C[2,1]. You should try converting in both directions.

Array Creation Tools

IDL provides a number of functions that can be used to create arrays and initialize their values. The list can be found in the section "Array Creation Routines" in IDL Online Help. A subset of these routines are listed below.

BINDGEN Return a byte array with each element set to its subscript.

BYTARRCreate a byte vector or array.

FINDGEN Return a floating-point array with each element set to its subscript.

FLTARRReturn a floating-point vector or array.

INDGEN Return an integer array with each element set to its subscript.

INTARRReturn an integer vector or array.

LINDGEN Return a longword integer array with each element set to its subscript.

LONARRReturn a longword integer vector or array.

IDENTITY Return an identity array.

MAKE_ARRAYGeneral purpose array creation.

REPLICATEForm array of given dimensions filled with a value.

The functions BYTARR, FLTARR, INTARR, LONARR create arrays with of the type indicated by the first letter of the name and with their initial values set to zero. You can then enter data into them by assignment statements. For example, create an integer array of size 3x4 and set the elements of the first row to the value 3.

A=INDGEN(3,4)

A[*,0]=3

PRINT,A

The functions BINDGEN, INDGEN, FINDGEN, LINDGEN create arrays of the type indicated by the first letter of the name and with the initial values set to the array index. For example, create an array of type byte of size 3x4 and set its initial value to the index.

B=BINDGEN(3,4)

PRINT,B

0 1 2

3 4 5

6 7 8

9 10 11

The functions that generate index arrays are very useful in creating a vector of independent variables to be used in calculating and plotting a function. Suppose that you needed to plot the function (1+t2)Cos(5t) over the interval [0,3] in steps of size 0.01. You will then need a vector of 301 values t=[0, .01, .02, ..., 2.99, 3]. You certainly would not want to type all this in. The statements that will do the calculation and plot a graph are given below.

t=FINDGEN(301)/100 ;Generates the desired vector

f=(1+t^2)*cos(5*t) ;Calculates the function

plot,t,f ;Draws the graph

The IDENTITY function returns a square array of type float with the elements on the main diagonal set to 1 and all others set to zero. This function is very useful in many linear algebra computations.

I=IDENTITY(4)

PRINT,I

The REPLICATE function makes an array of the specified size in which a give value placed in all of the positions. To make a 5x2 array in which all of the elements contain the value 3.1 one can use

C=REPLICATE(3.1,5,2)

PRINT,C

The function MAKE_ARRAY is the most general array creation tool. It has many options which are best described by the online help documentation and the reference manual.

What do you mean by dead lock condition?

WHEN EVER A OPERATING SYSTEM IS EXECUTING A PROCESS (P1)USING THE SOME RESOURCES OF THE SYSTEM AND A ANOTHER PROCESS (P2) WANT THE SAME RESOUCES WHICH IS BEING USED BY THE PROCESS (P1). THEN THE OS COMES TO A SITUATION CALLED DEAD LOCK.

IT IS JUST LIKE THE TRAFFIC JAM SITUATION IN WHICH THE ALL THE VEHICALS WANTS TO SHARE THE SAME ROAD.

What is a algerbraic expression?

An algebraic expression is a mathematical sentence that includes a variable but does not have an equal sign.

for example:

2x is an algebraic expression

2x = 6 is an equation

What is the need for oops paradigm?

Object oriented programming is a concept that was created because of the need to overcome the problems that were found with using structured programming techniques. While structured programming uses an approach which is top down, OOP uses an approach which is bottom up. Traditionally, programming has placed an emphasis on logic and actions.

Object oriented programming has taken a completely different direction, and will place an emphasis on objects and information. With object oriented programming, a problem will be broken down into a number of units. These units are called objects. The foundation of OOP is the fact that it will place an emphasis on objects and classes.

Objects will be defined, and they will interact inside the system in a number of different ways. There are a number of advantages to be found with using the OOP paradigm, and some of these are simple maintenance, an advanced analysis of complicated programs, and reusability. There are a number of programming languages that use OOP, and some of these are Java, C++, and Ada. One concept that you will want to become familiar with is data modeling. Before you can construct an object oriented system, you will first need to find the objects within the system and determine the relationships they have. This process is called data modeling. There are some other OOP terms that you will want to know.

A class is a unit that holds data and functions which will carry out operations on the data. A class will be comprised of three access modifiers. These three modifiers are protected, private, and public. A member that is public can be accessed and inherited. A member that is designated as private cannot be accessed by objects that exist outside the system. In addition to this, it cannot be inherited. While a member who is protected can be inherited, they cannot be accessed by objects which reside outside of the class hierarchy. Another term that you will hear about often in OOP is objects.

An object is a state of class. It can receive and send messages to other objects, and it can handle data. The objects which exist within software are often based off real world objects, and will behave in the same manner. There are two things that are found with all objects that exist in the real world. These two things are behaviors and states. While behaviors and states are found in real world objects, they can also be found in software objects as well. Another OOP concept that you will need to know is a method. A method is a process that is used to handle an object. A method can be public, protected, or private. The visibility of the member will determine how much of it can be seen by outside objects.

Inheritance is an aspect of OOP that allows subclasses to inherit the traits and characteristics of its superclass. The subclass will inherit all members except those that designated as being private. The subclass may have a large number classes from multiple bases, and this concept is called Multiple Inheritance. It is possible for a subclass to use the behavior of the members it has inherited, and it can also add new members as well. There are two powerful advantages that inheritance has, and these are the implementation of abstract data and reusability.

Encapsulation is another important concept that you will need to know. In a nutshell, encapsulation is responsible for shielding the data within a class from outside objects. It will only reveal the functional information. However, the implementation will be hidden. Encapsulation is a concept which promotes modularity, and it is also crucial for hiding information.

Is an algorithm close to a programming language?

Fairly close. A programming language is a means of communicating with the machine, instructing it to perform a specific sequence of statements. Depending on the language, those statements may be low-level (like assembly) or high-level (like Java). The level determines the amount of abstraction between the language and the machine. Higher-level languages are easier to program than low-level languages, but low-level languages are generally more efficient.

An algorithm is a procedure or formula for solving a problem; a finite series of computation steps to produce a result. A programming language is not an algorithm. It simply provides the means of translating an algorithm into machine-dependant instructions. Algorithms are typically written using pseudo-code, a non-existent, generalised programming language that can be easily translated into a more specific programming language.

Many programming languages incorporate algorithms as part of the language. For instance, the C++ standard template library provides many algorithms in the form of function templates that can accommodate a wide variety of sequence containers (class templates), such as arrays, lists, sets and maps, or any user-defined container that follows the standard. For example, the std::sort algorithm is a function template that can be used to sort a sequence container, regardless of it type and regardless of the type of data it contains. Although these algorithms are generic in nature, they are highly optimised such that they do not sacrifice performance for generality. You don't have to use them -- you can easily write your own algorithms to perform the same tasks -- but it makes no sense to re-invent wheels unnecessarily, especially for an "everyday" algorithm like sorting or accumulation.

Programs are themselves an algorithm, albeit a highly-complex one composed of many individual algorithms. Thus we can think of a programming language as being the means of implementing simple algorithms in order to solve complex problems.

Complexity of an algorithm in data structure?

* search array => O(1) linked list=> O(n) binary tree=> O(log n) hash=>O(1) * search array => O(1) linked list=> O(n) binary tree=> O(log n) hash=>O(1)

Why constructors are declared public only?

Constructors are not declared public only. They can be declared protected and private, as required by the class. Protected constructors are only accessible to the class members and to derived classes. Private constructors are only accessible to the class members.

Although a default public constructor is required by the majority of classes, it is not true of all classes. Derived classes can call any public or protected base class constructor explicitly via their own construction initialisation sections.

Private construction is typically used in the singleton model to instantiate a private static instance of the class as and when it is required, whilst preventing multiple instances of the class from being created. However, class members also include friends of the class, thus external friend classes and friend functions can also instantiate objects via their private constructors.

Note that the whole point of public, protected and private access is not to hide information (as is often wrongly said) but in order to limit access to that information. The same applies to a class' constructors as it does to its member methods and member variables.

How do you insert a node using doubly linked list in c plus plus?

#include<iostream>

#include<list>

void print_list (std::list<int>& list)

{

for (std::list<int>::const_iterator it=list.begin(); it!=list.end(); ++it)

std::cout << *it << ", ";

std::cout << "\b\b \n";

}

int main()

{

// instantiate a list

std::list<int> list;

// push a new value onto the back of the list:

list.push_back (1);

print_list (list);

// push a new value onto the front of the list:

list.push_front (2);

print_list (list);

// insert a new value at the back of the list

list.insert (list.end(), 3);

print_list (list);

// insert a new value at the front of the list

list.insert (list.begin(), 4);

print_list (list);

// locate value 1.

std::list<int>::const_iterator it=list.begin();

while (it!=list.end() && *it != 1)

++it;

// insert a new value in front of value 1.

list.insert (it, 5);

print_list (list);

}

Output:

1

2, 1

2, 1, 3

4, 2, 1, 3

4, 2, 5, 1, 3

Which is easier 'C' or 'C plus plus'?

Opinion 1:

I think both are easy to use an manipulate although i have never written a c++ program other than hello world but to know c++ you have to know c and c is a standard high level language which is easy to grasp

Opinion 2:

C++ is easier in the end because it is a revised version of the old c language. It is not required to learn C first before learning C++ because you pick up bad habits and when you move to C++, those habits will be hard to get rid of. C++ is a lot more powerful and accurate, it is harder at first but with time it will be a lot easier and more organized than c.

In conclusion, C is easier to learn but not recommended to learn.

I highly recommend people to go straight to C++ to pick up only good habits, then go back to C if you're curious how it works.

A program to find the sum of n numbers in visual basic?

//Script by aakash30jan

<script type="text/vbscript">

For count = 1 to 10

sum=sum+count

document.write("<br />" & sum)

Next

</script>

What is Character User Interface CUI?

Character User Interface or CUI is like Graphical User Interface which is used for the Input and Output of the Data in the computer, except in the GUI apart from text there are also graphical contents present, in CUI there is only use of text typed one after another just as commands used in MS DOS.

How does an md5 hash work specifically?

In cryptography, MD5 (Message-Digest algorithm 5) is a widely used, partially insecure cryptographic hash function with a 128-bit hash value. As an Internet standard (RFC 1321), MD5 has been employed in a wide variety of security applications, and is also commonly used to check the integrity of files. An MD5 hash is typically expressed 32-character string of hexadecimal numbers.

The MD5 hash also known as checksum for a file is a 128-bit value, something like a fingerprint of the file. There is a very small possibility of getting two identical hashes of two different files. This feature can be useful both for comparing the files and their integrity control. Let us imagine a situation that will help to understand how the MD5 hash works. Alice and Bob have two similar huge files. How do we know that they are different without sending them to each other? We simply have to calculate the MD5 hashes of these files and compare them.

The MD5 hash is used in many websites.

Can you wipe your hardrive without rebooting your computer?

Insert hard drive CD when you start up your computer. Check box when it asks you if you want to delete and re-use your hard drive. When completed, insert your OS CD, and money in the bank... if you want a quick re-format, dont insert the hard drive CD on startup.. just insert the OS CD on start up.. it will do a quick reformat that will give you results until you can find your hard drive CD if you dont have one.

You can also use DBAN or wipedrive - both these free and paid for products will erase / wipe your hard drive to DOD standards.

Be more specific please. If you mean deleting all the files, the best method i would suggest is to reinstall the OS.

Are high level languages machine dependent?

yes i definetly think that high level language is better than low level language!!! because it provides a much user friendly environment and makes programmes easier to read and write...It also makes the program less error prone.. The speed of writing programs also becomes easy

What is the relationship between high level language code and low level language code?

All types of programming languages have one property in common: all languages, ultimately and in some manner, lead to machine instructions upon which the processor operates.

Some higher programming languages, especially those of a traditional design such as the C programming language, might generate code in a low level language (i.e. assembly language) as an intermediate step during compilation. However, most modern designs do not implement or expose this as an explicit step, and transcoding of higher to lower level languages is certainly not required.

The fact that all programming languages lead to executed machine code, however, does not mean that all language lead to a translation which results in executable code; interpreted languages, which include popular modern languages such as Java and the .NET family of languages, will generally execute machine code which interprets the language instructions, while compiled languages (which includes most forms of C) generally generate directly executable machine code.

What is a stack frame?

The Stack class represents a last-in-first-out (LIFO) stack of objects. It extends class Vector with five operations that allow a vector to be treated as a stack. The usual push and pop operations are provided, as well as a method to peek at the top item on the stack, a method to test for whether the stack is empty, and a method to search the stack for an item and discover how far it is from the top.

When a stack is first created, it contains no items.

Methods:

  • empty() - Returns boolean - Used to check if the stack is empty
  • peek() - Returns Object - Take a look at the top most element in the stack without popping it
  • Pop() - Returns Object - Returns the top most element from the stack
  • push(Object o) - Pushes the object at the top of the stack
  • search(Object o) - Returns int - Returns the index location of the searched object. Returns -1 if the object is not found.

Stack is a data structure it allows data to be inserted and removed in a push and a pop operation . stack also support a peek operation which reads data without removing it. A stack is a LIFO-queue, meaning that the last data to be inserted will be the first data to be removed

How can computer hacking be dangerous?

Well multiple reasons. You could be reversed hacked. The victum might have a virus on theirs that sends itslelf to you, and if you are doing it illegaly then you could get cought by the feds from your IP. (google IP address trace)

Why use static variable in programming language?

For C programming, the use of a static variable has two uses:

One reason is to hide the variable from other modules. The scope of the static variable is limited to the compilation unit that it is described in.

The second use of a static variable is to keep the value of the variable intact through the entire program execution unit.

What is the difference between compiled language and interpreted language?

A compiled language is written and then run through a compiler which checks its syntax and compresses it into a binary executable. Since an interpreted language is not compiled, it must be checked for errors at run-time, which makes it quite a bit slower than a compiled language (like C or Java). Perl is an example of an interpreted language. Remember, though, that just because a language is interpreted doesn't necessarily mean it is not full-featured, or simplistic. Perl can get very complex and very cryptic, very quickly.

Who first used the term internet?

Jean Armor Polly is credited with coining the phrase, "surf the net". She said Internet instead of net, but it was shortened later by computer lingo geeks to net. Jean Armor Polly has written several books about safety on the Internet.

How many input MUX you will get if 4 input multiplexers drive a 4 input multiplexer?

we'll get 4 input mux

cuz 2^4=16.... therefore the first 4 input mux has 16 o/p..

hence four-4 i/p mux are required to fill all 16 leads.

Why static variables in a function have global extent?

A variable declared static outside of a function has a scope the of the source file only. It is not a global variable. A variable declared outside of a function and without the static qualifier would be a global variable.