C plus plus programming language program for hybrid inheritance?
There's no such thing as hybrid inheritance in C++. Hybrid inheritance implies two or more different types of inheritance but there are really only two types of inheritance in C++ and they are mutually exclusive: single inheritance and multiple inheritance.
A class that inherits directly from one class uses single inheritance.
A class that inherits directly from two or more classes uses multiple inheritance.
The only way to combine these two inheritance patterns is through multi-level inheritance, where a class inherits directly from one or more derived classes. However, whenever we create a derivative, we're only concerned with the base class or classes we are directly inheriting from. The fact they may or may not be derivatives themselves is largely irrelevant from the viewpoint of the derivative. Indeed, the only time we really need to consider one of the lower bases classes is when we need to explicitly invoke a virtual function of that particular class, as opposed to implicitly invoking the most-derived override of that function as we normally would. However, this is really no different to a derived class override invoking its direct base class method.
Virtual base classes are also thought of as being a type of hybrid inheritance, however virtual base classes merely determine which class is responsible for the construction of those classes. Normally, a derived class is responsible for the construction of all its direct base classes, which must be constructed before the derived class can begin construction. In turn, those base classes are responsible for the construction for their own base classes. In this way, derived classes are automatically constructed from the ground up, base classes before derived classes, in the order declared by the derived class.
For example, consider the following hierarchy:
struct X {};
struct Y : X {};
struct Z : Y {};
Z inherits from Y so in order for a Z to exist we must first construct a Y. By the same token, Y inherits from X so in order for a Y to exist we must first construct an X. Thus when we initiate construction of a Z, that initiates construction of a Y which initiates construction of an X.
Now consider a virtual base class:
struct X {};
struct Y : virtual X {};
struct Z : Y {};
The construction sequence is exactly the same as before (X before Y before Z), the only difference is that when we now instantiate a Z, as the most-derived class in the hierarchy it becomes responsible for the construction of the virtual X. Z is also (still) responsible for the construction of a Y, but Y no longer needs to construct an X because a (virtual) X already exists.
Virtual base classes become more relevant in multiple inheritance, where two or more base classes share a common base class:
struct W {};
struct X : virtual W {};
struct Y : virtual W {};
struct Z : X, Y {};
Here, Z uses multiple inheritance from X and Y. Both X and Y use single inheritance from W. Without virtual inheritance, Z would inherit two separate instances of W, specifically X::W and Y::W. But by declaring W as a virtual base of X and Y, the most-derived class, Z, becomes responsible for the construction of W, as well as its direct base classes, X and Y. Neither X nor Y need to construct a W because a W will already exist. Thus X::W and Y::W now refer to the same instance of W.
Note that we do not need to write any additional code for this mechanism to work. The virtual keyword alone is all we need. Even if X or Y provided explicit initialisation of W, those initialisers would be ignored by the compiler since initialisation of W is automatically the responsibility of the most-derived class. The only time those explicit initialisers would be invoked is if we explicitly instantiate an instance of X or Y, because then X or Y become the most-derived class.
Program for count the total number of node in binary tree?
The number of nodes in any subtree is the number of nodes in its left subtree, plus the number of nodes in its right subtree, plus one, so you can use a recursive algorithm and start at the root.
unsigned intbinarytree_count_recursive(const node *root)
{
unsigned int count = 0;
if (root != NULL) {
count = 1 + binarytree_count_recursive(root->left)
+ binarytree_count_recursive(root->right);
}
return count;
}
What are range of character data type in c plus plus?
The range of character data types in C++ is the set of characters in the host's character set.
It is inappropriate to consider the numerical range of such things as characters, because that depends on the particular codeset involved, such as ASCII, EBCDIC, UNICODE, KANJI, etc. Doing that leads to non-portable code, and lazy programming practices. Do not write code that depends on the collating sequence of the character set, or the numerical difference between two characters.
Type char can be signed or unsigned, the value range is -128..127 or 0..255 respectively.
Find the prime nofrom one to ten using 'for' or 'while' loop in c language?
I don't know C, but the process of finding a prime is the same in any programming language # Use a sequential list of numbers from two to some maximum. (10 in your case) # Delete all multiples of 2 greater than 2 from the list. # The next lowest, uncrossed off number in the list is a prime number. # Delete all multiples of this number from the list. This can be started at the square of the number, as lower multiples have already been crossed out in previous steps. # Repeat steps 3 and 4 until you reach a number greater than the square root of the highest number in the list; all the numbers remaining in the list are prime
C is often referred to as a high level assembly language. There are few languages with less overhead (in terms of run-time support). When you are coding to meet certain constraints (performance, real-time time constraints, memory limitations, etc.), C can provide you with code that meets those constraints but which is also (relatively) portable.
Note: Of course C and Assembly are not similar at all.
Write a recursive function to find sum of even numbers from 2 to 50 using C?
I can't imagine a useful reason to have a recursive function to find this, but here you go:
int sumEvens(int start, int end) {
// end condition
if (start > end) {
return 0;
}
// correction if we start on an odd number
if (start % 2 == 1) {
return sumEvens(start + 1, end);
}
// actual work
return start + sumEvens(start + 2, end);
}
Invoke with sumEvens(2, 50) to get the sum of all even numbers in the range [2,50]
Write a programe for calculating the area of circle in C programming?
#include
#include
#include
using std::cout;
using std::cin;
using std::endl;
using std::setw();
int main()
{
const double PI = 3.14153;
double radius = 0.0;
cout << "Enter radius of circle: ";
cin >> radius;
unsigned short precision = 5;
cout << endl <<"Enter precision you want have (not more than 6 digits): ";;
cin >> precision;
cout << setw(precision) < system("PAUSE"); return 0; }
No. Main is not a keyword in C or C++. However, your program, when linked, must provide one and only one externally scoped entry point to main(). If you use main in some other context, and you do not provide one and only one entry point main(), then your program will not link nor run.
What are the various operators available in c language?
There are eight types of operators which are used in C language.These are-
1.Arithmetic operator
2.Assignment operator
3.Relational operator
4.Increment/Decrement operator
5.Bitwise operator
6.Logical operator
7.Conditional operator
8.Additional operator
1.Arithmetic operator:Arithmetic operators are mathmetical operator.These are addition,Subtraction,Multiplication and divison.
2.Assignment operator:Assignment operators are used to store the result of an expression to a variable.
Which year C language was invented?
Dennis MacAlistair Ritchie and Kenneth Lane Thompson at Bell Laboratories in 1972.
What are the different reserve words in c-language?
Reserve words, also known as keywords are words whose meaning are already defined by a compiler. C language has a total of 32 reserve words. Short, union, else, for, goto, unsigned, enum, extern, char, continue, switch, struct, typedef are some examples.
9999
Why have character range -128 to 127?
To let the very first bit (2^7) show the sign of the number: bit=1 means negative (-128..-1), bit=0 means non-negative (0..127)
00H=0
...
7fH=127
80H=-128
...
ffH=-1
Interrupt handling is performed by the operating system kernel. In the Intel IA-32 platform, for instance, it is handled at Ring-Zero.
C++ code does not normally run in the kernel. It runs in user space, such as in Ring-Three. Unless the operating system allows you to load C++ code in non pageable Ring-Zero space, you cannot write C++ programs to handle interrupts. Even if you could do so, all of the dependencies, such as libraries, would need to also be there, unless you wrote dispatch stubs to transition into and out of Ring-Zero non-pageable space.
That said, you are looking for the Device Driver Kit, or DDK. (In the Windows platform.)
How do you read line by line of a file in c program?
read, fread, fgetc, fgets, fscanf etc... use the help/manual
#include <stdio.h>
int main ()
{
int year,days,d;
printf("year?"); scanf("%d",&year);
days = 365*year + (year-1)/4 - (year-1)/100 + (year-1)/400 ;
d=days%7;//to find which day of week
if(d==1)
printf("\n\n\tmonday");
else if(d==2)
printf("\n\n\ttuesday");
else if(d==3)
printf("\n\n\twednesday");
else if(d==4)
printf("\n\n\tthursday");
else if(d==5)
printf("\n\n\tfriday");
else if(d==6)
printf("\n\n\tsaturday");
else if(d==0)
printf("\n\n\tsunday");
return(0);
}
Difference between c syntax and c syntax?
Using normal C you cannot address a bit value.
The minimum you can address is 1 byte.
using embedded C you can access even abit value
C is a widely used general purpose high level programming language mainly intended for system programming
.
Embedded C is an extension to C programming language that provides support for developing efficient programs for embedded devices
.
It is not a part of the C language
How many values can each element in a seven-element array hold?
As many as you like. It ultimately depends on the type of the array. An array of int can obviously only store one integer value per element, however an array of integer arrays would allow us to store two or more integers per element. This is precisely how multi-dimensional arrays are implemented:
int x[4][5];
Here we've declared a 4-element array where each element is an array of 5 integer elements. Thus each element of the "outer" array can hold 5 values in the "inner" arrays. In reality this is just a 20-element array with one integer per element, but because we declared it multi-dimensionally we can refer to each of the 4 "inner" arrays individually as an array in its own right.
Arrays of arrays are useful when dealing with homogeneous types, but if we need to store heterogeneous types we can use an array of structures instead:
typedef struct person_t {
char name[50];
size_t age;
} person;
person x[100];
Here we've declared an array of 100 person objects. But each person object has two member values associated with it; a name and an age:
x[0].name = "Joe Bloggs";
x[0].age = 42;
main()
{
int age[100],count=0,i;
clrscr();
for(i=0;i<100;i++)
{
printf(" enter the person age %d",i);
scanf("%d",&age[i]);
}
for(i=0;i<100;i++)
{
if(age[i]>=50 && age[i]<=60)
{
++count;
}
}
printf(" no.of persons in the age group 50 to 60 is %d",count);
getch();
}
What is an example of square array?
*SQUARE
definition- A 4-sided regular polygon with all sides equal and all internal angles 90°example- A computer screen
*SQUARE (SQUARE ROOT)
definition- A divisor of a quantity that when squared gives the quantity
example- The square roots of 25 are 5 and −5 because 5 × 5 = 25 and (−5) × (−5) = 25.
Explanation of top down marketing?
Top down marketing is a branding strategy where country strategies are based upon global branding strategies.
How to write a program in c to find the cude of a number?
You cannot multiply a number (a multiplicand) unless you know what to multiply it by (the multiplier). The result of a multiplication is the product, such that multiplicandtimes multiplier equals product.
In C programming we use the multiplication operator (binary *) to obtain the product of two scalars:
double product (double multiplicand, double multiplier) {
return multiplicand * multiplier;
}
Nothing special, try it:
void foo (int frec, int val)
{
. int x= val;
. if (frec) {
. . printf ("before recursion x=%d\n", x);
. . foo (frec-1, val+1);
. . printf ("after recursion x=%d\n", x);
. } else {
. . printf ("in recursion x=%d\n", x);
. }
}
What is an array and how do you use them in c and c plus plus?
#include<iostream>
#include<vector>
int main()
{
std::vector<int> v {1, 4, 8, 15, 23}; // initialise array with 5 elements
v.push_back (42); // add a 6th element
for (auto i : v) std::cout << i << std::endl; // print array elements
}
How do you implement queue using stack in c plus plus?
A queue in any language is a singly-linked list structure that permits new data to be inserted only at the end of a list while existing data can only be extracted from the beginning of the list. Queues are also known as a first in, first out (FIFO) structure. Unlike a standard singly-linked list, the list maintains a pointer to the last node as well as the first, in order to insert new data and extract existing data in constant time.
Variations on the queue include the priority queue which permit data to be weighted, such that data with the greatest priority is promoted to the front of the queue, behind any existing data with the same or higher priority, using an insertion sort technique. Insertion is therefore achieved in linear time rather than constant time, however extraction is always in constant time.