What are input output streams in c plus plus?
The term stream is a generic abstraction that says nothing about the implementation. However, if we use the analogy that gave it its name, a stream of water, we can better understand how a stream works. A water stream allows water to flow from one point to another in one direction only (downstream, with the flow of the current). If we were to throw a stick into the water, it would be carried downstream by the water where it could then be extracted. Sticks can be inserted or extracted automatically by devices, thus allowing information to pass between those devices.
A file stream is a stream that is associated with a device representing a file. If the file is upstream then we can use the stream to extract information from the file. When we extract information from a stream, that stream is known as an input stream; it provides us with information. Conversely, if the file were downstream then we can use the stream to insert information into the file. When we insert information into a stream, that stream is known as an output stream; it carries information away from us.
An input/output stream is one where we can both insert and extract information. An input/output file stream is a typical example: we can extract data from the file associated with the stream, process the data (modify it in some way), and then insert the modified data back into the same file. To implement an input/output stream, we simply use two streams associated with the same device: one specifically for input operations, the other specifically for output operations. This implementation detail is hidden from the user, so the stream appears to be a bi-directional stream as far as the user is concerned.
When a piece of software running for an extended time uses more and more memory. The software is not releasing its resources correctly! And so the machine cannot recoup memory.
It is possible that eventually the machine will crash, or the offending software will need restarted.
What are the applications of An Abstract Class in c plus plus?
An abstract class is a class that has a pure virtual function.
A pure virtual function can be used in a base class if the function that is virtualised contains parameters that can and should be interchangeable, but the function should remain intact.
For example, there is a base class Object in a game that will contain movement for simple objects, but the movement function may need to use different parameters per object.
C plus plus supports more object oriented Programming features as compared to JAVA?
No. Java is 100% OOP while C++ supports the concept of primitives (which it inherited from C). Thus C++ supports far more features than Java, but it does not support any more OOP features than Java. Note that there are only four primary OOP features: encapsulation, abstraction, inheritance and polymorphism. Anything beyond that is implementation-specific and outwith the scope of OOP.
What are the 6 typical c plus plus Development environment and phases?
Design, flowchart, encode, compile, test and debug.
How do you inherit from class in c?
struct SClass{
int iNumber;
int (*fpgetValue)();
int (*fpsetValue)();
}Sc;
int m_Func(){
printf("\n\n Hello How are you doing,i called by function pointer");
getchar();
return 1;
}
int _tmain(int argc, _TCHAR* argv[])
{
Sc.fpgetValue=m_Func;
Sc.fpgetValue();
return 0;
}
What are legal variable names and declarations in c and c plus plus?
Any name that is not a reserved word can be a legal variable, function or type name. All names must be alphanumeric, but they cannot begin with a digit. The C++ standard recommends that all user-defined names be written entirely in lower case with underscores for spaces. Some programmers prefer 'camel case' (such as PrintObject and MaxNumber), which was a popular convention amongst the Pascal programming community, however print_object and max_number are the C++ conventions. Names in all caps are typically reserved for macro definitions (which is effectively a separate language from C++ itself), while names with leading underscores should generally be avoided as this convention is utilised extensively within the standard library.
What c plus plus programming statements to implement data abstraction?
Data abstraction is a design concept, whereby interfaces and implementations are kept separate. That is, it should not be necessary to know how an object works in order to use it. The interface provides all you need to know.
This reflects much of real life. When watching TV, you have a remote control which allows you to select a channel, but it is not necessary to know how the TV receives and processes radio signals, nor how it separates one channel from another. Those are implementation details that are only of concern to TV engineers.
In C++, there are no statements as such to implement data abstraction. You achieve it by designing a public interface which is accessible to normal users, and a private interface that is only accessible to the class designer.
How swapping two numbers using pointer in c plus plus?
Starting with a pointer to the pointer to the first element (p1**), verify the first pointer is not null (*p1 != null), retrieve the pointer to the second element (*p2 = *p1.next) and verify it is also not null (*p2 != null), and then retrieve the pointer to the third element (*p3 = *p2.next). Note that *p3 might be null, but *p1 and *p2 must not be null, or the swap can not be performed. Note that using pointer to pointer syntax allows you to treat pointer to first element the same as pointer to subsequent element, i.e. to not need to handle the special case. Also, since you do need to modify the pointer, you need a pointer to the pointer. Set *p1 = *p2, *p3 = *p1, and *p2 = *p3. Note that these assignments must be done using the original values, not the intermediate value, so you will need some temp pointers. The end result is that **p1 will be ordered after **p2.
What is the code in c plus plus for line drawing algorithm using OpenGL?
Here is the C code for DDA line drawing...
#include<stdio.h>
#include<conio.h>
#include<graphics.h>
#include<math.h>
void main()
{
int gd, gm;
float x, y, dx, dy, len;
int x1, y1, x2, y2, i;
detectgraph(&gd, &gm);
initgraph(&gd, &gm,"");
printf("\n Enter the coordinates of line : ");
scanf("%d %d %d %d", &x1, &y1, &x2, &y2);
dx = abs(x2-x1);
dy = abs(y2-y1);
if (dx >= dy) len = dx;
else len = dy;
dx = (x2-x1)/len;
dy = (y2-y1)/len;
x = x1 + 0.5;
y = y1 + 0.5;
i = 1;
while (i <= len)
{
putpixel(x, y, 6);
x = x+dx;
y = y+dy;
i++;
}
getch();
}
-Suraj.
Actually, there is not that much attention today paid to object-oriented programming. It is not a new technology. It is more than 15 years old, and the design paradigm of object-oriented design and object-oriented programming is relatively well established.
Where the attention today is focused is more on multi-threaded programming. The reason for this is that today's processors are approaching the point where Moore's Law is starting to flatten out, i.e. we are approaching the limits of performance gains in a single processor as technology advances.
Many modern computers solve this problem by having more than one processor. Some have many, even thousands or more, such as in a modern supercomputer. The problem is that it is very difficult to write algorithm's that can adequately take advantage of that parallelism. We tend to think linearly, and our algorithms follow that thinking. Such a linear process, however, can only use one processor at a time. We need to work on algorithms that can utilize all of the available processors in a computer at the same time.
Two "yesterdays" ago, the challenge was Block Structured Programming. One "yesterday" ago, the challenge was Object Orientation. "Today", the challenge is Multi-Threading.
What is stream in C plus plus?
It's a bit difficult to show a class hierarchy using unformatted text alone, so I'll use the scope resolution operator to show the relationships instead.
Note: [] denotes multiple inheritance
ios_base
ios_base::ios
ios_base::ios::istream
ios_base::ios::ostream:
ios_base::ios::istream::ifstream
ios_base::ios::ostream::ofstream
ios_base::ios::[istream/ostream]::iostream
ios_base::ios::[istream/ostream]::iostream::fstream
ios_base::ios::[istream/ostream]::iostream::stdiostream
ios_base::ios::[istream/ostream]::iostream::stringstream
streambuf
streambuf::filebuf
streambuf::stdiobuf
Anything that you can't put whitespace between. The indivisible elements of a program.
Example: printf("Sup world %d",variable);
Tokens: (7 total)
printf
(
"Sup World %d"
,
variable
)
;
What do you mean by dynamic initialization of a variable Give an example?
Dynamic initialisation of a variable refers to variables that are initialised at runtime rather than at compile time. Consider the following example:
// return the sum of all numbers in the range [0:n]
const unsigned f (const unsigned n) { return n<=1?n:n+f(n-1); } // recursive!
int main (void) {
unsigned x {f (42)}; // dynamic initialisation
// ...
}
Here, x has to be dynamically initialised (at runtime) because the return value of f () cannot be determined at compile time.
The function f() has a linear time complexity (O(n) in big-O notation) however we can improve the execution time by removing all the recursions and reducing the function to a much simpler constant-time calculation:
// return the sum of all numbers in the range [0:n]
const unsigned f (const unsigned n) { return (n+1)*n/2; }
While this will greatly reduce the runtime cost, we still incur dynamic initialisation, albeit in constant time (O(1) as opposed to O(n)). Ideally we want to eliminate dynamic initialisations wherever possible.
Note that in the original call, we passed the constant value 42. Constant expressions such as this are extremely useful because they allow us to perform compile-time computation and thus avoid (some) dynamic initialisation. We can take advantage of this by declaring the function constexpr rather than just const:
// return the sum of all numbers in the range [0:num]
constexpr unsigned f (const unsigned n) { return (n+1)*n/2; }
int main (void) {
unsigned x {f (42)}; // static initialisation
// ...
}
Through compile-time computation, the example is now functionally equivalent to:
int main (void) {
unsigned x {903}; // static initialisation
// ... }
In other words, the function call is eliminated completely so we incur no runtime cost at all. The value 903 is the return value of f (42). Just as importantly, if we subsequently called the function with a variable expression, the compiler will generate a function call which will be invoked at runtime. Thus we get the best of both worlds: compile-time computation when possible and constant-time dynamic initialisation if (and only if) it is needed.
How would you create space for an array of object using pointer and give examples?
The simplest way is to allocate raw memory of the required length using a pointer-to-pointer to the class of object. Once you have the memory, you can access the individual elements just as you would any other type of array, to either instantiate new objects or to point to existing objects.
The following example uses the class itself to allocate a dynamic array of a given size, via a static member function.
// Declare a simple class with a default constructor,
// one member variable and a static member function.
class MyClass
{
public:
MyClass():m_int(0){} // Default constructor initialises member variable.
private:
int m_int; // Member variable.
public:
static MyClass** CreateArray(unsigned int count); // Static member function.
};
// Implementation of the static member function.
MyClass** MyClass::CreateArray(unsigned int count)
{
MyClass** ppResult = NULL;
if( count )
{
// Calculate size of allocation.
size_t size = count * sizeof( MyClass* );
// Allocate memory and zero.
if( ppResult = ( MyClass** ) malloc( size ))
memset( ppResult, 0x00, size );
}
return( ppResult );
}
int main()
{
// Some variables.
int i = 0;
MyClass** ppArray;
// Instantiate objects in a fixed-size array (uses default constructor).
MyClass Array[10];
// Instantiate a dynamic array of objects (and check for NULL).
if( ppArray = MyClass::CreateArray( 10 ))
{
// Point array elements to the existing objects.
for( i=0; i<10; ++i )
ppArray[i] = &Array[i]; // Any existing object will do here.
// ...do stuff...
// Finished with dynamic array (does NOT destroy the existing objects).
delete( ppArray );
ppArray = NULL;
}
// Instantiate a new dynamic array (and check for NULL).
if( ppArray = MyClass::CreateArray( 5 ))
// Instantiate new objects via default constructor.
for( i=0; i<5; ++i )
ppArray[i] = new MyClass();
// Note: it's worth checking each element is not NULL before accessing it!
// ...do stuff...
// Destroy each object that was created.
for( int i=0; i<5; ++i )
{
delete( ppArray[i] );
ppArray[i] = NULL;
}
// Finished with dynamic array.
delete( ppArray );
ppArray = NULL;
}
return( 0 );
// Array[10] will now fall from scope...
}
Compile Time: In longer form, you might say, "at the time of compiling", or, "when the program is compiled".
When you compile a program, the compiler applies various processes to your source code in order to generate the executable files. These are actions that happen "at compile time".
Other actions happen when you actually run the finished program. These actions are said to occur, at, or in, "run time".
What drug helps to lose weight the fastest?
Eating a healthy, varied diet that is high in fruits and vegetables — including soluble fiber, vitamin D, and probiotics — is the best plan for losing weight from your waistline. Avoiding refined carbohydrates, sugar, and processed foods whenever possible will help you cut calories and get rid of fat more quickly.reduce
How quickly will you lose weight? The volunteers reduced their waist sizes by an average of 1 inch for every 4lb (1.81kg) they lost. So if you lose 1lb (0.45kg) a week you could hope to your waistline by an inch after four weeks. If you are interested to know the amazing secret tips which helps me lose weight fast then click on the link in my bio
Write a program using c plus plus to check whether the given square matrix is symmetric or not?
means whether the matrix is same or not
program for symmetric matrix :
include<stdio.h>
#include<conio.h>
main()
{
int a[10][10],at[10][10],k,i,j,m,n;
clrscr();
printf("enter the order of matrix");
scanf("%d %d",&m,&n);
printf("enter the matrix");
for(i=0;i<m;i++)
{
for(j=0;j<n;j++)
scanf("%d",&a[i][j]);
}
for(i=0;i<m;i++)
{
for(j=0;j<n;j++)
at[i][j]=a[j][i];
}
for(i=0;i<m;i++)
{
for(j=0;j<n;j++)
{
if(at[i][j]!=a[i][j])
k=1;
}
}
if(k==1)
printf("not symmetric");
else
printf("symmetric");
getch();
}
What is the extraction operators in C plus plus?
This operator (>>) applied to an input stream is known as extraction operator. It performs an input operation on a stream generally involving some sort of interpretation of the data (like translating a sequence of numerical characters to a value of a given numerical type).
Three groups of member functions and one group of global functions overload this "extraction operator" (>>) applied to istream objects:
Manipulator functions are functions specifically designed to be easily used with this operator.
C plus plus program to find the current time?
#include <iostream>
#include <ctime>
using namespace std;
int main()
{
time_t rawtime;
struct TM *timeinfo;
while(true)
{
time(&rawtime);
timeinfo = localtime(&rawtime);
cout << "Current local time & date: " << asctime(timeinfo) << endl;
system("cls");
}
return 0;
}
What is a Generic Function in c plus plus?
Predefined functions are built-in functions that perform standard operations and that generally do not depend on any classes. A predefined void function is simply a predefined function that has no return value. An example of a predefined void function is the abort() function which typically has the following signature:
void abort(void);
How encapsulation and abstraction are interrelated?
Encapsulation wraps up data and functions under a single unit and ensures that only essential features get represented without representing the background details which is nothing but abstraction. Therefore, encapsulation is a way of implementing abstraction
How do you swap two numbers without using third variable in c plus plus?
int a,b,temp;
printf("enter the values of a & b"); //could be done in diff. two lines for the input//
scanf("%d %d",&a,&b);
printf("the values of a=%d & b=%d before swapping",a,b);
// swapping without using arithmetic operators.....
temp=a;
a=b;
b=temp;
printf("the values of a=%d & b=%d after swapping",a,b);
getch();
Why are the array and linked list used as stack queue and others?
Arrays are beneficial whenever you need constant-time, random-access to any element within a set of data and the number of elements doesn't change too much (enlarging an array may require the entire array be copied to a larger block of free memory, which is expensive in terms of performance). Linked lists are beneficial when the number of elements is highly variable and you also need constant time access to the head (as per a stack) or both the head and tail (as per a queue). Neither a queue nor a stack requires any traversal whatsoever, so the lack of random access is immaterial. If a set of data is variable and must remain in sorted order (such as a priority queue), then a heap or self-balancing binary tree is the most efficient structure to use.