Compare java arithmetic and logic operators with c arithmetic and logical operators?
They are very similar,but when we do logic operators there are still some differences.In c or c plus plus ,logic true can be expressed as'true' or '0',but in java,true is just 'true'.If you gave a zero,it will treat it as type of integer ,and so as false.
How can i add the Dhcpsapi library in code blocks IDE?
Link your project to the dhcpsapi.lib library file and include the dhcpsapi.h header file in all translation units that make use of the library.
What difference between two nodes in c plus plus of single link list?
Their address. They may also have different values, and their sequence may matter, depending on the design of the algorithm.
There are mainly 3 types of variables in c. Integer, Float and character :)
How do you simulate mouse clicks in c plus plus?
The easy way is to simply invoke the relevant message handlers. If you wish to simulate mouse clicks within another application, however, post the relevant messages to the operating system's message queue. The OS will pass them to the appropriate application.
An algorithm is a specific set of instructions for carrying out a procedure or solving a problem, usually with the requirement that the procedure terminate at some point. Specific algorithms sometimes also go by the name method, procedure, or technique.
Nothing. In TurboC, though, it means: Compile, Link and Execute the current program.
Rather than use 'r', 'g', 'b' and 'w' (characters) to represent colours, it would be better to use an enum instead. You can always provide a getter to return a char if that is required.
enum car_colour{ red, green, blue, white, silver };
The following class provides the bare-bones of your car class. Note that the default constructor sets the coordinates at 0,0 and then calls the x and y mutators to set the actual coordinates. Note also that all mutators return false to indicate that no mutation has occurred (whenever the argument is the same as the current attribute value). This is more important with regards to the x and y mutators since the arguments must also be checked to ensure they are in range (0 to 19 for a 20x20 grid) before any mutation can occur. If any mutator returns true, this indicates a mutation has occurred. Other than that the class is fairly straightforward.
class car
{
public: // construction, destruction and assignment car(const car_colour colour=red, const bool ignition=false,const unsigned int x=0, const unsigned int y=0);car(const car& rhs):
m_colour(rhs.m_colour),
m_ignition(rhs.m_ignition),
m_x(rhs.m_x), m_y(rhs.m_y) {} ~car() {}car& operator=(const car& rhs);
public: // mutators (setters) bool set_colour(const car_colour colour);bool set_ignition(const bool ignition);bool set_x(const unsigned int x);bool set_y(const unsigned int y);
public: // accessors (getters)
car_colour get_colour(){ return(m_colour); }
bool get_ignition() const { return(m_ignition); }
unsigned int get_x() const { return(m_x); }
unsigned int get_y() const { return(m_y); }
char get_colour_as_char() const;
private: // attributes
car_colour m_colour;
bool m_ignition;
unsigned int m_x;
unsigned int m_y;
};
// default constructor
car::car(const car_colour colour=red, const bool ignition=false,
const unsigned int x=0, const unsigned int y=0):
m_colour(colour),
m_ignition(ignition),
m_x(0), m_y(0)
{
set_x(x);
set_y(y);
}
// assignment operator overload
car& car::operator=(const car& rhs)
{
m_colour=rhs.m_colour;
m_ignition=rhs.m_ignition;
m_x=rhs.m_x;
m_y=rhs.m_y;
}
// set the colour
bool car::set_colour(const car_colour colour)
{
if (m_colour!=colour)
{
m_colour=colour;
return(true);
}
return(false);
}
// set the ignition
bool car::set_ignition(const bool ignition)
{
if (m_ignition!=ignition)
{ m_ignition=ignition;return(true);
}
return(false);
}
// set the x coordinate
bool car::set_x(const unsigned int x)
{
if (x<20 && m_x!=x)
{
m_x=x;
return(true);
}
return(false);
}
// set y coordinate
bool car::set_y(const unsigned int y)
{ if (y<20 && m_y!=y)
{ m_y=y;
return(true); }
return(false);
}
// return the colour as a char
char car::get_colour_as_char() const
{
switch(m_colour)
{
case( green): return('g');
case( blue ): return('b');
case( white ): return('w');
case( silver ): return('s');
}
return('r'); // default colour.
}
How do you program an adc of pic in c plus plus?
Consult the device programmer's manual. Typically you will need an Application Programming Interface (API) suitable for the device in question. The appropriate API should be freely available from the device manufacturer.
In C plus plus What function is called to initialize a class?
Class initialisation is normally handled by the class constructor(s). Every constructor has an optional initialisation section between the declaration and the body of the constructor. This is generally used to call specific base class constructors, but can be used to initialise any member variables via their own constructors. Member variables may alternatively be initialised in the body of the constructor, but this is really only necessary when member pointers need to be allocated new memory. For those classes that have many members and many constructors, the initialisation may be handled by a private member method called by each constructor in order to simplify maintenance during development. However, when the class is finalised, the private member method will generally be replaced with formal initialisation sections in each constructor.
Program to convert binary to decimal without using array?
Suppose your binary number is stored in a series of bits in the unsigned long type named bits.
Then the fragment of a C program to convert this number to a decimal value would be ..
double decimal_value = 0.0;
for ( unsigned long i = 0; i < sizeof(unsigned long); ++i)
{
decimal_value += pow(2,i) * ( bits & 1 );
bits >> 1; // shift all the bits to the right one spot.
} // end for i
Doing this work is generally unnecessary as functions such as these are built in to most programing languages.
Another method for this: double decimal_value= bits;
Can identifier be any sequence of digits and letters?
If you mean a variable name, then no -- it must begin with a letter or an underscore, but any combination of letters, digits and underscores may follow.
If you mean a variable that stores an identifier, then yes -- so long as the identifier is a string type.
What is the code for c and c plus plus program to merge two circular linked list?
Circular linked lists are really no different to ordinary linked lists, other than that the tail node points back to the head node (and vice versa if the list is doubly-linked). Therefore the merge process is exactly the same: iterate through the second list and insert each node's data into the first list. Since lists are un-associated containers, it doesn't matter where the insertions occur but, by convention, insertions typically occur at the tail of the list. If an order must be maintain, an insertion sort should be employed instead. Note that if you need to maintain the original two lists (in their un-merged state), simply copy the first and insert the second into the copy instead.
What is the c plus plus programme for merge sort without recursion?
The following template function will sort an array of any type using the merge sort algorithm, non-recursively. Note that you must call the function by passing a pointer to the array, rather than passing the array by reference as you normally would with sorting algorithms. This is because the function uses a second array (a work array) of the same size to perform the actual merge, switching from one to the other upon each iteration, so there's no guarantee the final sorted array will be the one you originally referred to (it could be the work array). You could maintain a count of the iterations and perform an extra copy of the work array back to your referenced array if the count is odd, but it's more efficient to simply return the sorted array through a pointer.
The code can be difficult to follow if you're not familiar with the merge sort algorithm, so I've commented the code verbosely to explain what's going on. In essence, we're treating the original array as being several subsets of 1 element each. A subset of 1 is already sorted, so we simply merge these subsets in pairs, so the new array contains sorted subsets of 2 elements each. We repeat the process, merging each pair of subsets to create sorted subsets of 4, then 8 and so on, until there is only 1 sorted subset in the array. When we merge two subsets into one, we simply compare the first element of each subset and place the lowest into the merged subset.
Note that in the final iteration, the second subset of the pair may be smaller than the first, or it may not exist at all (in which case the remaining subset may be smaller). However, the merge algorithm caters for this eventuality quite efficiently. If there's only one subset remaining (which can happen during any iteration as elements are removed from the subsets and merged into the work array), the remaining elements are simply copied sequentially from that subset since they will already be in order (as determined by the previous iteration).
template<typename T>
void merge_sort(T* A[], size_t size)
{
// Arrays of length 0 or 1 are already sorted.
if( size < 2 )
return;
// Instantiate a new array of the same size as A.
T *B = new T[size];
// Array A initially contains subsets of width 1 element, then 2, 4, 8...
for( size_t width=1; width<size; width<<=1 )
{
// Dereference A (now known as C).
T *C = *A;
// Array B initially holds subsets of width 2 elements, then 4, 8, 16...
size_t width2 = 2*width;
// Iterate through each pair of subsets in C...
// sub1 is the start index of the first subset of the pair in C.
for( size_t sub1=0; sub1<size; sub1+=width2 )
{
// sub2 is the start index of the second subset of the pair in C.
size_t sub2 = min( sub1+width, size );
// next is the start of the next pair of subsets in C.
size_t next = min( sub1+width2, size );
// Start with the first elements in each pair of subsets in C
// (the ones with the lowest values in each subset).
size_t c1 = sub1;
size_t c2 = sub2;
// Iterate through B's elements from index [sub1] to index [next-1].
for( size_t b=sub1; b<next; ++b )
// Copy the lowest of the two indexed values in C to B.
B[b] = ( c1<sub2 && ( c2>=next C[c1]<=C[c2] )) ? C[c1++] : C[c2++];
}
// Swap the roles of *A and B (note that C still points to the dereferenced A at this point).
*A=B; B=C;
}
// Finished with B (*A is now the fully-sorted array).
delete[]B;
}
How do you change the Borland C plus plus application icon?
Change the icon in the application's resource file, then recompile.
How much are the size of memories of in built data types of C plus plus?
sizeof (typename) will tell you.
Here are some possible variations:
WinDos 16/small:
1: char
2: short, int, pointer
4: long
WinDos 16/large:
1: char
2: short, int
4: long, pointer
Windows 32, unix 32:
1: char
2: short
4: int, long, pointer
8: long long
Windows 64:
1: char
2: short
4: int, long
8: long long, pointer
Unix 64:
1: char
2: short
4: int
8: long, long long, pointer
What term using c plus plus instead of fscanf in c?
There is no alternative to fscanf() in C++. The same function can be used in both C and C++. For C++, the function can be found in the <cstdio> standard library header.
Note that Microsoft Visual Studio will claim that fscanf() is unsafe and recommends using the non-portable fscanf_s() instead. However, you can disable this warning by placing the following pragma on the line immediately before the call to fscanf().
#pragma warning(suppress:4996);
Write a program to declare 10 variables randomly and fill the array evenly using c plus plus?
#include<iostream>
#include<chrono>
#include<random>
#include<vector>
int main()
{
std::vector<int> Array;
unsigned seed = std::chrono::system_clock::now().time_since_epoch().count();
std::default_random_engine generator (seed);
std::uniform_real_distribution<int> distribution (0,100);
for (size_t index=0; index<10; ++index)
Array.push_back (distribution (generator));
}
The simplest solution is to use a std::set<size_t> sequence container to store the values as they are input. Duplicate entries are ignored automatically, thus when all 5 numbers have been input, the set will have at least 1 number but no more than 5. Thus the size of the set represents the count of distinct values that were input.
The four main pillars of all OOP languages are encapsulation, inheritance, polymorphism and abstraction.
Explain the Difference between bitwise operator ' and ' and address operator ' and ' of pointer?
The bitwise logical operator and (&) calculates the bitwise logical and of two integral values. It is a binary operator.
The address of (&) operator returns the address of the value to its right. It is a unary operator.
The distinction between the two is one of context. The logical and operator will follow (and be preceeded by) a value, while the address of operator will follow an operator.
Program to find biggest number among two numbers using template function?
template<class T>
T& max(const T& x, const T&y){return(x>y?x:y); }