answersLogoWhite

0

📱

C++ Programming

Questions related to the C++ Computer Programming Language. This ranges all the way from K&R C to the most recent ANSI incarnations of C++, including advanced topics such as Object Oriented Design and Programming, Standard Template Library, and Exceptions. C++ has become one of the most popular languages today, and has been used to write all sort of things for nearly all of the modern operating systems and applications." It it a good compromise between speed, advanced power, and complexity.

2,546 Questions

How does a class in c plus plus enforce data encapsulation?

Data encapsulation is enforced by restricting access to the class members. Access can be specified on a per-member basis, defaulting to private access for a class and public access for a struct. Private members are accessible to class members and to friends of the class. Protected members are the same as private members but are also accessible to derived class members. Public members are fully-accessible. Data members are typically declared private while interfaces are typically declared public or protected.

How do you open a project in Microsoft visual studio 2008?

Making sure that it is a 2008 project or earlier you go to open project then find the file on your computer. Double click it an d it will open (if it is older then 2008 it will ask for you to convert it first)

How do you find the greatest of two numbers without using the if-else comparison operators?

By subtracting any two of the numbers A-B , if the output number is negative , B IS GREAT and if its positive A is great

What features make C plus plus so powerful?

When C++ was initially developed in 1978, it was unique in that there was no other language that incorporated object-oriented programming that could produce efficient machine code. Object-oriented programming languages did exist, of course, but the code they produced was often interpreted and therefore far too slow for anything but the most trivial of tasks. C++, like all object-oriented programming languages, is capable of solving highly-complex problems in a highly efficient manner, breaking larger problems down into smaller, simpler problems. But while newer languages such as Java and C# are just as capable as C++ and very much easier to program, they simply cannot match C++ in terms of performance. That remains unique to C++ today as it did when it was first released in 1985, and is the reason all major applications, including C++ compilers themselves, are still largely or wholly written in C++. The very first C++ compiler was written in C, of course.

Why is multiple inheritance implemened through interfaces?

Interfaces have only methods declared and not defined. So that these various methods can be altered or customized or written according to the need. Hence Multiple inheritance is implemented through Interfaces.

Interface is a progam which just declares various methods or functions, so that any user can write the contents of that method declaration.

AnswerTrue Multiple Inheritance refers to the ability to inherit from multiple CLASSES. Thus, a true multiple inheritance language does not use interfaces. However, many single-inheritance languages provide most of the benefits of the multiple inheritance concept by using interfaces (Java, for example).

The problem with true Multiple Inheritance is twofold:

(a) at the compiler and runtime level, it is often difficult to determine which method is being referred to, as M.I. can lead to very convoluted (and sometimes conflicting) namespaces

(b) there is no specific superclass, which can lead to problems with determining relationships between classes

Using a S.I. model with interfaces avoids these two problems.

Why isn't main a keyword in c?

Neither is printf, stderr or NULL. Certainly, they are important words, but not keywords.

Why you write c plus plus not plus plus c?

C++ uses the postfix increment operator whereas ++C uses the prefix increment operator. Both do exactly the same thing; they increment C (the same as C=C+1 increments C). The difference is only in the return value. ++C returns a reference to C, whereas C++ returns the original value of C.

What type of integers are supported by C plus plus?

All the standard arithmetic operations are supported in C++. The most common operations, such as plus, minus, multiply and divide are built-in for all the numeric primitives, as well as C++ specific operators like post-increment and pre-increment (++). More complex mathematical and trigonometric operations are provided by functions declared in math.h. Your IDE may include other libraries, or you can download public-domain libraries, or simply write your own.

Importance of programming in system development?

When business organization facing a keen (鋒利的) competition in the market, rapid change of technology and fast internal demand, system development is necessary. In the system development, a business organization could adopt the systematic method for such development. Most popular system development method is system development life cycle (SDLC) which supports the business priorities of the organization, solves the identified problem, and fits within the existing organizational structure. When business organization facing a keen (鋒利的) competition in the market, rapid change of technology and fast internal demand, system development is necessary. In the system development, a business organization could adopt the systematic method for such development. Most popular system development method is system development life cycle (SDLC) which supports the business priorities of the organization, solves the identified problem, and fits within the existing organizational structure.

Advantage and disadvantage of inline function in c plus plus?

The advantage of an inline function is that it eliminates the function calls completely, thus improving the performance wherever those calls appear. The disadvantage is that it increases code size, which can be detrimental to performance. For this reason, declaring a function for inline expansion is merely a hint to the compiler. If the increased code size would be detrimental, the compiler is free to ignore the inline declaration and retain the function call instead.

While the programmer is free to manually expand their own functions, this only serves to increase maintenance should the function ever need to be changed, and could lead to errors should those changes not be propagated correctly. The advantage of having a function, even if it is only ever called once (or from within a loop), is to simplify your code and make it easier to read and maintain. If the function is simple, or is called seldom, then it is a good candidate for expansion, but its almost always better to let the compiler decide which functions should be inline expanded.

How many languages in OOP?

Thousands! Programming languages number in the thousands, from general purpose programming languages such as C++, Java, and others, to special purpose languages which are used in one application. They can be ordered by type (structured, object-oriented, functional, etc.) or by history, or syntax. See the related list of programming languages.

What is namespace in c plus plus program?

A namespace is similar to a class in object oriented programming. A namespace contains functions defined by the programmer. for example namespace std contains functions like cout and cin.

namespaces can be globaly declared like so: "using namespace std;"
which includes all the functions located in the namespace std.
if you only need to use cout you can globaly declare only cout like this "using std::cout;"

or

std::cout<<"calling cout directly from namespace std";

you can make your own namespaces as well

namespace mynamespace;
void myfunction(){
code for function
}

and use it

using mynamespace::myfunction;


The main use of a namespace is to reduce or eliminate collisions with names that may be duplicated but have different functionality. For example, I may want to use an object with the name of 'cout', but that name already exists. If I place it in a different namespace I would be able to use it with that name.

What is storage classes in c plus plus?

AUTO

EXTERN

STATIC are the storage classes in c++

C plus plus code to read the data from any file?

The following function will read any valid file name one byte at a time.

int read_file(char* filename)

{

FILE* input=fopen( filename,"rb" );

if( !input )

{

std::cerr<<"File access error: "<<filename<<std::endl;

return( -1 );

}

char ch;

while( fread( &ch, 1, 1, input )==1 )

{

// process the byte...

}

fclose( input );

return( 0 );

}

What is difference between c and pro c?

C is the computer language bases on K&R's language that has evolved over the years. It includes C++, as extended by Stroustroup..

Pro*C is an Oracle precompiler that will read a C or C++ program, detect Oracle extensions to it, and convert it to native code for subsequent processing by the C or C++ compiler. This involves building the data structures and function calls needed to use Oracle while passing the non-Oracle C or C++ code through intact. The amalgamated code is then processed by the C or C++ compiler and it now works with Oracle.

What are real life application of data structure?

In real life the importance of data structure is much more bcoz it providing a disconnected transaction between database & workstation

just take a example that when some one going to on line shopping at that time at first he/she wants to select the items to purchase simultaneously if the person donot want some selected items then he/she can also retrieve from the list,these all are done in data structure when you at last enter the submit button at that time this will retrieve from the database & enters in to sales list.

Means these all transaction are done in data structure there is no need to transect with data base by that transaction will be faster,secure,good performance,efficient etc

What is the definition of a base-class constructor?

A base class constructor is simply a constructor that is declared within a base class. There is nothing particularly special about them since all constructors are only of relevence and applicable to the classes in which they are declared.

Swap the value of two variables using call by value by c plus plus?

Lets start simple by swapping two int variables in a function call. You must use a & to pass the variables by reference so that when you edit their values the original variables get changed as well.

void swapVariables(int &var1, int &var2)

{

int temp = var1;

var1 = var2;

var2 = temp;

}

You could change this function to use any variable type that you want or you could use a template function instead so that the same function could be used with any variable type.

template <class T>

void swapVariables(T &var1, T &var2)

{

T temp = var1;

var1 = var2;

var2 = temp;

}

Another interesting thing you can do when swapping two variables is use an xor function to swap the two variables without using a temp variable.

void swapVariables(int &var1, int &var2)

{

var1 = var1^var2;

var2 = var1^var2;

var1 = var1^var2;

}

Which can also be simplified to:

void swapVariables(int &var1, int &var2)

{

var1 ^= var2 ^= var1^= var2;

}

Can a function be called from more than one place in a program in c plus plus?

In C and C++, as well as in many (all?) languages, a function can be called from more than one place in a program. That's the purpose of functions - to encapsulate pieces of code that are needed in more than one place in the program.

Can we write a c plus plus program without objects?

Since you can create programs in C plus plus (C++) without creating any object you can call the C++ a semi-object-oriented programming language. The C++ programming language was first released in 1983 and it was designed by Bjarne Stroustrup.

How do you return by reference in C plus plus?

Returning by reference implies that the reference will not fall from scope when the function returns (because references must never be NULL). Thus you cannot return a reference to a variable that was declared local to the function.

int& foo()

{

int local;

return(( int & ) local); // Error: cannot return a reference to a local variable.

}

However, you can return a reference to a parameter that was itself passed by reference, since that reference is guaranteed to exist (it can't be NULL).

const int& GetMax( const int& byRef1, const int& byRef2 )

{

return( byRef1 > byRef2 ? byRef1 : byRef2 ); // this is fine.

}

Generally, the only time you will return by reference is when returning a class instance member or a reference to the class instance itself, since they always remain in scope after the function call.

class bar

{

public:

bar():m_num(0){}

const int& GetIntRef()const{return((const int&)m_num);} // constant reference to instance member.

int& GetIntRef(){return((int&)m_num);} // non-constant reference to instance member.

const bar& AsRef()const( return((const bar& )*this );} // constant reference to this instance.

bar& AsRef()( return((bar&)*this );} // non-constant reference to this instance.

private:

int m_num;

};

Note that use of const is not obligatory when returning references. However, when values must not be changed, it's good policy to enlist the help of the compiler wherever possible. The previous example returns both constant and non-constant references. The function that makes a call to GetIntRef() or AsRef() will determine whether the returned reference should be constant or not. By implementing both methods, we cater for both scenarios.

C plus plus program to list all Armstrong number?

#include<iostream>

#include<vector>

unsigned count_digits (unsigned num, const unsigned base=10)

{

unsigned count=1;

while (num/=base) ++count;

return count;

}

class number

{

std::vector<unsigned> value;

unsigned base;

public:

number (const unsigned _value, const unsigned _base=10): value {}, base {_base} { *this = _value; }

number& operator= (const unsigned _value);

operator unsigned () const;

bool is_narcissistic () const;

};

number& number::operator= (unsigned _value)

{

unsigned count = count_digits (_value, base);

value.resize (count);

while (count)

{

value[value.size()-count--] = _value%base;

_value/=base;

}

return *this;

}

number::operator unsigned () const

{

unsigned num = 0;

for (unsigned index=0; index<value.size(); ++index)

num += value[index]*static_cast<unsigned>(std::pow (base, index));

return num;

}

bool number::is_narcissistic () const

{

unsigned num = 0;

for (unsigned index=0; index<value.size(); ++index)

num += static_cast<unsigned>(std::pow (value[index], value.size()));

return num == static_cast<unsigned> (*this);

}

unsigned main()

{

const unsigned min=1;

const unsigned max=100;

std::cout << "Narcissistic numbers in the range " << min << " through " << max << ":\n\t";

for (unsigned n=min; n<=max; ++n)

if (number(n).is_narcissistic())

std::cout << n << ' ';

std::cout << '\n' << std::endl;

}

What is modularization in c plus plus?

Modular design is the process in which you take a large problem and break it down into smaller problems, and address each smaller problem individually. In terms of C programming, it would mean taking a large programming task and breaking it down into several smaller logically separate tasks. Each of these smaller tasks would most likely be represented as a function in the program.

What are the disadvantages of bubble sort?

The advantage of sorting is that it is quicker and easier to find things when those things are organised in some way. The disadvantage is that it takes time to sort those things. In computing terms, the cost of searching a few unsorted items is minimal, but when searching a large number of items (millions or perhaps billions of items), every search will have an unacceptable cost which can only be minimised by initially sorting those items. The cost of that sorting process is far outweighed by the speed with which we can subsequently locate items. Inserting new elements into a sorted set also incurs a cost, but no more than the cost of searching for an element, the only difference is we search for the insertion point rather than a specific element.