Monday 13 June 2011

Difference between signed integers and unsigned integers


A signed integer is one with either a plus or minus sign 
in front. That is it can be either positive or negative.
An unsigned integer is assumed to be positive.

This is important in computing because the numbers are
stored (usually) as a fixed number of binary digits. For
a signed integer one bit is used to indicate the sign
- 1 for negative, zero for positive. Thus a 16 bit signed
integer only has 15 bits for data whereas a 16 bit unsigned
integer has all 16 bits available. This means unsigned
integers can have a value twice as high as signed integers
(but only positive values).

Operator Overloading

If we can use operators like +,/,*,- for common data types like int ,float ,etc ,then why can't we use them for the data types defined by the users ???
That is the main concept behind operator overloading.We can redefine the way in which c++ works .

Shell Sort with 7 Elements



#include "shellsort.h"


using namespace std;


int main(void)
{
int array[7]; // An array of integers.
int length = 7; // Length of the array.
int i, d;
int tmp, flag;


//Some input
for (i = 0; i < length; i++)
{
cout << "Enter a number: ";
cin >> array[i];
}


//Algorithm
d = length;


flag = 1;


while ( flag || (d > 1))  /*1 OR d>1 */
{
flag = 0;


d = (d + 1)/2;


for (i =0; i < (length - d); i++) {   /*i=0; i < 7 - 3=4; i++*/

if (array[i + d] > array[i]) {


tmp = array[i+d];


array[i + d] = array[i];


array[i] = tmp;


flag = 0;
}
}
}


cout<<"\nAfter Sorting.....\n";


//Some output
for (i = 0; i < 7; i++)
{
cout << array[i] << endl;
}


getch();
}