answersLogoWhite

0

📱

Computer Programming

A category for questions about computer programming and programming languages.

10,506 Questions

Which one is faster A binary search of an ordered set of elements in an array or a sequential search of the elements?

There is no such thing as an insertion search. There is only insertion sort, which is a method of sorting an unsorted list. Sequential search (or linear search) is only used with unsorted lists. If the list is sorted, a logarithmic search is quicker, by starting from the middle. If the items is not here, it must be in the lower half or the upper half, thus one half of the list can be discarded. You then repeat by starting in the middle of the remaining half. Thus for a list of 15 items, you end up with a list of 7, then 3, then 1, then 0. Thus it takes 5 comparisons to determine that an item does not exist. With linear search it would take 15 comparisons to determine that an item does not exist. Thus logarithmic search is quicker, but only works with sorted lists.

How do you write a Program in java to cheak a number is automorphic number?

Source Code ::

import java.io.*;

class automorphic

{

protected static void main()throws IOException

{

BufferedReader in=new BufferedReader(new InputStreamReader(System.in));

System.out.print("Enter the number: ");

int a=Integer.parseInt(in.readLine()),b=a,c=0,e=a*a;

while(b>0)

{

c++;

b/=10;

}

double d=Math.pow(10,c-1);

if(a==e%d)

System.out.println("Automorphic number!!");

else

System.out.println("Not an Automorphic number!!");

}}

Why is quick sort and merge sort called stable algorithms?

Quick sort is not stable, but stable versions do exist. This comes at a cost in performance, however.

A stable sort maintains the order of equal elements. That is, equal elements remain in the same order they were input. An unstable sort may change the order. In some cases, the order of equal elements is of no consequence, but when two elements with different values have the same sort key, then order can be important.

How long did Bill Gates work on Microsoft?

I'm actually doing a report about him, and its says that he attended public school before going to Lakeside Preparatory School at age of twelve. And also its says he attended Harvard but then dropped out his junior year to work with Microsoft.

How will you Write a c program to find the kth smallest element in an array in c?

//This is for kth largest element. (So this is for n-k smallest element) //Sudipta Kundu [Wipro Technologies] #include <stdio.h> //Input: array with index range [first, last)

//Output: new index of the pivot. An element in the middle is chosen to be a pivot. Then the array's elements are

//placed in such way that all elements <= pivot are to the left and all elements >= pivot are to the right.

int positionPivot(int* array, int first, int last); //Input: array with index range [first, last) and integer K (first <= K < last)

//Output: array whose Kth element (i.e. array[K]) has the "correct" position. More precisely,

//array[first ... K - 1] <= array[K] <= array[K + 1 ... last - 1]

void positionKthElement(int* array, int first, int last, int k); int main() {

int array[] = {7,1,8,3,1,9,4,8};

int i;

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

positionKthElement(array, 0, sizeof(array) / sizeof(array[0]),i);

printf("%d is at position %d\n", array[i], i);

}

return 0;

}

int positionPivot(int* array, int first, int last) {

if (first last)

return first; int tmp = (first + last) / 2;

int pivot = array[tmp];

int movingUp = first + 1;

int movingDown = last - 1;

array[tmp] = array[first];

array[first] = pivot;

while (movingUp <= movingDown) {

while (movingUp <= movingDown && array[movingUp] < pivot)

++movingUp;

while (pivot < array[movingDown])

--movingDown;

if (movingUp <= movingDown) {

tmp = array[movingUp];

array[movingUp] = array[movingDown];

array[movingDown] = tmp;

++movingUp;

--movingDown;

}

}

array[first] = array[movingDown];

array[movingDown] = pivot;

return movingDown;

} void positionKthElement(int* array, int first, int last, int k) {

int index;

while ((index = positionPivot(array, first, last)) != k) {

if (k < index)

last = index;

else

first = index + 1;

}

}

What programming language does Unix use?

Unix was created almost entirely in C. It consists of a main component (called the kernal) and a flotilla of small utilities. Most of these utilities were written in C. Unix distributions usually come with a C compiler so you can create or modify the environment yourself.

However, C is not your only choice. Modern versions of Unix still contain a C compiler, but they often have dozens of other languages available. Most versions of Linux come with a C++ compiler (which is different than C) as well as compilers and interpreters for Java, Perl, and Python. You can generally install hundreds of other languages.

The language you use depends on the type of problem you are solving. Generally you'll use C for basic low-level work, but you'll often pick a higher-level language to solve 'real-world' problems. For example, if you're doing server-side web development, you'll usually use PHP.

What are the Advantages of files in C language?

data files are permanent storage. where as normal data types are volatile, they will save the values as long as the program runs. saving a file will provide us the flexibility to recover the saved data whenever required.

What is the maximum number of nodes that you can have on a stack linked list?

You can have as many as you can fit in memory, which is dependent on size of each node, OS, amount of RAM, etc.

How can you use the link lists as queue?

If you already have a linked list implementation, you can use it as a queue by making a few changes:

* Add a queue() function to add a node to the end of the list * Add a dequeue() function to remove and return the first node

What is the difference between departmental store and kirana stores in India?

A chain store has branches at various locations. A department store is a store where different items are displayed in different areas or floors of the same store.

A department store may be part of a chain of stores.

Suhail Reshi...

Two linked list in a array is possible?

Like this:

#define MAXLIST 100

int first, next [MAXLIST];

/* let the list be: #0 ---> #2 ---> #1 */

first= 0;

next[0]= 2;

next[2]= 1;

next[1]= -1; /* means end of list */

Note: you should track which elements are unused,

in the beginning every elements are unused:

int first_unused= 0;

for (i= 0; i<MAXLIST; ++i) next[i]= i+1;

next[MAXLIST-1]= -1; /* means end of list */

What is difference between structure and class?

The struct default access type is public. A struct shouldtypically be used for grouping data.

The class default access type is private, and the default mode for inheritance is private. A class should be used for grouping data and methods that operate on that data.

In short, the convention is to use struct when the purpose is to group data, and use classes when we require data abstraction and, perhaps inheritance.

In C++ structures and classes are passed by value, unless explicitly de-referenced. In other languages classes and structures may have distinct semantics - ie. objects (instances of classes) may be passed by reference and structures may be passed by value.
Technically there are only two differences between classes and structures:

  1. classes are declared using the keyword class while structures are declared using the keyword struct
  2. structures are entirely public, while classes are private by default

Most C++ programmers use structures exclusively for data that doesn't require strict validation while classes are used to encapsulate data and the functions that work exclusively with that data. Although classes and structures can largely achieve the same goals, the lack of encapsulation and data-hiding in a structure make it far less robust than a well-designed class would be, with little or no difference in terms of memory consumption. Encapsulation comes into its own when classes become highly-complex (classes within classes) as each class is responsible only for its own data, not the classes it contains. Structures can be just as complex, but because they don't have the safeguards that can built into classes, it only takes one errant function to unwittingly invalidate data. A well-designed class ensures data validity at all times.

What are the symbols used in flowchart?

There are many symbols used in flowcharting. A flowchart is basically a diagram that shows the steps of a process (or algorithm), connected with arrows to help in showing the order of the steps.

First, think in terms of a list of the "types" of symbols. One such type is "arrows". "Arrows" would have many different symbols associated with it.

  • Start and end symbols
  • Arrows
  • Generic processing steps
  • Subroutines
  • Input/Output
  • Prepare conditional
  • Conditional or decision
  • Junction symbol
  • Labeled connectors
  • Concurrency symbol

This list is certainly not all-inclusive, as there are many types of flowcharts, each with its own special application. The list above is from "older basic computer science textbooks," so it has many types of symbols related to computer processes.

So we conclude that there really is no such thing as a single list of symbols. But don't give up!

The most commonly used symbols are:

  • START/END Usually a circle, or an elongated circle, or an oval. It indicates the starting point or ending point of a set of processes and decisions.
  • RECTANGLE Used to show where there is an action to be done (or an instruction to be followed).
  • DIAMONDS Used to show there there is a decision to be made.

A program written in a high-level programming language is called?

the program written in high level language is called "source program"

Why computer understand only 0 or 1?

It is understood that programming languages are used to create programs and a program is a sequence of instructions written to perform a specified task with a computer.The important thing to be noted is - there are different tasks and different types of tasks that are to be performed with a computer and thus the facilities offered by a single programming language is not enough to accomplish all those tasks.

In other words the features or purpose of one programming language differs from others (for example HTML is used to create websites and C or Shell programming can be used for system programming). Different programming languages are also used in different platforms to perform the same task (for example Visual C# or Visual C++ can be used for creating an application in Windows but Objective C is used to create the same application in Mac OS X).So different programming language are used to create program to perform different types of tasks due to limitations in the facilities offered by a single programming language.

Regardless of what programming language has been used, the particular compiler for that programming language compiles the program and creates its equivalent executable code(.exe file) in machine language(0 and 1), which the computer understands.

Program to drow graphical circle in c?

Standard C does not include any graphical functions thus there is no standard method for drawing circles. For that you will need a graphics library suited to your specific hardware and operating system. Specific methods will vary according to which library you use, however there are also generic library's available depending on your hardware's capabilities. Consult your library's documentation; there will typically be simple examples to demonstrate the library's core features, including drawing circles.

What are the striking features of OOP?

the list is as follows with the description :-

; Class : Defines the abstract characteristics of a thing (object), including the thing's characteristics (its attributes, fields or properties) and the thing's behaviors (the things it can do, or methods, operations or features). One might say that a class is a blueprint or factory that describes the nature of something. For example, the class Dog would consist of traits shared by all dogs, such as breed and fur color (characteristics), and the ability to bark and sit (behaviors). Classes provide modularity and structure in an object-oriented computer program. A class should typically be recognizable to a non-programmer familiar with the problem domain, meaning that the characteristics of the class should make sense in context. Also, the code for a class should be relatively self-contained (generally using encapsulation). Collectively, the properties and methods defined by a class are called members. ; Object : A pattern (exemplar) of a class. The class of Dog defines all possible dogs by listing the characteristics and behaviors they can have; the object Lassie is one particular dog, with particular versions of the characteristics. A Dog has fur; Lassie has brown-and-white fur. ; Instance : One can have an instance of a class or a particular object. The instance is the actual object created at runtime. In programmer jargon, the Lassie object is an instance of the Dog class. The set of values of the attributes of a particular object is called its state. The object consists of state and the behaviour that's defined in the object's class. ; Method : An object's abilities. In language, methods (sometimes referred to as "functions") are verbs. Lassie, being a Dog, has the ability to bark. So bark() is one of Lassie's methods. She may have other methods as well, for example sit() or eat() or walk() or save_timmy(). Within the program, using a method usually affects only one particular object; all Dogs can bark, but you need only one particular dog to do the barking. ; Message passing : "The process by which an object sends data to another object or asks the other object to invoke a method." [2] Also known to some programming languages as interfacing. For example, the object called Breeder may tell the Lassie object to sit by passing a "sit" message which invokes Lassie's "sit" method. The syntax varies between languages, for example: [Lassie sit] in Objective-C. In Java, code-level message passing corresponds to "method calling". Some dynamic languages use double-dispatch or multi-dispatch to find and pass messages. ; Inheritance : "Subclasses" are more specialized versions of a class, which inherit attributes and behaviors from their parent classes, and can introduce their own. : For example, the class Dog might have sub-classes called Collie, Chihuahua, and GoldenRetriever. In this case, Lassie would be an instance of the Collie subclass. Suppose the Dog class defines a method called bark() and a property called furColor. Each of its sub-classes (Collie, Chihuahua, and GoldenRetriever) will inherit these members, meaning that the programmer only needs to write the code for them once. : Each subclass can alter its inherited traits. For example, the Collie class might specify that the default furColor for a collie is brown-and-white. The Chihuahua subclass might specify that the bark() method produces a high pitch by default. Subclasses can also add new members. The Chihuahua subclass could add a method called tremble(). So an individual chihuahua instance would use a high-pitched bark() from the Chihuahua subclass, which in turn inherited the usual bark() from Dog. The chihuahua object would also have the tremble() method, but Lassie would not, because she is a Collie, not a Chihuahua. In fact, inheritance is an "a... is a" relationship between classes, while instantiation is an "is a" relationship between an object and a class: a Collie is a Dog ("a... is a"), but Lassie is a Collie ("is a"). Thus, the object named Lassie has the methods from both classes Collie and Dog. : Multiple inheritance is inheritance from more than one ancestor class, neither of these ancestors being an ancestor of the other. For example, independent classes could define Dogs and Cats, and a Chimera object could be created from these two which inherits all the (multiple) behavior of cats and dogs. This is not always supported, as it can be hard both to implement and to use well. ; Abstraction : Abstraction is simplifying complex reality by modelling classes appropriate to the problem, and working at the most appropriate level of inheritance for a given aspect of the problem. : For example, Lassie the Dog may be treated as a Dog much of the time, a Collie when necessary to access Collie-specific attributes or behaviors, and as an Animal (perhaps the parent class of Dog) when counting Timmy's pets.

Abstraction is also achieved through Composition. For example, a class Car would be made up of an Engine, Gearbox, Steering objects, and many more components. To build the Car class, one does not need to know how the different components work internally, but only how to interface with them, i.e., send messages to them, receive messages from them, and perhaps make the different objects composing the class interact with each other. ; Encapsulation : Encapsulation conceals the functional details of a class from objects that send messages to it. : For example, the Dog class has a bark() method. The code for the bark() method defines exactly how a bark happens (e.g., by inhale() and then exhale(), at a particular pitch and volume). Timmy, Lassie's friend, however, does not need to know exactly how she barks. Encapsulation is achieved by specifying which classes may use the members of an object. The result is that each object exposes to any class a certain interface - those members accessible to that class. The reason for encapsulation is to prevent clients of an interface from depending on those parts of the implementation that are likely to change in future, thereby allowing those changes to be made more easily, that is, without changes to clients. For example, an interface can ensure that puppies can only be added to an object of the class Dog by code in that class. Members are often specified as public, protected or private, determining whether they are available to all classes, sub-classes or only the defining class. Some languages go further: Java uses the default access modifier to restrict access also to classes in the same package, C# and VB.NET reserve some members to classes in the same assembly using keywords internal (C#) or Friend (VB.NET), and Eiffel and C++ allow one to specify which classes may access any member. ; Polymorphism : Polymorphism allows the programmer to treat derived class members just like their parent class' members. More precisely, Polymorphism in object-oriented programming is the ability of objects belonging to different data types to respond to method calls of methods of the same name, each one according to an appropriate type-specific behavior. One method, or an operator such as +, -, or *, can be abstractly applied in many different situations. If a Dog is commanded to speak(), this may elicit a bark(). However, if a Pig is commanded to speak(), this may elicit an oink(). They both inherit speak() from Animal, but their derived class methods override the methods of the parent class; this is Overriding Polymorphism. Overloading Polymorphism is the use of one method signature, or one operator such as "+", to perform several different functions depending on the implementation. The "+" operator, for example, may be used to perform integer addition, float addition, list concatenation, or string concatenation. Any two subclasses of Number, such as Integer and Double, are expected to add together properly in an OOP language. The language must therefore overload the addition operator, "+", to work this way. This helps improve code readability. How this is implemented varies from language to language, but most OOP languages support at least some level of overloading polymorphism. Many OOP languages also support Parametric Polymorphism, where code is written without mention of any specific type and thus can be used transparently with any number of new types. Pointers are an example of a simple polymorphic routine that can be used with many different types of objects.[3] ; Decoupling : Decoupling allows for the separation of object interactions from classes and inheritance into distinct layers of abstraction. A common use of decoupling is to polymorphically decouple the encapsulation, which is the practice of using reusable code to prevent discrete code modules from interacting with each other. However, in practice decoupling often involves trade-offs with regard to which patterns of change to favor. The science of measuring these trade-offs in respect to actual change in an objective way is still in its infancy. Not all of the above concepts are to be found in all object-oriented programming languages, and so object-oriented programming that uses classes is called sometimes class-based programming. In particular, prototype-based programming does not typically use classes. As a result, a significantly different yet analogous terminology is used to define the concepts of object and instance.

contact me.............. oopsanuj@yahoo.com

What is Ergonomics of a computer?

Ergonomics is the science of designing safe and comfortable machines for humans. In computers, it plays an important role in the design of monitors and keyboards to avoid cumulative trauma disorders or repetitive stress injuries.

What does kl mean in text language?

Kl is an abbreviation for the word Cool. An example could be this.

Bob: Hey Dave, i completed the task!

Dave: Kl.

Write a shell program to generate fibnacci series using while loop?

//WAP to print fibonacci series using do-while loop.?

using System;

class Fibonacci

{

public static void Main()

{

int a=1,b=1;

int sum=0;

Console.Write("Enter Limit:");

int n=Int32.Parse(Console.ReadLine());

Console.Write(a);

Console.Write(b);

do

{

sum=a+b;

a=b;

b=sum;

Console.Write(sum);

}

while(sum<n);

}

}

By-Vivek Kumar Keshari

Examples of procedural programming language?

  1. ABC
  2. Ada
  3. Algol 60
  4. Algol 68
  5. APL
  6. Arc
  7. Assembly
  8. Awk
  9. BASIC
  10. Batch
  11. BCPL
  12. Befunge
  13. BETA
  14. C
  15. C++
  16. C--
  17. C# (pronounced C-sharp)
  18. CHILL
  19. Clipper
  20. Cobol
  21. CobolScript
  22. Component Pascal
  23. Cyclone
  24. D
  25. DATABUS
  26. Euphoria
  27. Forth
  28. Fortran
  29. Free Pascal
  30. GNU Pascal
  31. Icon
  32. IDL
  33. Jal
  34. JavaScript
  35. Jovial
  36. Lagoona
  37. Leda
  38. Limbo
  39. Lua
  40. m4
  41. Maple
  42. Mathematica
  43. MATLAB
  44. Modula-2
  45. Modula-3
  46. Mumps
  47. Oberon
  48. Objective Caml (OCaml)
  49. Occam
  50. Oz-Mozart
  51. Pascal
  52. Perl
  53. PHP
  54. PL
  55. PL/1
  56. Pliant
  57. PL/SQL
  58. PostScript
  59. PowerBuilder
  60. Proteus
  61. REBOL
  62. Rexx
  63. S-Lang
  64. Small C
  65. Snobol
  66. Tcl-Tk
  67. T3X
  68. VBA
  69. Visual Basic
  70. Visual DialogScript
  71. Yorick

Note: Some of these languages, such as PHP, Perl, Caml/OCaml, and IDL also support object oriented programming. Others on the list (C++, JavaScript, C# ) are primarily object-oriented languages which can also (though less commonly) be used to program procedurally.

Some are macro or scripting languages (Rexx, Awk, m4) which, while they do support some procedural concepts, aren't really procedural languages, but rather interpreted streams.

Also note that Assembly is NOT a high-level language, and generally is not considered a procedural language, as it doesn't have enough abstraction.

Finally, traditional COBOL is NOT a procedural language (in fact, one of the long-standing criticism of it is that it lacks any structured programming characteristics). Current-day COBOL has some ability to use procedural programming concepts, but, overall, should not be considered a real procedural language. SNOBOL is similar, in that the original version were certainly not procedural in nature, but modern versions are much more structured programming friendly (and can be considered a procedural language).

Is NET in support of object oriented language?

Yes, every language supported by Microsoft and on the .NET framework is an object oriented language. (OOP)