What are the two parts of class specification in c plus plus programming?
There are more than two, but the class name and interface would be the minimum specification for any class. The interface can be further divided into public, protected and private access, each of which may contain member methods and/or member variables, which may themselves be static and/or non-static. The last part of the specification are the friend declarations, if required.
Both questions really boil down to the difference between a stack and a queue, so let's deal with that first. A stack is used when you want a last-in, first-out collection (LIFO), like a stack of plates; the last plate you place on the stack is the first to come off the stack. A queue is a first-in, first out collection (FIFO); the first person in a queue is the first to be served.
Secondly, we would never use an array for a stack or a queue. Arrays must be resized dynamically, both to cater for new elements and to remove redundant elements. When catering for a new element, it may be necessary to reallocate the entire array because arrays must reside in contiguous memory. We can alleviate some of this burden by allocating more elements than we actually need, but this wastes precious memory unnecessarily. Alternatively, we can use a two-dimensional array to allocate non-contiguous blocks of memory (which is important when the array is large), but it still wastes memory unnecessarily.
Linked lists are the optimum model for both stacks and queues as the nodes need not reside in contiguous memory and memory can be allocated and deallocated on a per-node basis with minimum impact on performance and memory consumption. While it is true some additional memory is required per-node to cater for each node pointing to the next, there is no redundant memory. And while arrays do allow constant-time random access to any element, stacks and queues do not require random access.
The main feature of a stack is that we require constant time access to the head of the stack. Insertions and extractions are made only to the head of the stack, therefore we need only maintain one pointer to the head of the stack. When a new node is inserted, its next node points to the existing head of the stack (which may be NULL if the stack is empty), and then the head pointer points to the new node. When the head node is extracted, its next node (which may be NULL) becomes the new head pointer.
The main feature of a queue is that we require constant time access to both the head and the tail. Insertions occur at the tail and extractions at the head, therefore we need two pointers, one at the head node, the other at the tail node. Initially both point to NULL. When a new node is inserted and the tail is NULL, both the head and tail point to the new node, otherwise the tail node points to the new node and the new node becomes the tail. The tail node always points to NULL. Extracting the head node is the same as in a stack, except the tail node is set to NULL whenever the head is set to NULL.
To fully address the question, let's consider stacks and queues using arrays. We'll ignore the resizing issues simply by assuming that there are initially 10 unused elements, and whenever there are fewer than 5 unused elements the array will be resized by an extra 10 elements, and reduced by 10 elements whenever there are more than 15 unused elements. Thus there will always be at least 10 elements. There are better methods than this, but it will suffice for the purpose of this answer.
Since insertions at the start of the array would require us to copy all elements into the next element to make room for the insertion, all insertions will occur at the end of the array in the first unused element. Therefore we must maintain a zero-based index of the first unused element (the tail). When we insert an element at that index, the tail is simply incremented.
For the stack, extractions also occur at the tail. Therefore, if the tail is non-zero, we simply decrement the tail and extract the element at that index. If the tail is zero, the stack is empty. Otherwise the tail tells us how many elements have been used for resizing purposes. Resizing should be done after an insertion or extraction.
For the queue, extractions occur at the head, therefore we initially point at element zero. If the head and tail are different, an item exists at the head element so we extract it and increment the head. If the head and tail are the same, then there are no elements in use so both can be reset to zero. The only real complication is in working out how many unused elements there are for resizing purposes. For this we simply subtract the head from the tail to determine how many elements are in use. This should be done prior to any insertion. If a resize is required it would be prudent to shunt all used elements to the start of the array and adjust the head and tail accordingly, then perform the insertion.
As you can appreciate, a queue is more complex than a stack when using an array, but ultimately an array is more complex than a linked list for both stacks and queues.
Why you need a for loop when you have already while loop or do while loop?
We need a for loop because the while and do-while loops do not make use of a control variable. Although you can implement a counter inside a while or do-while loop, the use of a control variable is not as self-evident as it is in a for loop. Aside from the use of a control variable, a for loop is largely the same as a while loop. However, it is quite different to a do-while loop, which always executes at least one iteration of the loop before evaluating the conditional expression. In a for and while loop, the conditional expression is always evaluated before entering the loop, which may result in the loop not executing at all.
Encapsulation.
What is the Visual C plus plus 2008 Express Serial Code?
The Express edition of C++ does not require a serial code. It is free.
Why void is used in c language?
void as function return-type means no return value
void as function parameter means no parameter
void * as pointer type means generic pointer
What are the physical attributes of all the members of the class amphibias?
Members of the class Amphibia, which includes frogs, toads, salamanders, and caecilians, typically have moist, permeable skin that allows for respiration and hydration. They possess a four-limbed body structure, although some groups like caecilians are limbless. Most amphibians undergo metamorphosis, transitioning from a larval stage with gills to an adult stage with lungs. Additionally, they usually have a strong skeletal structure adapted for both terrestrial and aquatic environments.
Factoring a quadratic expression of the form ( ax^2 + bx + c ) (where ( a \neq 1 )) typically involves methods like grouping or using the quadratic formula to find roots, as the leading coefficient complicates direct factoring. In contrast, for ( x^2 + bx + c ) (where ( a = 1 )), factoring is more straightforward, often relying on finding two numbers that multiply to ( c ) and add to ( b ). The presence of ( a ) changes the approach required, necessitating additional steps to factor out the leading coefficient or adjust the factoring process accordingly.
yes they exhibit polymorphism.. they have zooids and hydroids
What are the similarity between c and c plus plus compiler?
When Bjarne Stroustrup developed the first version of C++ in 1979 (which was originally called 'C with Classes'), his custom-built compiler did nothing more than convert his C++ source code into C-compliant code which could then subsequently be compiled by the standard C compiler to produce the required object files. Nowadays, the C++ compiler handles everything itself, but does more or less the same job, with the addition of specialised optimisation routines to produce object files efficiently, without the need to convert to an intermediate C source.
You mean an iterative function, not a recursive one. A recursive function is one that calls itself with altered arguments, typically used to implement divide-and-conquer algorithms. Since the arguments remain the same and you're not dividing the array into smaller subsets, recursion is not necessary. An iterative loop is all you need:
typedef unsigned int UINT;
const UINT CountOddNumbers( const UINT* const A, const UINT size)
{
UINT result=0;
for(UINT i=0; i<size; ++i)
result += A[i]&1;
return(result);
}
Note that this function is not safe, since size is not guaranteed to reflect the actual size of A. In C++, it's better to use a vector object, since vectors encapsulate the actual size of the embedded array:
const UINT CountOddNumbers( const std::vector<UINT> A)
{
UINT result=0;
for(UINT i=0; i<A.size(); ++i)
result += A[i]&1;
return(result);
}
What does the Calendar class provide in java?
It depends on which specific class of Calendar you are referring to. Different IDEs provide different implementations. Consult your IDE's documentation for more specific information.
In general, you can expect to construct a calendar with a date in a variety of formats and return the individual year, month, day, as well as perform date calculations such as adding weeks and days to a date, or determining the name of a particular date (Sunday, Monday, etc), or working out how many days there are between two dates. Calendars may also support hours, minutes and seconds, fully-encapsulating all the things you might expect to do with dates and times.
Some implementations provide the back-end functionality of a more graphical date-picker, allowing you to select a particular date from a drop down calendar month, while others can be completely abstract, expecting you to derive your own classes to leverage the underlying functionality in any way you see fit.
How do you use a C-continue statement in a block- without any looping or conditional statements?
In the C language, the continue statement can only be used within a loop (for, while, or do). Upon execution, control transfers to the beginning of the loop.
What is the function of symboland in C programming?
The symbol and (ampersand, &) in C and C++ programming is the bitwise inclusive or operator. If there are two ampersands (&&) it is a relational inclusive or operator. As a unary operator, it means to take the address of something. In C++, it can also be overridden in a class method to mean nearly anything else.
You declare a class as follows:
class MyClass
{
//some stuff here...
}
You create an object as follows:
MyClass object;
This is how you create classes and objects in C++.
What is mean by complexity in c plus plus programming?
Complexity is a measure of how long an algorithm is expected to take and/or how much space is required to complete the task. It is not specific to C++ -- the language is immaterial -- it only applies to algorithms. Complexity is often expressed in big O notation, where O(1) is constant time (the best that can be expected of any algorithm).