Explain in detail datatype supported in 'C plus plus ' language?
char: A one-byte integer with implementation-defined signedness.
signed char: A signed one-byte integer.
unsigned char: An unsigned one-byte integer.
wchar_t: A wide character of implementation-defined size and signedness.
short: A signed integer with at least 16 bits.
unsigned short: An unsigned integer with at least 16 bits.
int: A signed integer with at least 16 bits.
unsigned int: An unsigned integer with at least 16 bits.
long: A signed integer with at least 32 bits.
unsigned long: An unsigned integer with at least 32 bits.
long long: A signed integer with at least 64 bits.
unsigned long long: An unsigned integer with at least 64 bits.
float: A floating-point number with 32 bits of precision.
double: A floating-point number with 64 bits of precision.
int die = ((double)rand())*6/RAND_MAX+1; // result is 1, 2, 3, 4, 5, or 6
What does tbuffer mean in c plus plus?
There is no such keyword or data type known as tbuffer in C++. It's most likely an user-defined identifier, possibly a text buffer. But without knowing its actual type or its context it's impossible to say what it means.
How does Multiple document interface help in visual c plus plus environment?
The obvious answer is that it allows you to view more than one document or type of document at the same time using the same instance of the application. With SDI (single document interface), each document is loaded in a completely separate instance of the application. There are merits to both approaches, but in more recent times applications are more a hybrid of MDI and SDI, allowing individual documents to be completely detached from the MDI main frame. With multi-monitor desktops this becomes extremely useful as the application window no longer needs to be full-screen in order to get the best view of the documents.
How dynamic constructor create in c plus plus?
Dynamic casting is a type-safe method of casting one object type (a base class) to another object type (a derived class) in order to access methods that are specific to the derived class, but are not available to the base class. If the typecast fails for any reason, the return is NULL. If the cast is successful, the return is a pointer to the derived class.
Although there's nothing to prevent you dynamically casting objects in this way, it is considered bad programming practice, and is, in fact, wholly unnecessary. Virtual methods in the base class automatically give us access to more specific derived class methods from within the base class itself. In short, never dynamically cast an object. If a base class designed by a third-party has no suitable virtual method, then simply derive your own base class from it and provide your own virtual method.
By way of example, suppose you have a base class called animal from which you derive a cat and a dog. Cats and dogs make different sounds, so while it's tempting to create a Bark() method for the dog and a Meow() method for the cat, this only works when you actually have a pointer or a reference to a cat or a dog.
But what if you have a pointer or reference to the animal base class? Even if you know the animal is really a dog, how will you make it bark? The base class doesn't know it's really a dog, so there is no bark method to call. It may also be tempting to put both methods in the base class but, if we're not careful there's always a risk a cat will bark and a dog will meow.
So it appears the only solution is to dynamically cast the animal to a dog. If it turns out to be a cat, the result will be NULL and you'll be forced to dynamically cast a second time, this time to a cat. This doesn't sound so bad with only two animals to consider, but how about an entire zoo full of animals? Is it a lion, a tiger, a mouse, an elephant, a snake or something else entirely? Dynamic casting will get the job done, but it's a lot of work when you have to do this for every method in every derived class where cats and dogs are expected to act differently (such as Play() and DoBad()).
The correct way to deal with this is to include a pure-virtual method in the base class. All animals make a noise so simply declare a pure-virtual MakeNoise() method in the base class and implement it in each type of animal. A dog's MakeNoise() method will bark, it's Play() method will make it fetch a ball and it's DoBad() command will make it chase cars. All the things we expect of a dog.
Now when you have a pointer or a reference to an Animal, simply calling the base class method will invoke the correct override according to the actual type of animal it refers to. No need to dynamically cast, and absolutely no need to ever know what type of animal you're actually referring to. If it's a dog, it'll bark, fetch balls and chase cars. If it's a cat it'll meow, play with string and throw up in your shoes!
It's important to remember that the whole point of using virtual and pure-virtual functions is to allow the v-table (the virtual table) to determine the actual runtime type of an object and let it work out which override to call. It is not your responsibility as a programmer to force those methods out. The base class does not know and should not care whether it is a cat or a dog or a duck-billed platypus -- and nor should you! Your only concern is that the correct method be called and the v-table does that for, and a good deal more easily than dynamic casting ever can.
1. false
2. true
3. false
4. true, but that statement can be a compound statement, ie a statement-block between {}
5. false
What are Weakness of using pointer in c plus plus?
The main weakness is that the onus is primarily upon the programmer to ensure pointers are not misused, that any memory allocated to a pointer is released as soon as that memory is no longer required, and that pointers are nullified when not in use. There is no automatic garbage collection other than when a thread terminates, at which point all consumed memory is returned back to the system, however its never a good idea to rely on this. Programs with a long life-cycle must be specifically written to clean up resources behind themselves as they go, but the same should apply to any program, regardless of how trivial. It costs nothing and failure to do so is not only lazy, the consequences could easily be dire. If the program were part of an autopilot system, for instance, the consequences wouldn't bear thinking about. For this reason alone, C++ programmers are actively encouraged to use references wherever possible (because they are much easier to use and they clean up after themselves automatically), and to only use pointers when it is absolutely necessary.
Can you describe how Exception Handling is implemented in C plus plus?
Exception handling is a programming language construct or computer hardware mechanism designed to handle the occurrence of exceptions, special conditions that change the normal flow of program execution
Only public member functions can access public member data TrueFalse?
False. Public member data is accessible to all functions, whether they be public, protected or private members of the same class, or they are outside of the class completely.
Can you have a project in c plus plus?
A project is a collection of files (source files, headers, resources, etc) that constitute a single entity, such as a library or executable, that can be compiled independently of other projects. Projects are usually grouped into solutions, such that compiling one project will automatically compile all of its out-of-date dependencies (other projects in the solution that were compiled after the current project was last compiled). One project is always designated the startup project, which is the one that is compiled and executed by the debugger.
What is a C plus plus program to change 5x5 array to 1x25 array?
An array is simply a contiguous block of memory. The length of that memory is the product of all its dimensions multiplied by the size of its type. Thus a 5x5 array is exactly the same as a 1x25 array. The only difference is in how you refer to each element.
The following code demonstrates how we can remap a 5x5 array to a 1x25 array, simply by pointing at the first element. Note that we haven't actually changed the array, nor have we copied it to new memory. We're simply interpreting the exact same memory in two different ways.
#include<iostream>
#include<iomanip>
int main()
{
int x[5][5] = {
1, 2, 3, 4, 5,
6, 7, 8, 9, 10,
11, 12, 13, 14, 15,
16, 17, 18, 19, 20,
21, 22, 23, 24, 25
};
// treat as 5x5 array:
for (int a=0; a<5; ++a)
{
for (int b=0; b<5; ++b)
{
std::cout<<std::setw (3)<<x[a][b];
}
std::cout<<'\n';
}
std::cout<<std::endl;
// treat as one-dimensional array (remap)
int* y = x[0];
for (int c=0; c<25; ++c)
std::cout<<std::setw (3)<<y[c];
std::cout<<'\n'<<std::endl;
}
Output:
1 2 3 4 5
6 7 8 9 10
11 12 13 14 15
16 17 18 19 20
21 22 23 24 25
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25
In c plus plus you cannot assign integer value to enum?
That is correct - In c plus plus you cannot assign integer value to enum - You can only assign an enum value to an enum.
Even though an enum looks like an integer, it is not. It is an enum, and C++ implements strict type checking to reduce the probability of bad programming practices.
enum ColorCode {black, brown, red, orange, yellow, green, blue, violet, grey, white};
ColorCode myColorCode;
myColorCode = yellow;
Even though yellow has an integer value of 4, you cannot say myColorCode = 4.
Why do you get memory access errors with new operator?
The new operator returns a pointer to the memory allocated to an object, or returns NULL if the memory cannot be allocated. This isn't an error as such, it simply means there isn't a large enough block of free memory available to meet the allocation. There may well be more than enough unused memory available, but the memory must be allocated as a single, contiguous block. Modern operating systems use hard-disk space to provide more memory than physically exists in the system (virtual memory), however with a 32-bit system there is an upper limit of 4GB (which includes video memory), of which only 2GB is available to applications. Thus if the user has a lot of programs consuming a lot of memory then it may not be possible to free up enough physical RAM to meet an allocation. Hence the need to check if a returned pointer is non-NULL before attempting to access the memory it points to. On a 64-bit system this is less of a problem because there's effectively unlimited memory (the only limit being free hard-drive space), but even then you must still check a pointer is non-NULL before indirectly accessing the memory it points to.
Write a Program to find the square of a given number using Function Overloading?
#include
// overloads:
char square(char& c){return(c*c);}
double square(double& d){return(d*d);}
int square(int& i){return(i*i);}
int main()
{
double a=3;
double b=square(a); // b=9
int c=5;
int d=square(c); // d=25
char e=12;
char f=square(f); // f=144
return(0);
}
Note that since all the overloads will have the exact same implementation and will only differ by type, we can take advantage of C++ templates to generate the overloads for us, automatically, as and when they are required. Thus the following code is functionally equivalent to the previous code:
#include
template
T square(T& t){return(t*t);}
int main()
{
// force compiler to generate double square(double&) overload
double a=3;
double b=square(a); // b=9
// force compiler to generate int square(int&) overload
int c=5;
int d=square(c); // d=25
// force compiler to generate char square(char&) overload
char e=12;
char f=square(f); // f=144
return(0);
}
To draw a circle and show its movements using c plus plus graphics?
There are several options to draw a circle using C or C++ without the built-in functions...
<> <> <> <>
If you can draw a single pixel at a time, use a for loop to iterate Angle from 0 to 2*pi. Then plot a pixel with x=cos(Angle) and y=sin(Angle). Smaller steps will give better results. Lines from one point to the next may look nicer.
Generally, you can use a line from one pixel to the next to draw a polygon. The number of sides is determined by the number of steps from 0 to 2*pi. A circle is a polygon with an "infinite" number of sides (compared to the display resolution). Experiment with non-integral steps to see that the polygon can end at any place. Use an integral number of steps to end where the circle began. Start and stop at fractions of 2*pi, or step backwards, to create arcs. Speed up the code by using lookup tables to calculate sin() and cos(). Hint: they can be the same table, and don't need to be a complete 2*pi circle.
<> <> <> <>
You can also draw the circle without the sin() and cos() functions if you understand the trigonometry behind sin() and cos(). Recall that sin(theta) is radius / y, and cos(theta) is radius / x, given that x and y are the two sides of a right triangle and that radius is the hypotenuse.
By Pythagoream's theorem, x2 + y2 is radius2. It is then simple to solve for x or y, given the other along with radius. You also do not need to compute for the whole circle - you can compute for one quadrant, and generate the other three quadrants by symmetry. You generation loop would, for example, simply iterate from origin to radius as x by delta x, generating y, and reflecting that in the other three quadrants. You can also compute for one half of a quadrant, and use both symmetry and reflection to generate the other seven half quadrants.
Is overriding a dynamic polymorphism in c plus plus or not?
In C++, overriding and function, method, or operator is a different thing than (dynamic) polymorphism, so overriding a polymorphic method is almost entirely possible.
Swap the value of two variables using call by reference?
swap (int *a, int *b) {
*a ^= *b;
*b ^= *a;
*a ^= *b;
}
int c = 13;
int d = 27;
swap (&c, &d); /*c is now 27 and d is now 13 */
Note: there is no call-by-reference in C. In C++:
void swap (int &a, int &b)
{
. int tmp;
. tmp = a;
. a = b;
. b = tmp;
}
What are some of the attributes of pure virtual function?
A pure-virtual function is not unlike a virtual function, except that you needn't provide a default implementation like you must do with a virtual function. But whether a generic implementation is provided or not, the class is rendered abstract, which means you cannot instantiate the class directly -- you must derive a new class. Indeed, the only reason for declaring a pure-virtual function is to render the class abstract.
Why would you design a class that cannot be instantiated other than by derivation? There are many reasons, but ultimately the class is intended to represent a conceptual object rather than an actual object. A conceptual object is a generic object that encapsulates everything that is common to all its derivatives, but one that cannot provide a complete implementation of its interface.
For instance, circles and squares are actual objects that share a common concept: they are both types of shape. Thus circles and squares (and all other shapes) may be derived from a generic shape object. The shape object can encapsulate everything that is common to all shapes, such as colour attributes, line width and style, and so on. It can also provide common interfaces such as draw(), rotate() and so on. But it cannot implement these interfaces without knowing what type of shape it actually is. While you could use expensive runtime type information within the base class to determine the type of shape and write reams of base class code with switch statements to cater for all possible shapes, this makes no sense (and would be a maintenance nightmare) when the derivatives have all the information required to implement these interfaces. Thus the abstract shape class exists to provide a common interface while each specific shape fills in the details and provides the actual implementation.
The derivative must provide an implementation for the pure-virtual method (augmenting or replacing any generic implementation, where one exists) otherwise it becomes abstract itself. But once a derivative implements a pure-virtual function, the function becomes a normal virtual function with respect to any of its derivatives. That is, derived implementations can be inherited, but the base class implementation (if one exists) cannot be inherited.
A pure-virtual function is declared like any other virtual function, by prefixing the function with the virtual keyword. The difference is that you must append =0 after the function signature:
class abstract
{
public:
virtual void my_function()=0;
};
If a generic function body is require, it can be declared externally:
void abstract::my_function()
{
// ... function body goes here
}
Or it can be declared inline:
class abstract
{
public:
virtual void my_function()=0{ /* ... function body goes here */ }
};
Unable to find a version of the runtime to run application?
check version in C:\WINDOWS\Microsoft.NET\Framework
Discuss various forms of get function supported by the Input stream How are they used?
This function is virtually identical to get(buf, num, delim) version of get ( ). The difference between get(buf, num, delim) andgetline ( ) is that getline ( ) reads and removes the delimiter new - line character from the input stream if it is encountered which is not done by the get ( ) function. Following figure explains the difference between get ( ) and getline ( ) functions :
Yes. Some people enjoy getting as much genital diseases as possible and let them flourish. They're the same kind of people who go to specially organized parties to contract AIDS - willingly. It's a fetish-thing. There are even some forums online dedicated to it.
I've never heard the term posneg before, but I'll assume it's a contraction of positive and negative, which is a signedvalue in C++, as opposed to an unsigned value which is always positive. Signed and unsigned are modifiers that can be applied to any integral data type (integer and char types).
Trying to delete uninitialized pointer to object?
You cannot delete an uninitialized pointer, because there is no allocation for the object, and the pointer contains garbage. That includes the case where you attempted allocation and failed, but deletion is safe in that case because a NULL pointer is "safe" to delete, even though it does not point at anything.
What are the different mechanism for protecting data from external user of the class in c plus plus?
There is only one mechanism for protecting data in C++: declare the data private. This ensures that only the class and friends of the class have unrestricted access to the data.
Although protected access sounds more appropriate with regards protecting data, this is not the case at all. Protected data has the same restrictions as private data but also exposes the data to derivatives of the class. This means that any user can derive a class from your class and thus gain unrestricted access to the so-called "protected" data.
Although you could declare your class final to prevent users from inheriting from your class, it makes no sense to use protected data in a final class. Although the language would permit such a declaration, the two are mutually exclusive.
Note that, unlike Java, C++ has no 'final' keyword (the C# equivalent is 'sealed'). However, we can make use of existing mechanisms to achieve the same end. Consider the following:
class A;
class B
{
friend class A;
private:
B () {}
};
class A : public virtual B {};
In the above example, class A is final. To understand why, keep in mind that virtual inheritance guarantees that the most-derived class must be able to call the least-derived class constructor first. In this case, the least-derived class B has a private constructor that is only accessible to friend class A. Thus A must always be the most-derived class. In other words, only A can inherit from B and no other class can inherit from A.
Since A is final, it makes no sense to declare any protected members within A as no class can inherit them. Also, it makes no sense to declare protected members in B since A automatically inherits private members of B by virtue of being a friend class and is the only class that can inherit from B in any case.
As a general rule of thumb, protected data should be avoided whenever possible. Data should either be private or public. There is rarely the need for a derived class to inherit data, bearing in mind that this could undermine the encapsulation of your class.
Protected methods are generally OK if you expect your class to be inherited by many classes for which you may not have any control over (an open system), but where those derivatives require access to internal methods that would otherwise be declared private. The only alternative would be to declare those derivatives as friend classes, which is only feasible when you have full control over those derivatives (a closed system). In that case it may prove simpler to use final mechanics instead.
What are words that have special meaning in a programming language called?
Keywords or reserved words.