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 a function in C plus plus?

The purpose of C++ is to produce machine code programs from a text-based source. While much of what you can do in C++ you can also do in C, the addition of object-oriented programming (OOP) in C++ makes it possible to model highly complex structures more easily than with C alone. OOP adds a much greater degree of abstraction but C++ still retains the low-level features of C, allowing programmers the freedom to use the tools that best suit the task at hand. While modern OOP languages such as Java are ideally suited to rapid-application development, they simply cannot compete with C++ in terms of efficiency and performance. Hence all major software developments, particularly operating systems, drivers, games and office applications are still programmed in C++ to this day.

Mid point algorithm for ellipse?

Midpoint Ellipse Algorithm

Midpoint ellipse algorithm is a method for drawing ellipses in computer graphics.

This method is modified from Bresenham's algorithm. The advantage of this modified

method is that only addition operations are required in the program loops. This leads

to simple and fast implementation in all processors.

Let us consider one quarter of an ellipse. The curve is divided into two regions. In

region I, the slope on the curve is greater than -1 while in region II less than -1.

dy/dx = -1

Region II

Region I

a

b

x

y

m = -1

Consider the general equation of an ellipse,

b2x2 + a2y2 - a2b2 = 0

where a is the horizontal radius and b is the vertical radius, we can define an function

f(x,y) by which the error due to a prediction coordinate (x,y) can be obtained. The

appropriate pixels can be selected according to the error so that the required ellipse is

formed. The error can be confined within half a pixel.

Set f(x,y) = b2x2 + a2y2 - a2b2

In region I (dy/dx > -1),

(xk, yk)

Prediction

(xk+1, yk-½)

SE

E

Region I

x is always incremented in each step, i.e. xk+1 = xk + 1.

yk+1 = yk if E is selected, or yk+1 = yk - 1 if SE is selected.

In order to make decision between S and SE, a prediction (xk+1, yk-½) is set at the

middle between the two candidate pixels. A prediction function Pk can be defined as

follows:

What are the Advantages of linked list over stack and queue?

A linked list is a data structure in which each node has a pointer to the next node, and thus the whole list is linked.

Some advantages are:

* Easy traversal of the whole list (simply follow the pointers) * Easy insertion and deletion of nodes (don't need to move all the other nodes around)

What are the different types of error in C plus plus?

Well its not clear what kind of errors that you are looking at. Is it programming error or error during execution?

If its programming error then its basically deviation from the standard formats or definitions as defined in C.

What are the advantages of high level language?

High level languages abstract the details of the hardware from the developer, typically reducing the amount of time required to develop a program. This also tends to make the program "portable," meaning it can run across multiple types of hardware, called "platforms." As a side effect, it usually means that a developer does not need to learn the specific instructions that a particular platform requires, so there is less of a learning curve for each new platform the developer needs to write an application for.

Multiple inheritance in java?

Actually, java does not support multiple inheritance. You can achieve partial multiple inheritance using interfaces but java is not like C or C++ where you can do direct multiple inheritance. However, you can achieve partial multiple inheritance with the help of interfaces.

Ex: public class FerrariF12011 extends Ferrari implements Car, Automobile {

What is a program to print the Fibonacci series in c plus plus?

Yes, you can. To generate the Fibonacci sequence, you start with the first two numbers in the sequence, usually 0 and 1. The remainder of the sequence is the sum of the previous two numbers in the sequence:

The following function will generate n terms of the sequence using first and second as the first two numbers in the sequence:

void fibonacci (int n, int first=0, int second=1) {

for (int term=0; term

int sum = first + second;

printf ("%d, ", first);

// prepare for next iteration...

first = second;

second = sum;

}

printf ("\b\b \n"); // backspace over final comma and overwrite with space

}

3 pillars of object oriented programming?

abstraction, inheritance, encapsulation, and polymorphism.

Why do you use a void pointer in a programme?

void is type of pointer that usually means that you can make it point to any data type.

When you make a pointer point to somewhere its data type should match with the place where you want it to point.

When you dont know the data type where it will point to then you can declare a void pointer and make it point to the data type it want.

What are the differences between call by value and call by reference in c plus plus?

Pass By Reference :

In Pass by reference address of the variable is passed to a function. Whatever changes made to the formal parameter will affect to the actual parameters

- Same memory location is used for both variables.(Formal and Actual)-

- it is useful when you required to return more then 1 values

Pass By Value:

- In this method value of the variable is passed. Changes made to formal will not affect the actual parameters.

- Different memory locations will be created for both variables.

- Here there will be temporary variable created in the function stack which does not affect the original variable.

Who invented the C plus plus programming language?

Nobody discovered C++; it was developed by Bjarne Stroustrup in 1978 to address a shortcoming of Simula, which was ideal for modelling highly complex problems but was far too slow for any practical purpose.

Write a c plus plus program that prints your name and address?

#include<iostream>

#include<string>

int main()

{

using namespace std;

std::cout << "Enter your full name: ";

std::string name;

std::getline (std::cin, name);

std::cout << "Your full name is: " << name << std::endl;

}

Which data structure allows deleting data elements from front and inserting at rear?

A linked list is an example for a data structure that allows removal from one end and insertion of new items to the other. Many other data structures support the same operations. They differ in what else they can do, and how efficient the operations can be performed.

What is compound statement in c plus plus program?

A compound statement is a code block. We typically use compound statements as the body of

another statement, such as a while statement:

while (i >= 0)

{

a[i] = x;

++x;

--i;

}

Note that all compound statements are surrounded by braces {}.

What value of c makes the polynomial below a perfect square trinomial x2 8x plus c?

9x + 2 + 24x + c = 33x + 2 + c

If = 0 then c = -33x - 2

if = 1 then c = -33x - 1

if = 4 then c = -33x + 2

in general,

c = -33x -2 + n2 where n is any integer.

What is c plus plus oo?

C++ is a programming language developed by Bjarne Stroustrup.It inherits many of its functionality from c but also has its own unique features like polymorphism, encapsulation,abstraction, etc. It is both procedural and object oriented programming language. For more information, visit the link below:

Where is the function declare in c plus plus language?

All function interfaces must be declared before they can be used. This is known as a forward declaration and is strictly enforced in C++ (but not in C). To facilitate this, interfaces are typically placed in a header file which can then be included in every source file that requires access to that function. The interface need not be defined (implemented) in the header unless the function is a template function. Typically, implementations are kept separate from interfaces (template function implementations are kept in the header but typically separated from the interface) since the interface contains everything the user needs to know in order to make use of the function.

How do you use Graph in data structure?

Em depends on the points your plotting on the graph. If they are evenly distributed then it's probably a linear graph.

How polymorphism can be achieved by means of virtual functions in C plus plus?

Virtual functions of a class are functions (methods) that can be redefined in a child class and, through polymorphism, the correct function will be invoked depending on the type of the class involved. Virtual functions are declared with the virtual keyword... class myclass {

... virtual int myfunction(...);

... etc.

} When a class contains at least one virtual function, a static virtual table (vtable) is implemented behind the scenes by the compiler. This table is used to point to the correct implementation for that type of class at run-time. Abstract base classes are a special form of class, where they must be derived. They often declare virtual functions which is the defined interface, but through the keyword "= 0" enforce the requirement that the class be derived, i.e. that the class can not be instantiated directly... class myclass {

... virtual int myfunction(...) = 0;

... etc.

} class mysubclass : public myclass {

... virtual int myfunction(...);

... etc.

}

What is flowchart diagram?

A flowchart is a diagram that shows a continuous flow of materials or steps to (WIP), work in process. Basically it shows the process, steps or task for something to be completed from beginning to end.some give 2 ways give's Can you like show me a picture of one? from:daggettl0976

What is the difference between switch case and if else?

If else can have values based on constraints, where as switch case can have values based on user choice.In if else, first condition is verified, then it comes to else whereas in the switch case first it cheaks the case and then it switches to that particular case.

What are disadvantages of virtual functions in c plus plus?

Virtual functions have many advantages, but here are a couple of their disadvantages:

  • slower -- The function call takes slightly longer due to the virtual mechanism,and it also makes it more difficult for the compiler to optimize because it doesn't know exactly which function is going to be called at compile time.
  • harder to debug -- In a complex system, virtual functions can make it a little more difficult to figure out where a function is being called from. Or, to figure out why a function isn't being called if someone overrode it with a new virtual function.

What is the function of constants in c plus plus?

Constants are simply variables that do not change value. This is particularly useful when we need to continually refer to the same value, such as the length of a fixed-length array:

const int array_max = 100;

int array[array_max];

for (int i=0; i<array_max; ++i) {

array[i] = i * i;

}

// ...

Using a constant in this way reduces the maintenance burden considerably. For example, suppose we later decide that we really needed 200 integers in our array instead of just 100. So long as our code uses the constant, array_max, we need only change the constant's value and that change will be reflected wherever the constant is used. If we has used the literal constant, 100, instead, we'd need to search through our code and update each usage of that literal. That can lead to human errors and inconsistency in our code.

All constants are allocated in the static segment (where all static variables are allocated) even when they are declare locally. The one exception is a constant formal argument:

void f (const int i) {

// ...

}

Arguments are always passed by value, so i will hold a copy of whichever value was passed to it. Being a copy, any changes made to i will not be reflected in the calling code, however if the function must not modify the value, declaring the formal argument constant ensures we don't inadvertently change the value.

Typically we use constant formal arguments when those arguments are pointers or references rather than values. When we pass an object by reference or by pointer, we are passing a copy of the object's address and this would allow the function to indirectly modify the object. This is known as a side-effect and is undesirable. To give assurance to the caller that the object will not be changed, we use a constant reference or pointer:

void f (const obj& x) {

// ...

}

If we actually want the function to modify the object, the best method of doing so is to return a new object by value and leave the argument constant:

obj f (const obj& x) {

// ...

}

In this way the caller can decide what to do with the returned object:

obj y;

obj z = f (y); // create a new object from y without changing y

y = f (y); // modify y

f (z); // ignore the modification completely

Note that returning objects by value is normally expensive as the object must be copied. However, objects that implement the move semantic can be returned extremely efficiently, particularly those objects that are really just resource handles. This includes all the standard library containers such as std::vector and std::list. Moving a vector is many times quicker than copying one because all we're really doing is changing ownership of the resource; and that's (almost) as efficient as copying a pointer and assigning NULL to the original.

What is the difference between int main and int void?

int main() refers that main function returns an integer value, where the integer value represent the program execution status. This status value is sent to the Operating System. If you follow strictly follow the rules, then it should be int main not void main()