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 many levels of inheritance can be possible with multi level inheritance?

There is no limit actually. But, it is preferable to keep the levels under 6-7 for ease of use and maintenance

What are the rules of C plus plus programming?

1.every 'c' prg starts with a fun called main(),follwed by empty paranthas is.

2.varibles must be declared at the begining of program.

3.each and every statement must ends with a semicolon(;)

4. c prg is a case sensitive that upper case letter not allowed

Why inline function cannot be static?

Inline functions can be static. However, their usage outside of classes in C++ has been deprecated (a hangover from C). Static member functions are allowed of course, and they can be inline expanded where desired. In C, a static function simply has limited scope within the same translation unit. In C++, unnamed namespaces are the preferred method of achieving the same end.


What does the error no input files in c plus plus mean?

There is no such error in C++. 'No input files' suggests you are trying to run a program that processes input files but you haven't specified which files to process. But without knowing what program you are running, it's difficult to suggest a solution other than to consult the program's documentation regarding the command-line syntax.

A well-written program will automatically present the correct command-line syntax when invoked incorrectly, or will at least provide a more-meaningful error message including an error code.

When asking about program errors, it is helpful to include the exact command you executed, including any relevant information such as the program name, author and version, as well as the specific platform you executed the program upon. The more information you provide the easier it is to find a solution.

What is the application of public protected and private keywords?

The public, protected, and private keywords are access modifiers that specify if the item they modify can be accessed inside or outside the class or a derived class.

A public item is fully accessible, inside or outside the class, including inside a derived class.

A protected item is accessible only inside the class or inside a derived class.

A private item is accessible only inside the class.

What are the home application of c plus plus programming language?

C++ is useful when you want to write a program which you can use for your home use. For instance, you have a lot of different files. You can use C++ to sort them out using file extensions. Or you can write a program which will keep track of programs and music you download and so on.

Disadvantage of doubly linked list?

Doubly-linked lists, per Node, contain a pointer to the Node before the current Node, and the Node directly following. This is a lot of information to store, so it can sometimes be memory inefficient.

Compared to the Vector class, a list cannot be accessed through array notation (using square [4] brackets, with the number defining which Node to access). This means that a list must have an iterator to make it work and to make it editable.

What is imol plus used for?

General pain/fever relief and anti-inflammation. Contains ibuprofen and paracetamol.

What is front functions in c plus plus?

Front functions such as vector::front(), list::front() and queue::front() return the first object in a container class. Not to be confused with begin() functions such as vector::begin() which return an iterator object which is typically used in iterative functions (loops) to traverse the objects within a container.

Can a derived class make a public base function private true or false?

True. A derived class can make a public base function private. The derived function is private, within the derived class, but public in other contexts.

What types of database exist in c plus plus?

#include <stdio.h>

main()

{

FILE *a;

int sno,tm,em,mm,scm,sm,hm;

char sname[20],any[1];

clrscr();

a=fopen("student.dat","a");

do

{

printf("Enter Student Number : ");

scanf("%d",&sno);

printf("Enter Student Name : ");

scanf("%s",sname);

printf("Enter Telugu Marks : ");

scanf("%d",&tm);

printf("Enter English Marks : ");

scanf("%d",&em);

printf("Enter Maths Marks : ");

scanf("%d",&mm);

printf("Enter Science Marks : ");

scanf("%d",&scm);

printf("Enter Social Marks : ");

scanf("%d",&sm);

printf("Enter Hindi Marks : ");

scanf("%d",&hm);

fprintf(a,"%d %s %d %d %d %d %d %d\n",sno,sname,tm,em,mm,scm,sm,hm);

printf("Do you wish to continue(Y/N)");

scanf("%s",any);

}while(strcmp(any,"y")==0);

fclose(a);

}

What is a delegate in C plus plus?

C++ does not have built-in support for delegates, however it is possible to simulate delegation through the use of template hacks. See related links below for more information.

Why can't you initialize data members in a structure in c or c plus plus?

You can initialise a structure's data members in both C and C++.

In C, you initialise the structure at the point of instantiation.

typedef struct foo

{

int m_data1;

double m_data2;

} foo;

int main()

{

foo f={.m_data1=42, .m_data2=1.99};

return 0;

}

You can also assign members separately from instantiation, but this is considered bad coding practice as all the members will be initialised with garbage (whatever happens to reside in memory at the point of instantiation). This raises the potential for accessing that garbage data before it is assigned.

foo f;

/*

any attempt to access f's members at this point

will result in undefined behaviour

*/

f = (foo) {.m_data1=42, .m_data2=1.99};

/* f is now initialised */

In C++, a struct is exactly the same as a class except it has public access by default, rather than private access by default. As such, you can use the class constructor initialisation list to initialise the data members to default values:

struct foo

{

foo():m_data1(42),m_data2(1.99){}

private:

int m_data1;

double m_data2;

};

Typically, you will also provide an overloaded constructor to initialise the members to more specific values:

foo(const int data1, const double data2): m_data1(data1), m_data2(data2){}

However, you can also combine the default constructor and the overloaded constructor to produce an overloaded default constructor:

foo(const int data1=42, const double data2=1.99): m_data1(data1), m_data2(data2){}

You can also implement a copy constructor with an initialisation list:

foo(const foo& f):m_data1(f.m_data1),m_data2(f.m_data2){}

Note that initialisation lists are more efficient than using the constructor body to perform initialisation. Therefore you should always perform as much initialisation as possible in the initialisation list and only use the constructor body for any additional initialisation processes that cannot be handled by the initialisation list. Ideally, members should be initialised in the same order they were declared.

Note also that the initialisation list employs construction syntax rather than assignment syntax, even for primitive data types. If the class or structure is a derived class, you can also invoke specific base class constructors through the initialisation list. Again, these base classes should be listed in the same order specified by the inheritance list, and should be listed BEFORE the data members since the base classes must be constructed first.

Write a programme in C plus plus for creating a payslip?

Payslips come in many shapes and forms so it is not possible to provide a fully-working example without some additional information. However, the basic information on any payslip will be the employee's name, reference number and tax code, hours worked and at what rate, gross pay, tax, NI and nett pay, along with the year-to-date totals. Thus in order to create a payslip, you must draw this information from a database and format it so that it all prints within the bounds of a blank, pre-printed payslip.

For additional information I would suggest asking one of the many C++ programming forums. However, no-one is going to write the program for you unless you pay them handsomely. So do as much as you possibly can by yourself and only ask when you're stuck with a specific problem.

How can you disconnet passtime plus system?

Yes, it is spliced into the starter, find the box, and study it. It's really simple, just unplug and replug - matching color to color.

What is the difference between interpretation and compilation in computer programming?

Interpretive languages compile blocks of code into machine code, execute them, and then move onto the next block. The blocks may be as little as a single statement, but once each statement is executed, the machine code is lost. This means that functions must be recompiled every time they are called. Ultimately, performance suffers because every block must be interpreted before it can be executed. Moreover, the program must always be executed within the interpreter; you cannot create standalone programs.

Compiled languages pre-compile the entire program to produce a standalone machine code executable. As a result, compiled programs execute many times faster than interpretive languages.

C++ and Java are both compiled languages however Java programs are compiled to byte code rather than machine code. The byte code must then be interpreted by the Java virtual machine in order to execute. As a result of this interpretation, Java programs do not perform well compared to equivalent programs written in C++.

C plus plus code to calculate a right angle?

Right angles are always 90 degrees. There is no need to calculate this; an angle is either 90 degrees or it is not. The following inline function is all you really need:

inline const bool IsRightAngle(double angle) {

return(angle==90.0); }

What is button in Visual C plus plus?

A button is more correctly named a command button. It is an ActiveX control that is derived from a CWnd object. Command buttons can be resized, restyled, and can be assigned a caption and/or an image. Programmers can override command button methods (such as OnLButtonDown/OnLButtonUp and OnKeyDown/OnKeyUp) to invoke specific actions.

Are reference variables are NOT available in C?

Yes, reference variables are permitted in C. However a reference variable in C is simply another name for a pointer variable, because pointers can be dereferenced to allow indirect access to the memory they point at.

However, in C++, references are neither pointers nor variables, they serve another purpose altogether, one which is not available in C. So the real answer is that C++ references are not available in C, but reference variables are.

Although it is common practice to avoid using the term reference lest there be any confusion with a C++ reference, it doesn't alter the fact that a C pointer variable is also a C reference variable. They are one and the same thing.

In C++, a reference is entirely different from a C reference. More specifically, it is an alias, an alternate name, for a memory address. Unlike pointer variables, a reference consumes no memory of its own. That is, you cannot obtain the address of a reference since there is none to obtain. Hence the 'address of' operator (&) is used during instantiation to signify that the instance name is actually a reference of the specified type, and not a variable of the type.

The address being referred to must also be assigned to the reference when the reference is instantiated. That is, you cannot declare a reference and then assign a memory address to it elsewhere in your code. By the same token, you cannot subsequently reassign a reference while it remains in scope. Remember, references are not variables. What they refer to may be variable, but not the reference itself. In that respect it is not unlike like a constant pointer to a variable.

References allow you to refer to the same memory address using one or more aliases. Since they consume no memory of their own, there is no practical limit to the number of aliases you can have in your C++ program. When compiled, all references to the same memory are effectively replaced with the actual memory address, or the address of a static location containing the actual memory address if the address was allocated dynamically. So while references are often implemented just as if they were pointers, this is only of concern to developers of C++ compilers. In more general C++ source code, the two concepts must be kept distinct.

C++ references are also much easier to work with than pointers. Whereas pointers to allocated memory must be manually released when no longer required, references do not. When a referenced object falls from scope, the object's destructor is called automatically. More importantly, references can never be NULL so, if you have a reference, a valid object of the specified type is guaranteed to exist at the referred memory location. The only time you will encounter problems with references is when you point at them, and then delete the pointer! If you subsequently access the referenced memory or the reference falls from scope, your program will exhibit undefined behaviour. Obviously this is a programming error, but these type of problems exist with pointers in general, hence pointers are best avoided as much as is possible. If an object is guaranteed to exist, then refer to it, don't point at it. Only use a pointer when an object is not guaranteed to exist, or if you need to change the address being referred to. And if a pointer is non-NULL, refer to the object.

What relationship does a stack and recursion have?

Local variables and formal parameters are stored on the stack. Recursion is the process of calling a function from within itself, saving local variables and formal parameters. Since the stack is a recursive last-in-first-out data structure, the best place to place variables for each step is on the stack.

The classic example is N Factorial...

int nfact (int n) if (n == 2) return n else return nfact (n - 1);

This example only has one formal parameter. If you called it as nfact(10), by the time n reached 2 there would be 9 return addresses and 9 formal parameters on the stack, and nfact() would have been called 9 times. At that point, the stack unwinds due to the return n statement, and the final result is 3628800.

A simplified picture of the stack at n==2 would look like ...

10
return address of caller
9
return address in nfact
8
return address in nfact
7
return address in nfact
6
return address in nfact
5
return address in nfact
4
return address in nfact
3
return address in nfact
2
return address in nfact

More complex code could easily create and manipulate local variables, so long as they were on the stack. Each recursive instance, then, would be properly isolated from its parent and child, and they would not interfere with each other.

How do you get to the g plus plus compiler once it is installed on ubuntu?

The C++ compiler is invoked with g++, however on many systems it is installed as c++. Consult the documentation for information on the command line options.

Is it true that wrapping up of data of different types into a single unit is known as encapsulation?

Not quite. Encapsulation means to combine data and the methods that work upon that data into a single unit (an object), such that access to both the data and methods is restricted in a controlled manner. Data-hiding is fundamental to encapsulation.