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.
How does a class in c plus plus enforce data encapsulation?
Data encapsulation is enforced by restricting access to the class members. Access can be specified on a per-member basis, defaulting to private access for a class and public access for a struct. Private members are accessible to class members and to friends of the class. Protected members are the same as private members but are also accessible to derived class members. Public members are fully-accessible. Data members are typically declared private while interfaces are typically declared public or protected.
How do you open a project in Microsoft visual studio 2008?
Making sure that it is a 2008 project or earlier you go to open project then find the file on your computer. Double click it an d it will open (if it is older then 2008 it will ask for you to convert it first)
How do you find the greatest of two numbers without using the if-else comparison operators?
By subtracting any two of the numbers A-B , if the output number is negative , B IS GREAT and if its positive A is great
What features make C plus plus so powerful?
When C++ was initially developed in 1978, it was unique in that there was no other language that incorporated object-oriented programming that could produce efficient machine code. Object-oriented programming languages did exist, of course, but the code they produced was often interpreted and therefore far too slow for anything but the most trivial of tasks. C++, like all object-oriented programming languages, is capable of solving highly-complex problems in a highly efficient manner, breaking larger problems down into smaller, simpler problems. But while newer languages such as Java and C# are just as capable as C++ and very much easier to program, they simply cannot match C++ in terms of performance. That remains unique to C++ today as it did when it was first released in 1985, and is the reason all major applications, including C++ compilers themselves, are still largely or wholly written in C++. The very first C++ compiler was written in C, of course.
Why is multiple inheritance implemened through interfaces?
Interfaces have only methods declared and not defined. So that these various methods can be altered or customized or written according to the need. Hence Multiple inheritance is implemented through Interfaces.
Interface is a progam which just declares various methods or functions, so that any user can write the contents of that method declaration.
AnswerTrue Multiple Inheritance refers to the ability to inherit from multiple CLASSES. Thus, a true multiple inheritance language does not use interfaces. However, many single-inheritance languages provide most of the benefits of the multiple inheritance concept by using interfaces (Java, for example).The problem with true Multiple Inheritance is twofold:
(a) at the compiler and runtime level, it is often difficult to determine which method is being referred to, as M.I. can lead to very convoluted (and sometimes conflicting) namespaces
(b) there is no specific superclass, which can lead to problems with determining relationships between classes
Using a S.I. model with interfaces avoids these two problems.
Why isn't main a keyword in c?
Neither is printf, stderr or NULL. Certainly, they are important words, but not keywords.
Why you write c plus plus not plus plus c?
C++ uses the postfix increment operator whereas ++C uses the prefix increment operator. Both do exactly the same thing; they increment C (the same as C=C+1 increments C). The difference is only in the return value. ++C returns a reference to C, whereas C++ returns the original value of C.
What type of integers are supported by C plus plus?
All the standard arithmetic operations are supported in C++. The most common operations, such as plus, minus, multiply and divide are built-in for all the numeric primitives, as well as C++ specific operators like post-increment and pre-increment (++). More complex mathematical and trigonometric operations are provided by functions declared in math.h. Your IDE may include other libraries, or you can download public-domain libraries, or simply write your own.
Importance of programming in system development?
When business organization facing a keen (鋒利的) competition in the market, rapid change of technology and fast internal demand, system development is necessary. In the system development, a business organization could adopt the systematic method for such development. Most popular system development method is system development life cycle (SDLC) which supports the business priorities of the organization, solves the identified problem, and fits within the existing organizational structure. When business organization facing a keen (鋒利的) competition in the market, rapid change of technology and fast internal demand, system development is necessary. In the system development, a business organization could adopt the systematic method for such development. Most popular system development method is system development life cycle (SDLC) which supports the business priorities of the organization, solves the identified problem, and fits within the existing organizational structure.