Does pure virtual function contain any body?
A pure-virtual method may provide an implementation, but it is not a requirement. If you find that all your derived classes have the exact same implementation (either in whole or in part), then it makes sense to place that implementation within the abstract class, thus ensuring consistency across all derivatives (and thus reducing maintenance). Each derived class can then explicitly call the base class method and optionally augment it with a more specific implementation where required, much as you would with a non-pure virtual method. The only real difference is that you are expected to provide an override for a pure-virtual method, whereas overriding a non-pure virtual method is always optional.
Is vc plus plus object oriented language?
I thought its a development tool..
this is what i got from wiki ---
is a commercial (free version available), integrated development environment (IDE) product from Microsoft for the C, C++, and C++/CLI programming languages. It has tools for developing and debugging C++ code, especially code written for the Microsoft Windows API, the DirectX API, and the Microsoft .NET Framework.
There's no need to create a class to do this as std::string already does this and a lot more besides. The following class will do exactly as you've asked, but it's really just a wrapper for a std::string and achieves absolutely nothing.
#include<iostream>
class string{
public:
string(std::string s=""):m_str(s){}
string(const string& s):m_str(s.m_str){}
const std::string& get_string(){return(m_str);}
private:
std::string m_str;
};
int main()
{
string name1;
string name2("minu");
string name3(name2);
std::cout << "name1 = '" << name1.get_string().c_str() << "'" << std::endl;
std::cout << "name2 = '" << name2.get_string().c_str() << "'" << std::endl;
std::cout << "name3 = '" << name3.get_string().c_str() << "'" << std::endl;
return(0);
}
Output:
name1 = ''
name2 = 'minu'
name3 = 'minu'
What are the conditions to swap in c plus plus without temporary?
You can swap two integers without temporary storage by bitwise exclusive-or'ing them in a specific sequence...
a ^= b;
b ^= a;
a ^= b;
How can you let the user enter a string and store it into a char array in C plus plus?
Here is an example:
// Example.cpp : Defines the entry point for the console application.
//
#include <stdio.h>
int main();
{
char example; /*Giving example the initialization char*/
printf("What value do you want example to have: ");
scanf("%s", example); /*This is where the value you have entered is being assigned to example*/
printf("Hello %s", example);
return 0;
}
Here is the program running:
What value do you want example to have: dude
Hello dude
What is a Concrete class in c plus plus?
A concrete class is a complete type, as opposed to an abstract class which is an incomplete type.
class A {
public:
virtual void f () = 0; // pure-virtual; class A is abstract
// ...
};
class B : public A {
public:
void f () override; // overrides A::f(); class B is concrete
};
class C {
// no pure-virtual methods; C is a concrete type
// ...
};
Template classes are generic types. We usually evolve a generic type from a concrete type rather than write a template class from scratch, a technique known as lifting. The concrete type provides us with the complete implementation which is useful for testing and debugging purposes. When the concrete class is fully-implemented and error-free, we can generalise to produce the generic type.
How can the base class data be accessed from database directly using derived class?
In order to access a base class member the base class member must be declared protected or public. Private data is only accessible to members of the same class and to friends of the class. I'm not entirely sure what you mean by accessing from a database. A derived class does not require a database in order to access its base class members, it only requires protected access at the very least. Note that although you can declare derived classes to be friends of their base classes and thus allow private access, it would be an unusual design since base classes should never know anything about any of their derivatives.
Is run time initialization of an array an initialization or an assignment?
It is an initialisation. You cannot assign values to a dynamic array until it has been initialised. Static arrays can be initialised at compile time. They can also be assigned at compile time.
void main()
{
// Compile time:
// =========
// Initialise a static array.
int arr1[10];
// Initialise and assign a static array.
int arr2[10] = {0,1,2,3,4,5,6,7,8,9};
// Runtime:
// ======
// Dynamic array (size unknown, no memory allocated)
int* pArr[];
// Initialise (size known, allocate memory, 40 bytes):
pArr = ( int* ) malloc( 10 * sizeof( int ));
// Assign (set values of elements):
int x;
for(x=0;x<10;++x)
pArr[x] = x;
// Uninitialise (release memory).
free( pArr );
return( 0 );
}
What is an exception With an example program explain how it is handled?
An exception is literally that: an exception. Exceptions are thrown when something that shouldn't happen does. For example, if you're trying to turn "Hi" into an Integer, you'll get a NumberFormatException (in Java.) If there is nothing in place to handle an exception, the program will crash. Try-catch blocks are used for exception handling within methods, and exception throwing is used to give out exceptions, or let a different method handle it.
Example program (Java):
class ex{
public static void main(String[] args){
String Strx = "5a";
int x = 0;
try{
x += Integer.parseInt(Strx);
}catch(NumberFormatException e){ // If Strx is not an Integer
x += Integer.parseInt("5");
}
System.out.println("The value of x is " + x); // The value of x is 5
}
}
Alternatively, you could remove the try-catch blocks, and simply write "public static void main(String[] args) throws NumberFormatException" in the 2nd line of the program.
What is the sudoku solver c plus plus code?
The code is below and i should also explain the algorithm. Well, What we are doing here is that we already defined the size to be 9x9 sudoku and are getting values using loops. All the empty spots are given UNASSIGNED value. Then we have functions to tell that if it is safe to put a value in the empty box by calculation and according to the rules of Sudoku it checks for is there any other some number horizontally and vertically and do the sum of the row and column is less than or equal to required or not. If the functions returns true then the program puts the value there.
Do reference variables occupy memory in c?
All references must be non-null, therefore they will always have memory allocated to them. A reference is simply a non-null memory location that stores a specific type of variable, as determined by the reference's type. The reference name is an alias (a token) for the memory location, in much the same way that an array name is an alias for the starting address of the array.
A pointer variable is different in that memory must be set aside for the pointer variable itself, in addition to the memory it actually points to. On a 32-bit system, 4 bytes must be allocated to every pointer variable, to store the memory address that they point to, which could be null. But references only occupy the memory they actually refer to, which can never be null (a null reference will in fact render the program invalid).
Write a Program for Array implementation of queue and stack using exception handling.?
include <iostream>
using namespace std;
#define SIZE 10
template <class StackType> class stack {
StackType stck[SIZE];
int topOfStack;
public:
void init() {
topOfStack = 0;
}
void push(StackType ch);
StackType pop();
};
template <class StackType>
void stack<StackType>::push(StackType ob)
{
try {
if(topOfStack==SIZE) throw SIZE;
} catch(int) {
cout << "Stack is full.\n";
return;
}
stck[topOfStack] = ob;
topOfStack++;
}
template <class StackType>
StackType stack<StackType>::pop()
{
try {
if( topOfStack == 0)
throw 0;
} catch(int) {
cout << "Stack is empty.\n";
return 0;
}
topOfStack--;
return stck[topOfStack];
}
int main()
{
stack<char> stack1, stack2;
int i;
stack1.init();
stack2.init();
stack1.push('a');
stack2.push('x');
stack1.push('b');
stack2.push('y');
stack1.push('c');
stack2.push('z');
for(i = 0; i <3; i++)
cout << "Pop stack1: " << stack1.pop() << endl;
for(i = 0; i <4; i++)
cout << "Pop stack2: " << stack2.pop() << endl;
// demonstrate double stacks
stack<double> doubleValueStack1, doubleValueStack2; // create two stacks
// initialize the stacks
doubleValueStack1.init();
doubleValueStack2.init();
doubleValueStack1.push(1.1);
doubleValueStack2.push(2.2);
doubleValueStack1.push(3.3);
doubleValueStack2.push(4.4);
doubleValueStack1.push(5.5);
doubleValueStack2.push(6.6);
for(i = 0; i <3; i++)
cout << "Pop doubleValueStack1: " << doubleValueStack1.pop() << endl;
for(i = 0; i <4; i++)
cout << "Pop doubleValueStack2: " << doubleValueStack2.pop() << endl;
return 0;
}
Project - Settings - Link Tab Click on folder that has header files and librarys in the tree view Push OK
C plus plus program for displaying position and frequency of a number in the given list?
#include<iostream>
#include<vector>
#include<list>
#include<map>
#include<time.h>
int main()
{
srand ((unsigned)time(nullptr));
// Create a list of 100 values in the range 0 to 9.
std::cout << "Number list:\t";
std::list<size_t> numbers;
for (size_t i=0; i<100; ++i)
{
numbers.push_back (rand()%10);
std::cout << numbers.back() << ' ';
}
std::cout << '\n' << std::endl;
// Determine position(s) of each number.
std::map<size_t, std::vector<size_t>> map;
size_t pos = 0;
for (auto it=numbers.begin(); it!=numbers.end(); ++it)
map[*it].push_back(pos++);
// Print number, frequency and position(s).
for (auto it=map.begin(); it!=map.end(); ++it)
{
std::cout << "Number:\t\t" << (*it).first << std::endl;
std::cout << "Frequency:\t" << (*it).second.size() << std::endl;
std::cout << "Postions:\t";
const std::vector<size_t>& positions = (*it).second;
for (auto it=positions.begin(); it!=positions.end(); ++it)
std::cout << (*it) << ' ';
std::cout << '\n' << std::endl;
}
}
Can you assigned value of int to a ordinary pointer?
Yes, with type-cast (but I don't see why you should):
char *ptr = (char *)300;
What must identifiers start with?
the name of an identifier consists of letters and digits but name always starts with a letter.
How many types of selection statements in c language?
there are two types of selection statements in c-language they are if-else and switch case.these two are known as selection statements,because their syntax is like this,
if-else syntax:-if(condition)
{
statements
}
else
{
statement
}
in the abow syntax it contains two blocks first one is if and second one is else in 'if' it fills with required condition if the condition is satisfied then it execute the if block,whether it is false it execute the else statements.
switch case syntax:-
switch(condition)
{
case.1:statements;
case.2:statements;
case.3:statements;
.
.
.
case.n:statements;
default:statement;
}
in abow switch case we can select any case and execute,in this selection statement gives the fiexibulity to the user.it contains default statement it shows the wrong selection in these cases.
examples programs to these statements:-
1.biggest of two numbers program?
main()
{
int a,b,c;
printf("enter a,b values");
scanf(&a);
scanf(&b);
scanf(&c);
if(a>b)
{
printf("a is big");
}
else
{
printf("b is big");
}
}
out put:-
enter a,b values 8,5
a is big
enter a,b values 3,9
b is big
2.perform arithmetic operation intwo numbers?
main()
{
int a,b,c,d;
printf("enter a,b values");
scanf(&a);
scanf(&b);
scanf(&c);
printf("enter your choice"&c);
switch(c)
{
case.1:d=a+b;
printf("d value is"&d);
case.2:d=a-b;
printf("d value is"&d);
case.3:d=a*b;
printf("d value is"&d);
default:printf("wrong selection");
}
}
out put:-
enter a,b values 6,5
enter your choice 1
d=11
enter your choice 2
d=1
enter your choice 3
d=30
A compound statement that is formed by joining two statements with the word and is called a?
conjunction...your welcome
Which header file needs to be included in a program that uses the data types ifsteam and ofsteam?
#include <fstream>
How do we write c program without using swap to interchange values by accessing another variable?
int a,b;
a=a+b;
b=a-b;
a=a-b;
that's it simple