What is delegation in oops concept?
Delegation allows the behavior of an object to be defined in terms of the behavior of another object.
ie, Delegation is alternative to class inheritance. Delegation is a way of making object composition as powerful as inheritance. In delegation, two objects are involved in handling a request: a receiving object delegates operations to its delegate. this is analogous to the child classes sending requests to the parent classes.
Example in a Java/C# like language class A {
void foo() {
this.bar() // "this" is also known under the names "current", "me" and "self" in other languages
}
void bar() {
print("a.bar")
}
}
class B {
private A a; // delegationlink
public B(A a)
{
this.a = a;
}
void foo() {
a.foo() // call foo() on the a-instance
}
void bar() {
print("b.bar")
}
}
a = new A()
b = new B(a) // establish delegation between two objects
Calling b.foo()
will result in a.bar being printed, since class B "delegates" the method foo() to a given object of class A.
WAP to interchange the value of two variable without third variable?
Ellipses (...) used to emulate indentation... swap (int *i1, int *i2) { /* only works for integers, i1 != i2 */
... *i1 = *i1 ^ *i2;
... *i2 = *i1 ^ *i2;
... *i1 = *i1 ^ *i2;
}
What is C program pattern 12321 121 1?
/*determine the pattern 1234321*/
#include<stdio.h>
#include<conio.h>
main()
{
int i, j;
for (i=1; i<=7; i++)
{
if (i<5)
{
j=i;
printf("\n %d", j);
}
else
{
j=8-i;
printf("\n %d", j);
}
}
getch()
}
When calling a function that has multiple parameters can you list the arguments in any order?
No. C function argument are positional.
What is difference between visual c plus plus and mfc?
That is like comparing apples and trees...
Visual C++ is a development environment that allows one to program in C++, which is a language.
MFC (Microsoft Foundation Classes) is a library to allows one to use C++ to write MS Windows programs using a particular set of API-like calls. It is a library, not a language.
The two cannot really be compared, as they are too different in scope.
What is the console operator basic requirement assessment test?
The Console Operator Basic Requirement Assessment Test is designed to evaluate the skills and competencies of individuals seeking positions as console operators, typically in fields like telecommunications or energy management. The test assesses knowledge in areas such as equipment operation, troubleshooting, safety protocols, and communication skills. It aims to ensure that candidates possess the foundational abilities necessary to perform effectively in high-stakes environments. Passing this assessment is often a prerequisite for further training or employment in related roles.
How do you search for an element in unsorted array?
Let's use integers as an example.
int elementToFind; // the element we want to search for
int[] elementArray; // the array we want to search through
boolean found = false; //boolean flag to indicate if we found the element or not
for(int i = 0; i < elementArray.length; ++i) {
if(elementArray[i] == elementToFind) {
// we found the element at index i
// do whatever you want to do with this information
found = true;
}
//if found is still false so it means this element is not found
if(!found) {
//the element is not found in the array
}
}
Write a program in c plus plus for finding the sum of first 10 even numbers?
int i, sum = 0;
for (i=0; i<20; i+=2) sum+=i;
What is the meaning of statement p z in c-language?
The statement p z in c code is a syntax error. The p is an identifier, and so is the z. They cannot be typed tyogether like that unless an operator is placed between them, such as p + z.
A checkout operator, often referred to as a cashier, is responsible for processing customer transactions at retail establishments, such as grocery stores or supermarkets. Their primary duties include scanning items, handling payments, issuing receipts, and providing customer service. Checkout operators also play a role in maintaining a clean and organized checkout area and may assist with inventory management or restocking items as needed. Strong interpersonal skills and attention to detail are essential for this role.
How do you use pragma startup preprocessor directive?
Syntax:
==========================================
==========================================
Suppose you want to print a Character for 50 (or so) Times before entering Main ().
Here the code goes:
#include "stdio.h"
#include "conio.h"
void PrintChars ()
{
char cChar;
int iTimes, iLoop;
printf ("\n Enter a Character to print: ");
scanf ("%c", &cChar);
printf ("\n How many times you want \'%c\' to print", cChar);
scanf ("%d", iTimes);
for ( iLoop=1; iLoop <= iTimes; iLoop++)
printf ("%c", cChar);
}
#pragma startup PrintChars
void main ()
{
printf ("Entering Main()...\n");
getch();
printf ("Exit from Main()...\n");
getch();
}
Difference between arrays and linked list?
As I know the search method depends on your(programmer's) logic. In sequential search it will be better to stop the search as soon as search value encounters or if search value is not in the array then it should stop at the end.
Find advantage and disadvantage of conditional operator?
I do not think there are disadvantages for conditional operators. Other people will think differently.
Most importantly, what is the answer your teacher want you to give. Read your course material or ask your teacher, is the best advice I can give you.
Implementation of priority Queue using Heap?
Now let's consider how to implement priority queues using a heap. The standard approach is to use an array (or an ArrayList), starting at position 1 (instead of 0), where each item in the array corresponds to one node in the heap:
Note that the heap's "shape" property guarantees that there are never any "holes" in the array.
The operations that create an empty heap and return the size of the heap are quite straightforward; below we discuss the insert and removeMax operations.
Implementing insertWhen a new value is inserted into a priority queue, we need to:How Write a c program to find and replace a string in the given text?