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

Is NET programming is update from C plus plus programming?

No. .NET programming is Microsoft-specific, similar to Java in some respects, but it is non-portable. C++ is a general purpose and cross-platform programming language.

Write c plus plus code to overload operator to find maximum between two objects?

The only operator you need to overload is the greater-than operator. You can then use the std::max function from the standard template library.

#include<iostream>

#include<algorithm> // for std::max()

class my_object

{

private:

int m_data;

public:

my_object(int data=0): m_data(data) {}

my_object(const my_object& copy): m_data(copy.m_data) {}

my_object& operator=(const my_object& other) { m_data = other.m_data; }

my_object& operator=(const int) { m_data = int; }

// greater-than operator overload:

const bool my_object::operator> (const my_object& other)

{

return this->m_data > other.m_data;

}

};

int main()

{

my_object a = 42;

my_object b = 0;

my_object c = std::max(a, b);

// alternatively:

my_object d = a > b ? a : b;

}

Note that the alternative method shown above is slightly less obvious than calling std::max, but both do exactly the same thing. However, both methods require you to overload the greater-than operator.

What is null macro?

The NULL macro is an implementation-defined macro. It is used to symbolise the zero address (0x0) in C programs and older C++ programs. It is not type safe, but is the conventional method of assigning the zero address to a pointer variable. C++11 introduced the type-safe nullptr data type.

Can you mix new and malloc in the same C plus plus program?

Yes.

Note: This is generally a bad idea. Using delete on something you malloc'ed or free on something you new'ed usually will cause Bad Things to happen.

What prototype for menu function takes no arguments but returns a char value?

char SomeFunction();

This has nothing to do with menu functions. It is a straight C/C++ answer. Menu functions depend on the platform API, not on C/C++.

Advantages and disadvantages of semaphore in os?

Advantage of semaphore is simplicity. Disadvantage of semaphore is more prone to programmer error. It does not guarantee that if programmer misplace the P and V then it will also work correctly. It may occur deadlock or violation of mutual exclusion due to programmer error.

Is C plus plus same as Microsoft Visual C plus plus Express Edition?

Your question request a comparison between apples and pears. C++ is a programming language. Microsoft Visual C++ Express is one of many development tools that you can use to create programs using the C++ programming language.

Microsoft Visual C++ Express supports native C++ development, and supports development in 'managed C++,' a Microsoft-specific derivative of the C++ language, aimed specifically at the .NET platform.

What is Normalization of pointers?

The 8085 had a 16-bit address bus thus it could address a maximum of 64KB of memory (2^16). The 8086 had a 20-bit address bus and could therefore address a maximum of 1MB of memory (2^20). To maintain compatibility, segmented memory was introduced, such that the segment and offset were stored in separate 16-bit registers. In order to perform 20-bit pointer arithmetic upon the 8086, the segment and offset had to be normalised by the compiler to produce a valid 20-bit address. This was achieved by left-shifting the segment by 4 bits and then adding on the offset.

The 8086 also introduced the concept of near, far and huge pointers. A near pointer only stores the offset while far and huge pointers store both the segment and the offset. The only practical difference between far and huge pointers is in how pointer arithmetic works. With far pointers, only the offset is affected whereas with huge pointers, both the segment and the offset are affected.

How do you code a simple C plus plus program to remote shutdown computers?

Any code that remotely controls another computer is far from simple. The simplest method would be to write a client-server application, where the client runs as a service awaiting a shutdown instruction from the server. However, it goes without saying that a network administrator would take a dim view of employees remotely shutting down other employee's computers.

What is the difference between brute force search and heuristic search?

Brute force is a systematic approach. Heuristics use educated guesses, rules of thumb and common sense.

What are the benefits of matrices in programming?

Matreses like the temper pedic and the sleep number bed are not as good as they say. The temperpedic is filled with seemingly soft foam but its actually tight and feels bad. The sleep number bed is electronic and like all electronics can start a fire but your just sleeping on this fire.

How do you write a program in c plus plus language to draw a precedence diagram for assembly?

Precedence assembly diagrams are used to show all the steps that must be undertaken in order to produce the complete assembly of a component from its component parts. Some steps must be completed before others can begin (serial assembly), but there will sometimes be two or more steps that can be completed in any order (parallel assembly).

In order to model the sequence of events we need a node object that holds a single step in the assembly, along with two node pointer lists. The first list points to all the nodes that must be completed before this node's step can begin, while the second list points to all the nodes that may be started once this node's step is complete. We call these lists the parent list and the child list respectively. Every assembly has one root node which has no parents, and one leaf node with no children. These nodes mark the start and end of the assembly, and all other nodes interlink directly or indirectly with these two nodes to form a lattice.

The simplest lattice is the serial assembly lattice, where one node leads directly to another in sequence. The minimum number of nodes in a serial assembly is three: a root, a child step and a leaf.

The next simplest lattice is the diamond formation where there are four nodes in total: a root, two child steps and a leaf. This forms a simple parallel assembly lattice because the two child nodes may be completed in any order, but only after the root is complete. Moreover, the leaf cannot begin until both children are complete.

More complex assemblies can be catered for by adding more child steps and by combining serial and parallel formations. Note that each node within the lattice forms the root of a component part within the completed assembly. Thus the lattice provides automatic sub-grouping of each component part.

The only thing missing is a completion field in each node. This is necessary when drawing your diagram because children with two or more parents can only begin when all their parents are complete. To achieve this you simply need a boolean flag that is initially false. As you draw your diagram, begin at the root, process it and mark as complete. Now repeatedly traverse from the root using depth-first traversal to locate the first incomplete node. If any of its parents are incomplete, traverse to the first incomplete parent and check its parents. Eventually you will locate an inmcomplete node where all the parents are marked complete, at which point you can process the node and mark it as complete. Start over at the root to locate the next node. Eventually you will arrive at the leaf and all its parents will be marked complete. After processing the leaf, the assembly is complete.

What c plus plus program must be saved in a text with the extension cpp?

The .cpp extension is merely conventional; it is not required by the C++ standard. You can actually use any file extension you wish.

Appending array elements using function in c plus plus programming?

#include<iostream>

void append(std::vector<int>& v, int i){ v.push_back(i); }

int main()

{

std::vector<int> v;

append( v, 100 ); // same as calling v.push_back(100);

return(0);

}

How is anode inserted in a linked list?

suppose that a linked list which have 4 nodes.

Example:-

10->20->30->25->50->NULL

there is three way to insert the node in this list.

1. from beginning position

2. from ending position

3. from specific position

What is data field?

A data field is a place where data can be stored. It may be a column in a database or a field in a data entry form.

What is late bound function call in C plus plus?

Late binding, or dynamic binding, occurs at runtime. Early binding, or static binding, occurs at compile time. The difference between the two is that, with early binding, the compiler knows exactly which function will be called in advance and can statically bind to that function during compilation. With late binding, the compiler does not know which function will be called in advance, it only knows the function signature. Thus the binding has to be done at runtime.

For example, if you call a virtual function of a base class, the compiler cannot determine in advance the exact type of the derivative (in some cases it may not be derived at all). All it knows is that you've called the base class method and that an override may or may not exist at runtime. Thus the exact method to be called will ultimately be determined at runtime, via the derived class' virtual table. Note that although the derived class is itself late bound (because the compiler cannot know the exact type of a derivative that may be made available in the future), only the virtual methods of the base class need to be late bound. Non-virtual methods can be statically bound, since they are never expected to be overridden.

Calling virtual methods is actually no different to using function pointers within your code (a virtual table is simply an array of function pointers, with one table per base class, and another for each of its derivatives). Again, the compiler cannot know in advance where a function pointer will actually be pointing at compile time, thus the call must be dynamically bound at runtime.

How do you enter only diagonal elements in c plus plus?

Matrices have two diagonals: main diagonal and anti-diagonal. The main diagonal runs from top-left to bottom-right. For square matrix A:

// main diagonal:

for (size_t xy=0; xy<A.size(); ++xy)

cin >> A[xy][xy];

// anti-diagonal

for (size_t x = A.size()-1, y=0; y<A.size(); --x; ++y

cin >> A[x][y];

What is argument in c plus plus?

If this is a homework assignment, please consider trying to answer it yourself first, otherwise the value of the reinforcement of the lesson offered by the assignment will be lost on you.

An argument (or parameter) in C or C++ is a special variable that is passed to a function when it is called. In the example...

float sin(float x);

... the x is an argument. Within the body of the function, x refers to the copy of the caller's argument that was passed to the function.

Similarities between C plus plus struct and class?

The only difference between a struct and a class in C++ is that struct members are public by default while class members are private by default. Other than that they act and behave in exactly the same way and are both used to define classes. By convention, struct is used exactly as it would be used in C, with all public members and no member functions, to provide backward compatibility with C-style code.