What kinds of game-related classes would be best implemented as abstract?
That would depend on what type of game you are developing. Unlike a concrete class which can be instantiated in its own right, an abstract class can only be instantiated through derivation. In other words, an abstract class can only be used as a base class, and is known as an abstract base class for that reason. We can also refer to them as abstract data type, given a class is also a type.
We typically use an abstract base class to define a common interface for all its derivatives. If we need to divide the interface to cater for specialisations, we can derive intermediate base classes from the abstract base class. In this way we do not pollute the common base class with uncommon virtual methods.
Abstract base classes typically have no data members and thus incur no memory overhead. However, if data members are required, they should be kept to a minimum and should only be declared if essential to the derivatives. Data members that are essential to some but not all derivatives should be placed in the appropriate intermediate class instead.
In a game (or indeed any program) we might have many objects of many different types. However, objects that have a common public base class (including abstract base classes) can be treated as being "of the same type" (the common base). For instance, we might define an abstract Object base class such that all classes that publicly derive from the Object class can be treated as being of the same type (an Object).
In a game we typically have objects that cannot be moved (static objects) and objects that can be moved (non-static). We can separate the two types of object by deriving Static and Nonstatic abstract base classes from our common Object class. We can then derive further intermediate classes from these two classes to cater for all the different types of object in our game. For instance, an armoury usually provides a choice of weapon and allows the user to select a primary and secondary weapon, thus we can derive a common Weaponabstract base class from our Nonstatic abstract base class, and then derive concrete (specific) weapons from the Weaponclass.
What does gmon.out do in a program?
gmon.out is used by the GNU profiling tool (gprof). It is written in the program's working directory just before the program you are profiling terminates normally. If the program terminates abnormally (via a low-level _exit or an unhandled exception) the file is not written.
The gprof syntax is:
gprof options executable-file gmon.out bb-data [yet-more-profile-data-files...] [> outfile]
Synchronous Transport Module (STM) currently has levels 1, 4, 16, 64, 256 and 1024 where each level corresponds to a specific bit rate. The STM frame is considered as the basic transmission format for the Synchronous Digital Hierarchy (SDH) technology. These STM frames are byte-oriented arranged in a row and column manner.
10 80 03 09 55 32 100 07 05 02 12 65 63 22 92
10 is found at index 0
05 is found at index 8
76 is not found
85 is not found
200 is not found
How does a linked list differ from stack and queue?
A linked list is a data structure that allows bi-directional traversal with constant-time access to both the head and the tail of the list. Elements may be pushed and popped from anywhere in the list.
A stack is a structure where elements are pushed and popped only at the head of the stack.
A stack is typically implemented using an array (either fixed-length or variable-length) where elements are pushed and popped from the end of the array (you need to keep track of where the last-used element is). However, a stack can also be implemented as a singly-linked list, pushing and popping at the head of the list.
Stacks generally do not allow traversal of the elements.
You'll need to run an operating system that supports multiple logins and use a video card that allows multiple terminals. Some versions of Linux and Unix allow "virtual" terminals.
What is the three major parts of a pascal program?
-var,const,uses declaration part
could start with uses in case of a declaration for a libr ex. (uses crt)
var,const refers to those used in the main probram
-functions,procedures declaration part
declaration of the function/procedure + content ex.
(function one(x:integer):integer;
var y:integer;
begin
......
one=....(integer expresion for return value);
......
end;)
the procedures don't have any return value (:integer)
-main program
begin
........
end.
What is Multicore Programming?
A programming technique that perform computations parallelly on more than one processor(core) without changing overall funcationality of the serial program.
When inserting or extracting at the end of a singly-linked list or at the beginning or end of a doubly-linked list, the complexity is constant time. Inserting or extracting in the middle of a list has linear complexity, with best case O(1) when the insertion or extraction point is already known in advance and a worst case of O(n) when it is not.
Are FIFO and LIFO forms of access used to add and remove nodes from queue?
No. FIFO is a first-in, first-out structure, and this describes how nodes are inserted and extracted from a queue. That is, new nodes are inserted at the back of the queue while existing nodes are extracted from the front of the queue. In other words, nodes are processed on a first-come, first-served basis.
However, LIFO is a last-in, first-out structure and this describes how nodes are inserted and extracted from a stack. You can think of a stack as being like a stack of plates such that the top-most plate is always the first to be extracted while new plates are placed on top of existing plates. Stacks are typically used in backtracking algorithms because nodes are extracted in the reverse order they were inserted upon the stack.
What are the advantages and disadvantages of event driven programming?
Advantages: Ease of development, Flexibility, Simplicity and suitable for graphical interfaces. Disadvantages: Complex, Hard to control, Time consuming to get event loops and event handlers running.
What is the difference between a function pointer and a pointer to a function?
A pointer to a function is the memory address that stores the address of a function, while the pointer itself is a function pointer.
A pointer to a function might be defined as "int (*pf)(int, int);", while to actually point to the function, you would use a function pointer, such as "pf = &func;".
What are the differences of the time sharing and multiprogramming?
Time-sharing is an approach to interactive computing in which a single computer is used to provide apparently simultaneous interactive general-purpose computing to multiple users by sharing processor time. So basically, time sharing is for multi-user computer systems. Multiprogramming is A form of processing in which a computer holds more than one program in memory and works on them in round-robin fashion that is, by sharing out the processor's time so that each program receives some attention some of the time. This way of working is in contrast to using the processor to run one program at a time.
Difference between insertion and selection sort?
Before we examine the differences, let us examine the implementations. The code that follows is written in C++, but can be easily adapted to other languages.
Firstly, let us assume we have an array of num elements (we'll use integers here, but typically you will use pointers to maintain efficiency):
int array[num];
A selection sort has the following nested loop structure:
for( int outer=0; outer < num-1; ++outer )
{
int min = outer;
for( inner=outer+1; inner < num; ++inner )
{
if( array[inner] < array[min] )
min = inner;
}
if( min != outer )
swap( array[min], array[outer] );
}
Whereas an insertion sort has the following nested loop structure:
for( index=1; index < num; ++index )
{
value = array[index];
hole = index;
while( hole > 0 && value < array[hole-1] )
array[hole] = array[--hole];
array[hole] = value;
}
Although both algorithms split an array into two subsets (a sorted subset to the left and an unsorted subset to the right) and both move one element from one set to the other on each iteration of the outer loop, the selection sort begins with an empty sorted subset while the insertion sort begins with a sorted subset of one element (any array with only one element can always be regarded as being sorted).
In both cases, the outer loop keeps track of the initial index of the current unsorted subset and both perform a complete traversal of the unsorted subset. However selection sort stops when there is only one unsorted element left, which automatically becomes the largest value in the sorted set and therefore doesn't need to move, whereas insertion sort traverses the entire unsorted subset.
The key difference is in the inner loops. With selection sort, the inner loop skips the first unsorted element and traverses the remainder of the unsorted subset locating the index of the lowest value (recorded by min). At the end of the inner traversal, if min is not the same as the outer loop index then the values are swapped. Thus the sorted subset gains a new element containing the next largest value on each iteration, beginning with the lowest value.
With insertion sort, the outer loop extracts the first unsorted element's value and stores its index (hole). There isn't really a hole in the array, it's simply a marker to determine where the extracted value will be inserted. The inner while loop then traverses the sorted subset. On each iteration, if the hole marker is non-zero and the value is less than the value of the element to the left of the hole marker, then that element's value is copied into the hole to its right and the hole marker moves left. When the inner loop ends, the hole marker denotes where the extracted value should be placed. Thus if the extracted value is greater than or equal to the largest sorted value, then the value doesn't move (it was already sorted), otherwise it is inserted into its correct position within the sorted subset.
It can be proved that although selection sort only requires one swap at most for every iteration of the outer loop, it must perform (num-1)! comparisons in total (that is, for num=6 there are 5+4+3+2+1 comparisons in total). It should be noted that every swap incurs three copy processes, however a single copy takes less time than a single comparison.
By contrast, insertion sort stops comparing when the insert point is located, thus, on average, there will be fewer comparisons than (num-1)!. However, while every iteration of the outer loop incurs two copy processes even if the current element doesn't need to move, and additional copy processes for each movement of the hole marker, it's wrong to assume selection sort is always faster. On average, it is actually slower.
Looking at the worst case example, let us suppose the array is in reverse order. Selection sort requires (num-1)! comparisons no matter what and will also incur n-1 swaps in total (which is 3(num-1) copies in total). By contrast, insertion sort also requires (num-1)! comparisons but requires 2(num-1)+(num-1)! copy processes. The end result is that selection sort performs slightly better, and will improve as the array size increases.
Another worst case example is the already-sorted array. Again, selection sort requires (num-1)! comparisons but no swaps at all. However, insertion sort only requires num-1 comparisons and 2(num-1) copies. In this case, insertion sort performs slightly better, and will improve as the array size increases.
While both algorithms are fairly efficient when dealing with small arrays (typically up to 20 elements), with insertion sort performing better on average, they are highly inefficient when dealing with larger arrays. For this you need recursive, logarithmic, divide-and-conquer algorithms, such as quicksort, which are capable of sorting num elements with only (log num) comparisons. However, these algorithms don't perform well with smaller subsets, so it pays to combine the two into a hybrid algorithm. That is, when a logarithmic algorithm reduces a subset to 20 elements or less, then that subset can be sorted far more efficiently with an insertion sort.
How do you calculate size of an unsized array?
In Java, all arrays have a finite size. Even if you did not initialize an array to a particular size (say the array was being passed into a method), some other part of the program did. Because of this, the length of an array can always be accessed via the .length parameter.
Example:
int[] arr = new int[5];
System.out.print(arr.length); //5
public void k(int[] arr)
{
System.out.print(arr.length) //arr will always have a finite size
}
Difference between a class and a struct?
Examples of Avogadro's law in everyday life?
Avogadro's Law: Doubling the number of moles of gas doubles its volume, if temperature and pressure aren't changed.
Explain The merits of using a deque to implement a stack in data structure?
Explain The merits of using a deque to implement a stack in data structure
What are the first parameters of stream insertion and stream extraction for operator function?
The first argument of the insertion and extraction operators is always a non-const reference to the stream being operated upon. The second argument is an object of the type being inserted or extracted. For insertions, always use a constant reference to the type. For extractions, use a non-const reference. The return value is always a reference to the first argument. For any given type, T, the following functions may be defined:
std::ostream& operator<< (std::ostream& os, const T& data)
{
// ...
return os;
}
std::istream& operator>> (std::istream& is, T& data)
{
// ...
return is;
}
The implementation of the output stream insertion operator must convert type T to a character sequence.
The implementation of the input stream extraction operator must convert a character sequence to a type T.
Both operators must be declared in the global namespace, never as members of any class. However, they may be declared friends of the class declared in the second argument if (and only if) they require private access to the class representation.