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 do you open SAV file?

The best way to open up .sav files are just to click on them. They will usually appear as a download that you can open.

Array as primitive data members in c plus plus program?

C-style arrays can be used as data members, both as fixed-size arrays or as dynamic arrays. The following examples demonstrate how they could be used as one-dimensional data members.

class a {

private:

int b[10] {0}; // in-class initialisation (all elements zero).

public:

int& operator[] (unsigned index) {

if (index>=10) throw std::range_error();

return b[index]; }

};

class c {

public:

c (unsigned sz=10): size(sz), p (size?new int[size]:nullptr) {

memset (p, 0, size); }

c (const s& _s): size(_s.size), p (size?new int[size]:nullptr) {

if (size) memcpy (p, _s.p, size); }

c (s&& _s): size(_s.size), p (_s.p) { _s.p=nullptr; } // swap resources

c& operator= (const s& _s) {

if (p) delete [] p;

size = _s.size;

p = (size?new int[size]:nullptr);

if (size) memcpy (p, _s.p, size); }

c& operator= (s&& _s) {

size = _s.size;

p = _s.p;

_s.p=nullptr; } // swap resources

~c() { if (p) delete [] p; }

int& operator[] (unsigned index) {

if (index>=size) throw std::range_error();

return p[index]; }

private:

unsigned size {0};

int* p {nullptr};

};

A much simpler approach would be to use std::array<int> and std::vector<int> instead of primitive C-style arrays.

What is the site name which may provide online free classes of C plus plus?

Classes has two meanings here. If you mean classes as in education, then I know of no free online classes. There are plenty of sites that will give tutorials free of charge, but it is best if you buy a comprehensive book on the subject and learn the basics of the generic language first. Then use the sites to gain a better understanding of the platform-specific features available in your IDE. If you mean classes as in data types that you can freely use in your programs, there are many sources available. Most come in the form of example code, many of which can be found in all the popular C++ forums and peer groups, but you can also download open source libraries for free.

How do you read data separated by commas into arrays in c plus plus?

You need to put if statement to check presence of comma in the stream. Most likely you have to read data from stream character by character and compare each time with come:

...
char commaCheck = ',';
...
while (cin >> commaCheck)//you can replace cin with your stream
{
...
if (commaCheck == ',')
{
...
}
...

}

How do you write a program in c plus plus to check if an array is symmetric?

To determine if an array is symmetric, the array must be square. If so, check each element against its transpose. If all elements are equal, the array is symmetric.
For a two-dimensional array (a matrix) of order n, the following code will determine if it is symmetric or not:

template
bool symmetric(const std::array, n>& matrix)
{
for (size_t r=0 ; rfor (size_t c=0; cif (matrix[r][c] != matrix[c][r]) return false; // not symmetric!
return true! // symmetric!
}

How do you create an element in an array using C plus plus program?

If this is a homework related question, you really should consider trying to solve it yourself before looking at this answer. Otherwise, the value of the lesson, and the reinforcement provided by the assignment, will be lost to you.

You do not create individual elements of arrays in C or C++. You create the array, and then reference the elements. Say you want to create a 10 x 20 array of floats. You would declare float MyFloatArray[10][20]. You would then reference the elements, such as MyFloatArray[3][8]. Note that 10 and 20 are the number of elements in each direction, but the valid range of indices is 0 to 9 and 0 to 19, respectively.

What are the advantages of Class A network over Class B and Class C?

A class A network has more IP addresses - you can connect more hosts on it.

A class C network has 256 IP addresses (of which you can use 254), a class B network about 65,000, a class A network about 17 million.

More specifically, a Class A network can have 16,777,214 usable host addresses per network whereas a Class B network can have 65,6534 usable host addresses per network.

Another advantage is the ridiculous amounts of subnetting you can do. For example, in a Class C network, you can't borrow the same number of bits as you can with a Class A because you only have the last octet to work with for the host portion. With a Class A network, the last three octets are the entire host portion, so you have 24 bits to work with for subnetting (technically 23 since you can't subnet down through all available bits and have no bits left for hosts =p). Due to the amount of subnets you can have and the 16+ million hosts you can potentially have on the same network, Class A networks are reserved for super big applications (ISPs and gigantic companies).

How do you remove ntdvm error in Turbo C plus plus?

Turbo C++ is a 16-bit application. If you change graphics mode and move the mouse, or try to create a named pipe, NTDVM.exe will stop responding. A hotfix is available from the Microsoft knowledge base, KB2732488.

Give an example of matrix in c plus plus program?

A matrix is a two-dimensional array of objects. If, for instance, you wanted a 10 by 20 matrix (array) of doubles, you would say...

double mydoublearray[10][20];

You would then refer to each element with the syntax...

double somedouble;
somedouble = mydoublearray[3][7];

Note that array indices start from zero, and go to the declared size minus one, so the first element is mydoublearray[0][0]and the last element is mydoublearray[9][19].

You can have arrays of elementary types and of classes. The syntax is the same. Just use the class name instead of the word double.

Where should data member declarations of a class be?

Members can be declared anywhere within a class declaration, and in any order.

Some programmers like to keep data member declarations at the top of the class declaration, either before or after the constructors, while others prefer them at the very bottom, but it really doesn't matter where they are placed as long as they appear somewhere (with an appropriate private, protected or public access specifier).

The order they are declared is generally only of importance when debugging, as the order of declaration generally dictates the order in which they are presented by the debugger's watch windows. Many debuggers will list the first few member variables without the need to expand the class completely, thus the variables that are of most interest should be placed before those of less interest.

How data secured from out side world in c plus plus?

In C++, data is not secured from the outside world it is merely protected from accidental mutation. A determined programmer can easily circumvent the encapsulation of an object. Consider the following:

class X {

int data; // private by default

};

Here, the data member is declared private (the default access for a class), however the class definition exposes the implementation details making it possible to define the exact same class with public access under a different name:

struct Y {

int data;

};

Given that X and Y both have the same memory layout, it is trivial to undermine the encapsulation of an X by casting to a Y:

void f (X& x) {

x.data = 42; // error: x.data is private

Y& y {(Y&) x}; // refer to x as if it were really a Y with pubic access

y.data = 42; // ok

}

What is the LT button?

Left Trigger... On Xbox360 it is, anyway.

What is the difference between fixed partition and dynamic partition?

The difference between fixed partition and dynamic partition... For the case of disk partitions: Fixed partitions are defined in the master boot record, or in one of its chains that define logical partitions in an extended partition. As such, they are known at boot time and, if the operating systems recognize them, they can be shared between multiple installations, such as Windows and Linux. Dynamic partitions are defined by the operating system. They are defined out of unallocated drive space and, as such, are not known at boot time. They can not generally be shared between different installations. Also, unless the operating system using dynamic partitions makes at least its allocations known to the boot record, any attempt to manage disc space using both techniques is dangerous. For the case of analysis and programming: Partitioning is a technique used to break data up into managable pieces. Binary Search, for instance, partitions an array into successively smaller pieces as it narrows its search space down. Sorting can also partition data, sorting each partition and then sorting the partitions. Quick Sort and Merge Exchange Sort are examples of that. Statistical analysis may also partition data. The list is endless. Addressing the specific question, then, static partitioning is breaking the data up into fixed sized pieces, while dynamic partitioning makes the piece size variable, often as a consequence of the results as they evolve.

Where can the source code of Prim Algorithm be found?

Algorithm's don't have source code per se. Source code depends on the programming language used to implement the algorithm and this will obviously vary from language to language. However, we often use pseudo-code to provide an informal language-agnostic implementation in human-readable form. Pseudo-code is not source code because it is not machine-readable and has no formal standard. However, it employs established structured programming conventions such as loops and variables, thus the code can be easily adapted to suit many high-level programming languages.

Prim's algorithm can be informally described as follows:

  1. Initialise a tree with a single vertex, chosen arbitrarily from the graph.
  2. Grow the tree by one edge: of the edges that connect the tree to vertices not yet in the tree, find the minimum-weight edge, and transfer it to the tree.
  3. Repeat step 2 until all vertices are in the tree.

In pseudo-code, the algorithm can be implemented as follows:

Associate with each vertex v of the graph a number C[v] (the cheapest cost of a connection to v) and an edge E[v] (the edge providing that cheapest connection). To initialise these values, set all values of C[v] to +∞ (or to any number larger than the maximum edge weight) and set each E[v] to a special flag value indicating that there is no edge connecting v to earlier vertices.

Initialise an empty forest F and a set Q of vertices that have not yet been included in F (initially, all vertices).

Repeat the following steps until Q is empty:

  1. Find and remove a vertex v from Q having the minimum possible value of C[v]
  2. Add v to F and, if E[v] is not the special flag value, also add E[v] to F
  3. Loop over the edges vw connecting v to other vertices w. For each such edge, if w still belongs to Q and vw has smaller weight than C[w], perform the following steps:
  • Set C[w] to the cost of edge vw
  • Set E[w] to point to edge vw

Return F

Source: wikipedia

What is class?

It is where you leave school or otherwise find a way to avoid going to that particular class.

If in a multithreaded process a static variable is initialized at 10 and first user increments is value?

Then all the threads and all the instances of the class that contain the static variable would see the new value. Please make sure that you address any concurrent access (synchronization) issue that might appear.

What is linear data structure?

when elements are accesed or placed in contiguous memory location yhen data structure is known as linear data structure. stacks, arrays, queues and linklists are example of data structure.

in non-linear data structure element are not placed in sequential manner. trees, graph are the ex. of non-linear data structure.

What is Friend class How is it different from Abstract class?

Friend class is one which has been declared so (as a friend) inside other class to make it access the private members of the class which has extended it's friendship.

For Example,

class A

{

private:

.......

public:

..............

friend class B;

};

class B

{

.......

..............

};

As in the above code snippet, class A has extended it's friendship to class B by declaring B as it's friend inside it's area.

Since the Class B has became a friend of A, B can directly access all the private members of A. But the reverse is not possible.

Where as an abstract class is a one, which doesn't represent any particular object in nature. Instead they use give as abstract look of an object.

For instance,

When we say TATA Indca, Lancer, Ford Icon, Toyota Innova they are different car models. Each of them having their own properties and features, but all of them are Cars. So here, Car is an abstract class where as the others are concrete classes.

Why steganography is good with java?

Steganography is good with JAVA because JAVA is a highly secured language.

If we use steganography with JAVA, it will enforce multiple levels of security of data.

form: RISHU

What is the difference between structure and class?

Structures are public by default while classes are private by default. Classes are generally more beneficial as the encapsulation dictates the object's purpose, and data hiding ensures the data remains valid. But the ability to emit a structure from an object and vice versa simply adds to the overall flexibility, giving you the best of both worlds whenever needed.

How do you display x to the power of 2 on output screen using C Plus Plus?

Use: cout << pow(x,2) << endl;

you need to include iostream and cmath. #include #include

Which data structure is used for breadth first seach?

Breadth first search can be performed upon any tree-like structure. A binary tree is a typical example. A breadth first search begins at the root and searches the root's children, then all its grandchildren, and so on, working through one level of the tree at a time.

How do you change the values in an array c plus plus program in discussion?

To change the values in an array in C++ you simply assign values to the appropriate elements:

// Zero-initialise an array of 10 integers:

std::array<int, 10> a {0};

// Assign values to individual elements by index:

a[0] = 2;

a[1] = 3;

a[2] = 5;

a[3] = 7;

a[4] = 11;

a[5] = 13;

a[6] = 17;

a[7] = 19;

a[8] = 23;

a[9] = 27;

// Iterate through the indices:

for (size_t index=0; index<a.size(); ++index) {

a[index] = random_integer();

}

// Iterate elements by reference using a ranged-for loop:

for (auto& elem : a)

{

elem = random_integer();

}

Note that the suffix operator [] can also be used with C-style arrays. For example:

int a[10] {0};

a[0] = 2;

a[1] = 3;

a[2] = 5;

// etc...

How do you add allegro.h to codeblocks on Mac OS Sierra?

You don't add it to code blocks, you include it in your own code. If your compiler can't find it, specify the relative path -- relative to the source file.