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

What is the purpose of the keyword private?

The private keyword is used to ensure that no other classes will be able to access (view or modify) that class member.

What are the disadvantages of procedure oriented programming in c plus plus?

There are no any disadvantages of procedure oriented programming in C++. You can use it as well as object oriented programming, generic programming or any other paradigm. Just remember that this way you won't be using many helpful features of that language.

How do you write an algorithm to swap the values of x and y using a temporary variable t?

To swap the values of two variables, x and y, using a temporary variable t:

t = x;

x = y;

y = t;

To implement this algorithm as a function, the variables must be passed by reference. For efficiency, particularly with large or complex objects that are expensive to copy, use move semantics. The C++ standard library provides the following implementation (since C++11):

namespace std {

template<typename T>

void swap (T&& x, T&& y) {

T t = std::move (x);

x = std::move (y);

y = std::move (t);

}

};

The C++ standard library swap function (std::swap) uses the above implementation (since C++11). If a type does not support the move semantic, copy semantics will be used instead.

How do you increase the stack size of cc1plus dot exe for GCC 4 5 2 so it doesn't stack overflow?

If a stack is overflowing then there is usually some fundamental flaw in the program design. The best solution is to redesign the program. That said, one possible workaround might be to turn off optimisations with QMAKE_CXXFLAGS += -O0. However, it's far better to understand exactly why the stack is overflowing in the first place, and redesign the code to ensure it never happens. If you genuinely need a larger stack, then you can alter it programmatically using setrlimit.

Is int a statistical function?

No, 'int' is short for 'integer' (or 'integral' etc).

How do you Convert C plus plus code to MIPS?

C++ is high-level source code, while MIPS is low-level machine code for a reduced instruction set computer (RISC). To convert C++ source code to MIPS you need a C++ compiler specific to the MIPS architecture you're building against.

What represents the left hand side of a binary operator in c plus plus?

The left hand operand of a binary operator must represent a modifiable lvalue:

void f (const int x, int y) {

x = y; // error -- x is constant lvalue

y = x; // ok

}

What is the correct data type of an accumulator variable used to store real estate sales total?

To ensure 100% accuracy, I would use an integer type rather than a floating point type and convert from pence to pounds on the fly if necessary. If you're only interested in whole pounds then an integer is still the way to go (increasing your range by 100 fold). The only issue then is how large a value you need to store in the accumulator. An unsigned 32-bit accumulator can accommodate a running total of up to 4,294,967,295, which converts to £42,949,672.95 or £4,294,967,295 in whole pounds, while an unsigned 64-bit accumulator can accommodate a total of 18,446,744,073,709,551,616, which converts to £184,467,440,737,095,516.16 or £18,446,744,073,709,551,616 in whole pounds. Personally, I'd go with the unsigned 64-bit integer just to err on the side of caution.

Although it's unlikely in this case, should you require negative values, a signed 64-bit integer has a range of 9,223,372,036,854,775,807 to -9,223,372,036,854,775,808.

Note that floating point numbers may incur errors due to rounding. Although such errors may be unlikely in this case, since you are only dealing with 2 decimal places at most, whole numbers are guaranteed to be 100% accurate.

Who are the members of gym class heroes?

Gym Class Heroes is a four man band from New York that started in 1997! The members are Travis McCoy, Matt McGinley, Disashi Lumumba-Kasongo, and Eric Roberts.

How you can interchange two integer values using swap variable in c language?

t = a; a = b; b = t; // t is a third integer variable (swap variable)

But here's a way without a swap variable, given as as a macro in C:

#define SWAP(a,b) { if (a!=b) { a^=b; b^=a; a^=b; }} // Swap macro by XOR

Once you define it, you can say swap(x,y) to swap x and y. The numbers kind of flow through each other and end up swapped.

Which is the primary need to develop Java programming from C plus plus?

The primary need to convert any language source, including C++, to Java is simply one of portability.

While C++ is itself portable, writing cross-platform code requires that you write code in a more abstract manner than you would when writing for a specific platform, making extensive use of compiler directives to determine which version of each translation unit will be compiled upon which particular platform. This increases code maintenance because you must then maintain separate versions of the platform-specific code, as well as include a different set of headers for each platform, and thus call different functions for each platform. You must also compile the source separately upon each supported platform, which means the code must be as generic as possible in order to be understood by every possible compiler. Thus cross-platform C++ code tends to be limited to the most popular platforms only, which usually means Windows and Unix only.

Java's higher level of abstraction is such that you need only write one set of instructions and compile it one time only. The Java virtual machine handles all the low-level machine specifics, so the same executable will run on any machine that has a Java virtual machine implementation. While this greatly reduces code maintenance and increases portability, the need to interpret the compiled byte code (rather than native machine code which requires no interpretation) reduces performance enormously. Thus the ease of maintenance has to be weighed against the loss of performance to determine if it is a worthwhile exercise.

What is a statement in C plus plus?

A statement may be simple or compound. The following examples are all simple statements:

int i=1;

i++;

std::cout<<i<<std::endl;

Note that a simple statement ends with a semi-colon.

A compound statement is a group of simple statements enclosed in braces. Compound statements usually begin with an opening statement, such as for, if, switch, etc.

for(int i=0; i<10; ++i)

{

int j=i*i;

std::cout<<j<<std::endl;

}

In this example, the compound statement begins with the for keyword and ends at the closing brace. Everything between the braces is treated as a single statement composed from simple statements. If there were only one simple statement, the braces would be optional, but the statement would still be regarded as a compound statement.

The comma operator can also be used to form compound statements (braces are neither required nor implied):

int i=1, j=2;

The compiler treats this as if it were written in full:

int i=1;

int j=2;

What subjects can you do if you are good at algebra but bad at computer programming in terms of writing code in every programming language including C plus plus and visual basic?

Just because you're good at algebra doesn't mean you have to be good at programming. Algebra is taught from a very early age (even in kindergarten) and it is one of those areas of mathematics, besides arithmetic and geometry, that virtually everyone uses every day without even realising it. It's such an elementary subject that there are no specific subjects you can do just because you're good at it. However, if you have a yearning to take algebra further then you might consider abstract algebra, an area of advanced mathematics studied primarily by professional mathematicians. No programming required, but there's absolutely nothing stopping you from learning to program. Even if you're no particularly good at it, it's still useful to have an appreciation for a variety of languages.

How do you use delete function in inheritence in classes using c plus plus?

You use delete to release the memory occupied by an object that is being pointed to by the pointer you delete. Provided all base classes have a virtual destructor, it doesn't matter what the type of pointer you actually delete is, so long as it is a type of class from which the object is actually derived. The destructor from the most-inherited class (the object itself) will be called first, which calls the destructors of its immediate base classes, and theirs, and so on until the object is completely released from memory.

Note that you must not delete pointers to object references -- they must be nullified (not deleted) when they are no longer required. The referenced object will be deleted automatically when it falls from scope.

What is aggregation in C plus plus?

Aggregation and composition are two sides of the same coin. Both an aggregate and a composite object encapsulate one or more sub-objects. But while a composite object owns its sub-objects, an aggregate object does not. That is, when a composite object is destroyed, its sub-objects are also destroyed. But with an aggregate object, the sub-objects are not destroyed.

Aggregate objects typically use references or pointers to refer to their sub-objects, whereas composite objects typically use member variables or pointers to refer to their objects. In essence, a composite object instantiates its own sub-objects, whereas an aggregate object's sub-objects must be passed to it, typically via the constructor.

In complex models you will often find a combination of composition, aggregation and inheritance, even within the same object.

What are the differences between C plus plus and C sharp?

C# is completely object-oriented whereas C++ allows the concept of primitive variables which are not object-oriented. Moreover, C# only works on Microsoft .NET platforms, whereas C++ is a generic language. C# actually has more in common with Java than it does with C++, because both C# and Java compile to byte code that is suitable for interpretation by a virtual machine, whereas C++ compiles to native machine code.

What is string library functions syntax?

String library function is one which is used to perform an operation in C-programming,without which library functions likestrlen(),strcp(),strcmp(),strdup(),strrev(),etc..,.can be performed

Is inheritance polymorphism possible in structure in c plus plus?

Yes. A C++ struct is exactly the same as a C++ class. The only difference is that struct members are public by default, whereas class members are private by default. Other than that, they work exactly the same way. Typically, you will use a struct when there is no need to encapsulate the data members (public access only), or when you need backward compatibility with C-style code. A C-style struct has only public data members (none of which can be a class of course, but may be another struct), but it has no methods whatsoever. Thus you need to disable the compiler-generated default and copy constructors, the destructor and the assignment operator. This is achieved by declaring them without a function body (no curly braces).

What are the advantages of structure in c plus plus?

They are primarily included to retain compatibility with C. However, structures are public by default. So if you don't require the data hiding capability of a class, a struct is a suitable alternative. Also, when mixing C and C++ code, there may be a requirement to typecast a class to a struct and vice versa.

What Android phones have android 2.3.3?

The current and most advanced version of the Android Operating system (2.3.4) can be found on the Nexus class of phones, most notably the Nexus S and Nexus 1. However, all devices which run a hacked custom firmware called Cyanogen Mod also run 2.3.4. As of now, no phones still run 2.3.3 because of inherent security concerns and most 2.2.1 devices will just skip it and move directly to 2.3.4+ depending on the time of update.

Edit: As of June 2013, the latest version of Android is 4.2.2 (Jellybean). Except for the Nexus One (due to hardware limitations), the rest of the Nexus phones can upgrade to Jellybean.

Write abstract class in c plus plus?

An abstract class is any class definition that contains at least one pure-virtual function.

class AbstractClass

{

public:

virtual void DoSomething()=0; // Pure-virtual.

};