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

Syntex for accessing data members of the structure in c plus plus?

Use the member accessor (.) operator.

struct object {

int m_data;

};

int main()

{

object o;

o.m_data = 100;

std::cout << o.m_data << std::cout;

return(0);

}

C plus plus program that display student name course and grade using arrays of strings?

enum field { name, course, grade }; std::string student[3];

student[name] = "Joe Bloggs";

student[course] = "C++ Programming";

student[grade] = "A+";

Why the format specifiers are not used in cpp?

You might be wrong: printf and scanf are usable in C++ just as in C. With format specifiers.

The most common function of an array is to store variables however there will be times when an array is used to store objects. briefly describe four such objects?

Any name can be placed in an array, be it a primitive name or an object name, even a function pointer. Four examples of common objects that may be placed in an array include any object defined in the STL (standard template library), which includes vectors, lists, iterators and maps. All are self-explanatory, although a vector is simply an array implemented as an object. Therefore an array of vectors is nothing more than an array of arrays (effectively a multi-dimensional array). However, vectors are the "correct" way of implementing arrays in C++ (unless you specifically wish to use C-style code in your C++ projects), thus a multi-dimensional array is best implemented as a vector of vectors.

Most c plus plus programmers use uppercase letters for variable names true or false?

False. Most C++ programmers use uppercase for macros (precompiler definitions), making them less likely to be confused with actual variables, constants or functions in the C++ source code. Macros are not actually part of the C++ language because the compiler never sees them, but they allow the precompiler to perform preprocessing tasks that would be difficult or impossible to accomplish with C++ code alone.

How do you convert time from 24 hour to 12 hour in C Plus Plus?

#include<iostream>

using namespace std;

int main()

{

int t1;

int t2;

char a;

char p;

cout << "enter two numbers for example 0930 for 9:00 !" << endl;

cin >> t1;

cout << "enter number two" << endl;

cin >> t2;

cout >> "totel amount of hours are">>h>>endl;

system("PAUSE");

return 0;

}

What is the significance of asmlinkage modifier in C?

The asmlinkage tag tells gcc that that the function should not expect to find any of its arguments in registers (a common optimization), but only on the CPU's stack. Many kernel functions use the fact, that system_call consumes its first argument, the system call number, and leaves other arguments (which were passed to it in registers) on the stack. All system calls are marked with the asmlinkage tag, so they all look to the stack for arguments.

What are the types to pass a structure to functions?

A structure is a type so you just need to pass the structure as you would any other data type: by reference or by value.

What are the features differentiate java from c plus plus and c?

Java compiles to byte code suitable for interpretation by the Java virtual machine, whereas C and C++ both compile to native machine code. Thus C and C++ programs perform better than equivalent Java programs. However, Java programs can run on any machine with a suitable Java virtual machine implementation, which is pretty much everything these days. C and C++ programs must be compiled separately upon each supported platform, provided the source code is either generic or includes compiler directives to filter the platform-specific code. Java programs need only be compiled once, thus cross-platform development is greatly simplified, at the cost of performance.

C and Java cannot really be compared since C does not support object-oriented programming concepts. C++ is object-oriented but, unlike Java, it is not 100% object-oriented as it supports the concept of primitive data types that it inherited from C. Java is more closely related to C#, which is 100% object oriented.

How do arrays differ from single memory position variables?

A single memory position variable can store only one value of its type.

An array can store n number of values, where n is the size of the array.

Program to find factorial of a number using inheritance?

/*71.PROGRAM TO FIND FACTORIAL OF A NUMBER USING RECURSION*/

#include<stdio.h>

#include<conio.h>

int fact(int);

void main()

{

int n,f;

clrscr();

printf("Enter number whose factorial is to be calculated:

");

scanf("%d",&n);

if(n>0)

{

f=fact(n);

printf("factorial of %d is %d",n,f);

}

else

printf("Factorial of numbers less than 1 does not

exist");

getch();

}

int fact(int n)

{

int facto=1;

if(n>1)

facto=n*fact(n-1);

else

return 1;

return(facto);

}

What is x2 plus 3x plus 7 equals 6x plus 18?

xx+3x+7=6x+18

xx+3x+7-(6x+18)=6x+18-(6x+18)

xx-3x-11=0

Factors of -11:

1,-11

-1,11

Doesn't factor evenly, use quadratic

Can you delete array?

If the array was allocated with new, then delete it with delete []. Otherwise, if it was allocated with malloc() then delete it with free. Otherwise, you cannot delete it because it was pre-allocated at link-load time by the compiler.

What function is used to release the memory on heap?

The free() function releases memory obtained with the malloc() family of functions. The delete and delete [] operators release memory obtained with the new operator.

Note: realloc() can allocate and free memories as well as reallocate.

Is a subclass only method through a base class variable allowed?

Yes, it is allowed, but it is considered poor design to do so. The problem is not that your subclass contains a specialised, non-generic method, it is only in how you are accessing it. When you hold a variable, pointer or reference to a base class then you are expected to treat that class generically. If you cannot do this, then you should seriously rethink your design. Always ask yourself why you are attempting to extort non-generic behaviour from a generic class.

That said, it is sometimes the case that the base class design is outwith your control. It is still the result of poor design but in these cases you have little option but to make use of dynamic downcasts in order to extort specific behaviour from your subclass. The only alternative is to veto the base class completely and write your own, but if this requires a major rewrite then a dynamic downcast might be the better option in the short-term.

Another option would be to use an intermediate subclass, but this is only suitable when you have two or more subclasses that share a common interface, but where that interface is not generic enough for the base class itself. This won't resolve the problem of extorting non-generic behaviour when you hold a reference to the base class, but it can help reduce the number of dynamic downcasts to a minimum (the ideal situation is no dynamic downcasts, but the option is there if you really must use it).

Percolating the specific implementation into the base class can often be a simpler option. Although you should generally avoid this, if you are designing a closed hierarchy then the cost of the reduced encapsulation may be considered a more preferable option to the additional expense of a dynamic downcast.

Can you declare float variable as increment operator in for loop?

I don't really understand your question, but for example the following code is perfectly legal:

float f;

for (f=0.0; f<=1.00001; f += 0.1) printf ("%g\n", f);

How to print the reverse of an array without using backward loop?

int youArray[arraysize] = {...};

...

for (int i = 1; i <= arraySize; i++)

{

cout << yourArray[arraySize - i] << endl;

...

}

...

Which base class member functions are not inherited by a derived class?

Derived classes only inherit the protected and public members of their base classes. Private member functions cannot be inherited by a derived class.

Write a program that will prompt you to give the number of pods and the number of beans per pod and calculate the total number of beans use C plus plus?

#include

using namespace std;

int main()

{

int pods,beans;

float total;

cout<<''enter the number of pods";

cin>>pods;

cout<<'enter the number of beans";

cin>>beans;

total=pods+beans;

cout<

return 0;

}

What is step involve is using data file in c plus plus programming?

Declaration of file pointer

opening of file in desired mode.

performing the desired operation.

closing the file