What are risks of object oriented development?
There are no risks, as such. The point of object-oriented programming is to reduce the risks of invalidating data unintentionally. With a well-designed class system, there should be no risk whatsoever. With a badly-designed class system, the risks are as a great as those with structured or procedural programming.
A method that is automatically called when an instance of a class is created?
The constructor of a class is automatically called when an instance of the class is created (using new in C++). The constructor method has the same name as the class that it is a part of. Constructors have no type and do not return anything.
Similarly, the destructor is automatically called when the instance of the class is destroyed. The destructor is the same name as the class and is preceded by a tilde (~)
For example:
class Example
{
public:
Example() // Constructor
{
printf("Object created\n");
}
~Example() // Destructor
{
printf("Object destroyed\n")
} };
int main()
{
Example* x = new Example(); // Creates object, calls constructor
delete x; // Calls destructor, deletes object
return 0;
}
How do you concatenate a string?
v can concatenate two string by using a function like: select CONCAT( CONCAT('ename','e_mrks'),"name","marks" from student;
Can structured techniques and object-oriented techniques be mixed?
Yes, in fact, they are always mixed. You always write structured procedures (the main function, at least), that will control your objects. Objects can't work just by themselves. At least, that's how it is in C++.
How to check whether variable is allocated on stack or heap in CPP programmatically?
You can not check whether a variable (object) is allocated on the stack or heap in CPP programmatically.
If you are being passed the address of an object, you may not make any assumptions about how that object was allocated unless you are also passed information about that allocation. The "owner" or allocator of the object knows how that object was allocated. The "user" of the object does not know, unless told, and should not even care.
If you want to write code that transfers "ownership" of an object to another "owner", you may, but that new "owner" must be told how to manage the object.
It is possible to look at the address of the object, and infer locality based the value of that address, but that is extremely fragile, because it is implementation specific. Do not even consider it.
It IS possible to create a class that can track whether it was allocated on the stack or heap. To do so, you need to override the desired operater new() and operate delete() functions in your class, such that your class will be allocating instances of the class itself. Then you need a means to signal from the operator new() function back to the class instance that it was allocated via new (since operator new executes before the class constructor). One simple way to do this is to keep a global list of all the objects you've created for the class (via operator new); the class constructor can then lookup the this pointer in the list to see if it was allocated with new, and set a flag accordingly. In this case, operator delete() would need to remove items from the list.
If your program is multi-threaded, access to this global list would either need to be protected by a semaphore or the list could reside in thread-local storage.
What was the most important capability of C plus plus that C did not provide?
The most important capability is Object Oriented Programming (OOP) principals, which necessitated the inclusion of classes. That was the main reason Bjarne Stroustrup developed C++ in the first place (indeed, C++ was originally called 'C with Classes').
How do you do image cropping in visual c plus plus 6?
Use a bitmap view control setting the width and height to the size of the cropped image. Then move the image within this window so the portion you wish to see is centred in the view. For example, suppose you have a 50x48 pixel image and you want to crop to 48x48. In other words you want to remove two columns of pixels from the left side, or one column from each side, or two from the right side. Start by creating a view of the required size (48x48). Then load the bitmap and set the left coordinate to either -2, -1 or 0, relative to the view.
Is there any difference in allocation of the memory of the member of class and object?
A class is the definition of a type -- it consumes no memory in an off itself. An object is an instance of a class, and therefore consumes memory, equal to the total size of all its member variables (attributes), including base class members, plus padding for alignment. If the class declares any virtual methods, a v-table is also created, which consumes additional memory.
What is the difference between destructors in c plus plus and c sharp?
In C# only class instances can have a destructor, whereas both class and struct instances can have a destructor in C++. While syntactically similar, a C++ destructor executes exactly as written, whereas a C# destructor merely provides the body of the try clause of the class' finalize method.
Write a programme for substraction of two numbers in c language?
substracion of any two number program in c
Wrenn first referred to cultural encapsulation in his 1962 work, The Culturally Encapsulated Counselor. His term is cited in numerous current works referring to culturally competent counseling. Cultural encapsulation is the process of working with clients from an ethnocentric perspective, where one does not effectively understand the world view and culture of origin of the client, nor do they integrate this knowledge into the counseling process. Thus, cultural encapsulation is problematic in therapy and can negatively impact the therapeutic alliance.
Call by value essentially passes a copy of an object's value whereas call by reference essentially passes the object itself. Pass by reference is the preferred method whenever possible as call by value will automatically invoke the object's copy constructor, which is often unnecessary, especially if the object is not affected by the function call (pass by constant reference).
How do you print characters up and down in c plus plus vs. side to side?
Place a newline (linefeed) character ('\n') after each character you print.
Depending on the device you may need a carriage return as well ('\r'). Usually the carriage return comes before the linefeed, but can often be treated as a string of two characters ("\r\n").
Write a program to find a substring in a given string in c?
#include<stdio.h>
#include<conio.h>
int main()
{
int i=0,j=0,k=0,count=0,l=0,k1=0;
char a[80],b[80];
clrscr();
printf("\nEnter main string:-\n");
gets(a);
printf("\nEnter sub-string:-\n");
gets(b);
l=strlen(b);
while (a[i]!=EOF)
{
if (a[i]==b[j])
{
i++;
j++;
k1=1;
if (j==l)
{
j=0;
k=1;
count=count+1;
}
}
else
{
if (k1==1)
{
j=0;
k1=0;
}
else
i++;
}
}
if (k==1)
{
printf("\n\nThe given sub-string is present in the main string.");
printf("\nIt is present %d times.",count);
}
else
{
if (k==0)
printf("\n\nThe given sub-string is not present in the main string.");
}
}
Platform dependent, possibly LIBC.LIB or something like that.
How do you read a word with blank space in c plus plus?
A word with blank spaces is not a word, it is a collection of words, possibly a sentence, a paragraph or an entire book. These are strings (character arrays) and you can read these just as easily as you can an individual value, using the std::getline() function. The following example demonstrates this.
#include<iostream>
#include<sstream>
int main()
{
std::string s;
std::cout<<"Type some words: ";
std::getline( std::cin, s );
std::cout<<"You typed:"<<s.c_str()<<std::endl;
}
What is searching in c plus plus language?
Searching in C++ is the same as searching in any language. It is the process of locating a subset of data within a data set, whether to determine if the subset exists or does not exist in the set. The set of data is typically a set of objects contained in an array, a list, a vector, or some other container object that can be iterated one element at a time, while the subset is typically a single object which may or may not exist in the set of objects. In other words, you must search for a specific value in order to ascertain if that value exists in the set.
All search algorithms have a time complexity which can be expressed using big-O notation. The best case is O(1), meaning constant time. That is, the time taken to search for any value in the set is exactly the same, regardless of the value's position in the set. Unfortunately, this is impossible as O(1) can only be guaranteed when the value being sought happens to be the first value in the set or the set only has one value. The worst case is O(n) for a set of n elements, where every value in the set must be inspected. This can occur when the value being sought does not exist or is the final element in the set.
The structure that contains the data can have a large effect on time complexity. For instance, with a linear structure, such as an array, the average time complexity is O(n/2) if the array is in sorted order. However, this can be reduced to O(log n) by starting the search in the middle of the structure rather than at the beginning. If the middle value is greater than the value being sought, you can eliminate all the elements to the right of that value. If it is less, you can eliminate all the values to the right. You then repeat the process using the remaining elements, essentially halving the amount of data to be searched at each stage until there is only one element left to inspect. If it is not the value you are looking for, the value does not exist in the set.
It is exactly what it says it is: a pointer to a base class. The assumption is that you have an object to a derived class, but actually hold a pointer to its base class. The following minimal example demonstrates this:
class base{ public: virtual ~base(){} };
class derived: public base{};
int main()
{
base* p = new derived; // base class pointer to a derived instance.
delete( p );
return(0);
}
Note that derived has an "is-a" relationship with base (derived is a base), thus the above code is perfectly legal. Moreover, because the base class destructor is declared virtual, when you delete p you automatically destroy the instance of derived before the instance of base, thus ensuring a clean teardown (without a virtual destructor, a dangling reference to derived would be left behind, which will only lead to problems further down the line).
Taking things further, calling any virtual methods upon the base class automatically invokes the override in your derived class, thus ensuring that your derived class behaves accordingly, polymorphically, even though you only hold a pointer to the base class. In other words, the base class provides a generic interface that is common to all its derivatives, and you can call those generic methods via the base class pointer without ever needing to know the actual derived type.
Remember that base classes should never know anything about their derivatives since a new derivative could be created at any time in the future and would therefore be impossible to predict in advance. But so long as the derivative makes use of the virtual functions (the generic interface) provided by the base class, there is never any need to know the actual type. The derivative's own v-table takes care of that for you, thus completely eliminating the need for expensive runtime type information and dynamic downcasts (which is always a sign of poor class design). This then makes it possible for your derived class overrides to call non-generic methods, thus extorting non-generic behaviour from what is essentially a generic, base class pointer.
Explain about exception handling with multiple exception?
Exception handling in Java is done through a try-catch-finally block. The "try" block of code is where you put the code which may throw an exception. The "catch" block of code is where you put the code which will execute after an exception is thrown in the try block. This is often used to display an error message, or to mitigate problems caused by the exception. The "finally" block is where you put code that you want to execute after the try and catch blocks have been processed.
// example code for catching exception while reading from a file
try {
// this line of code can throw a FileNotFoundException
FileReader in = new FileReader("myfile.txt");
// this line of code can throw an IOException
in.read();
} catch(FileNotFoundException ex) { // catch first exception type
System.err.println("Cannot find myfile.txt!");
} catch(IOException ex) { //catch second exception type
System.err.println("Cannot read from myfile.txt!");
} finally { // no matter what we want to close the file, so do it here
// however, this line can also cause an exception, so we need to catch that, too
try {
in.close();
catch(IOException ex) {
// not much we can do about an exception that occurs here
}
}
Why you have to declare variable first in turbo c?
All variables (and constants) must be declared before they can be used. This is so the compiler knows exactly how much memory to allocate to the variable, as the declaration tells the compiler exactly what the variable's type is.
What is an infinite loop in c plus plus?
An infinite loop is one sequence of commands that just repeats over and over again forever. When it comes to creating an infinite loop you can use the:
for
do while
and do statements.
using the keywords 'true'
What is pure object oriented language?
Object-oriented (OO) applications can be written in either conventional languages or OOPLs, but they are much easier to write in languages especially designed for OO programming. OO language experts divide OOPLs into two categories, hybrid languages and pure OO languages. Hybrid languages are based on some non-OO model that has been enhanced with OO concepts. C++ (a superset of C), Ada 95, and CLOS (an object-enhanced version of LISP) are hybrid languages. Pure OO languages are based entirely on OO principles; Smalltalk, Eiffel, Java, and Simula are pure OO languages.
Reference: Tokar, Joyce L. "Ada 95: The Language for the 90's and Beyond."
" According to me JAVA is not a pure oop Language ,because java contains primitive datatypes that's not an Objects."
example:java.
Iteratively divide N by 10, recording the remainder of the division at each step, until N has value of zero. Then interatively recall the remainders, in the same order they were retrieved, and write them from left to right.
What is the declaration of overloaded pre-increment operator implemented as member function?
The pre-increment operator accepts no parameters and returns the same object (by reference) after incrementing.
The post-increment operator accepts an unused (dummy) integer parameter and returns a copy of the object (by value) that is made immediately prior to incrementing the object.
Note that it is good practice to always use the pre-increment operator even if a post-increment operator exists. The only time you should ever use a post-increment is when you actually store the return value. If you don't store the return value then you will end up making an unnecessary copy, which is highly inefficient. With primitive data types that are less than or equal in length to a pointer this isn't a major issue, but it's good practice nonetheless. If you do it for primitives then you're far more likely to remember to do it for class instances as well.
The following example emulates an integer type with pre-increment and post-increment operators implemented:
class Simple
{
public: // Construction:
Simple(int data = 0):m_data(data){}
Simple(const Simple& simple):m_data(simple.m_data){}
public:
// Assignment:
Simple& operator= (const Simple& simple) {
m_data = simple.m_data;
return( *this ); }
// pre-increment:
Simple& operator++ () { // no parameters!
++m_data; // increment this object
return( *this ); } // return a reference to this object
// post-increment:
Simple operator++(int) { // int parameter (not used)!
Simple copy( *this ); // call the copy constructor
++m_data; // increment this object
return( copy ); } // return the copy (by value)
private:
int m_data;
};