Sunday, July 05, 2015

How to reset account password in admin mode

Posted By: BackBenchers World - Sunday, July 05, 2015

Wednesday, July 01, 2015

How to change color in command prompt

Posted By: BackBenchers World - Wednesday, July 01, 2015
This is a cool trick that let you alter foreground and background colors in command prompt.

Syntax: COLOR [attr], where attr specifies color attributes of console output.

Color attributes are specified by TWO hex digits -- the first corresponds to the background; the second foreground. Each digit can be any of the following values:

Color corresponding to particular hexadecimal value
Hexadecimal Value Corresponding Color
0 Black
1 Blue
2 Green
3 Aqua
4 Red
5 Purple
6 Yellow
7 White
8 Grey
9 Light Blue
A Light Green
B Light Aqua
C Light Red
D Light Purple
E Light Yellow
F Bright White

CMD Screenshot
In case no argument is given, this command restores the color to what it was when CMD.EXE started. This value either comes from the current console window, the /T command line switch or from the DefaultColor registry value.

Tuesday, June 30, 2015

Working with Sparse Matrix

Posted By: BackBenchers World - Tuesday, June 30, 2015
#include<stdio.h>
#include<conio.h>
# define MAX 50

struct triplet
{
int row;
int col;
int element;
}spmatrix[MAX];

void main()
{
clrscr();
int i, j, k=0, n, row, col;
printf("Array representation of Sparse Matrix\n\n");
printf("Enter Matrix Dimension:\n");
scanf("%d%d",&row,&col);
printf("\nEnter number of non-zero elements in sparse matrix: ");
scanf("%d",&n);

for(i=0;i<n;i++)
{
printf("\nEnter element row, element column and its value\n");
scanf("%d%d%d",&spmatrix[i].row,&spmatrix[i].col,&spmatrix[i].element);
}

printf("\nThe Sparse Matrix is:\n");

for(i=0;i<row;i++)
{
printf("\n");

for(j=0;j<col;j++)
{
if((spmatrix[k].row==(i+1))&&(spmatrix[k].col==(j+1)))
{
printf("\t%d",spmatrix[k].element);
k++;
}

else
{
printf("\t0");
}
}
}
getch();
}

Monday, June 29, 2015

Static Implementation of Stack

Posted By: BackBenchers World - Monday, June 29, 2015
#include<stdio.h>
#include<conio.h>
#include<stdlib.h>
#define MAX 5

int stack[MAX], top;

void display()
{
int i;

printf("The Elements in Stack are:\n");
for(i=0;i<=top;i++)
{
printf("%d\n",stack[i]);
}
}

void push()
{
char no;

if(top==MAX-1) printf("Stack Overflow");

else
{
top=top+1;

printf("Enter a Number: ");
scanf("%d",&no);

stack[top]=no;
display();
}
}

void pop()
{
if(top==-1) printf("Stack Underflow");

else
{
top--;
display();
}
}

void main()
{
clrscr();
char ch=1;
top=-1;
char choice;
printf("Working with Data Structure\n\n");
printf("Menu\n\n1. Push\n2. Pop\n");
printf("0. Exit");

while(ch)
{
printf("\n\nEnter your choice: \n");
choice=getch();

switch(choice)
{
case '1': push();
break;

case '2': pop();
break;

case '0': return;

default: printf("Wrong choice");
}
}
}

Sunday, June 28, 2015

Dynamic Implementation of Stack

Posted By: BackBenchers World - Sunday, June 28, 2015
#include<stdio.h>
#include<conio.h>
#include<alloc.h>

struct node
{
int info;
struct node *link;
}*top;

void create()
{
struct node *ptr, *cpt;
char ch;

ptr=(struct node*)malloc(sizeof(struct node));    //Allocating memory to ptr

printf("Enter the information of first node: ");
scanf("%d",&ptr->info);

ptr->link=NULL;

do
{
cpt=(struct node*)malloc(sizeof(struct node));    //Allocating memory to cpt

printf("\nEnter the information of next node: ");
scanf("%d",&(cpt->info));

cpt->link=ptr;
ptr=cpt;

printf("\nPress <Y> for more nodes\n");
ch=getch();
}
while(ch=='y'||ch=='Y');
top=ptr;
}

void traverse()
{
struct node *ptr;
ptr=top;

if(ptr==NULL) printf("Stack Underflow");

else
{
printf("\nThe Elements in the list are: ");
while(ptr!=NULL)
{
printf("\n%d",ptr->info);
ptr=ptr->link;
}
}
}

pop()
{
struct node *ptr;

if(top==NULL)
{
printf("Stack Underflow");
}

else
{
ptr=top;
top=ptr->link;
free(ptr);
traverse();
}
}

push()
{
struct node *ptr, *cpt;

ptr=(struct node*)malloc(sizeof(struct node));    //Allocating memory to ptr

printf("Enter the information of node: ");
scanf("%d",&ptr->info);

ptr->link=top;
top=ptr;
traverse();
}

void main()
{
clrscr();
char ch=1;
char choice;
printf("Working with Data Strucrure\n\n");
printf("Menu\n\n1. Create\n2. Push\n3. Pop\n4. Traverse\n");
printf("0. Exit");

while(ch)
{
printf("\n\nEnter your choice: \n");
choice=getch();

switch(choice)
{
case '1': create();
break;

case '2': push();
break;

case '3': pop();
break;

case '4': traverse();
break;

case '0': return;

default: printf("Wrong choice");
}
}
}

Monday, June 01, 2015

Potege Z20t Device

Posted By: BackBenchers World - Monday, June 01, 2015
Toshiba has introduced Hybrid Toshiba Potraz Z20t device which runs on Windows 8.1. This Hybrid device has 12.5 inch touch screen. It comes with reversible keyboard power dock. It is powered by Intel Core M Processor. This device has option for RAM up to 8GB. It could be available in market by this month with 128GB, 256GB and 512GB SSD variants. This device owns 9 hours battery life according to company which can be extended to 17 hours with keyboard dock.

Sparse Matrix

Posted By: BackBenchers World - Monday, June 01, 2015
These are special type of matrices in which most of the elements are "0s" (zeros). That is, if a lot of elements  from a matrix have a value 0 then the matrix is known as sparse matrix.

There is no precise definition of when a matrix is sparse and when it is not, but it is a concept, which we all recognize intuitively. If the matrix is a sparse, we must consider an alternative way of representing it rather than the normal row-major or column-major arrangement. This is because a sparse matrix is a matrix containing very few non-zero elements. If the user stores the entire matrix including zero elements then there is a wastage of storage space.

There are two ways of representing a sparse matrix:
  • Arrays representation
  • Linked representation


In array representation of of a sparse matrix, only the non-zero elements are stored so that storage space can be reduced. Each non-zero element in the sparse matrix is represented as (Row, Column, Value).

For this, a two-dimensional array containing 3 columns can be used. The first column is for storing the row number, the second column is for storing the column number and the third column is represents the value of corresponding to non-zero element at (row, column) in the first two columns. For example, consider the following sparse matrix.

Sparse Matrix of 5X6 Order

The above matrix can be represented as

Row
Column
Value
0
3
8
1
2
1
1
5
7
2
1
3
3
2
2
4
5
5

The structure declaration of array is given below:

#define MAX 50

struct triplet
{
int row;
int column;
int element;
}spmatrix[MAX];

The maximum number of non-zero elements in the sparse matrix is defined by constant MAX.

The array representation will use, [2*(n+1)*size of (int) + n*size of (T)] bytes of memory where n is the number of non-zero bytes and T is the data type of elements.

The major limitation of of array representation of a sparse matrix is that we need to know the number of non-zero elements in the matrix.

In the linked list representation, a separate list is maintained for each column as well as each row of the matrix, i.e., if the matrix is of size 4 X 4, then there would be 4 lists for 4 columns and 4 lists for 4 rows.

The head node for the column list stores the column number, a pointer to the node which comes first in the column and a pointer to the next column head node.

The head node for the row list stores, a pointer to the node, which comes first in the row list, and a pointer to the next row head node.

A node on the other hand stores the row number, column number and the value of the non-zero element of the sparse matrix. It also stores a pointer to the node that is immediatly to the right of the node in the row list as well as a pointer to the node that is immediatly below the node in the column list.

For example: A sparse matrix (5 X 6), the figure is given above:

The linked list representation of the above matrix is:

Linked List Representation of Sparse Matrix


Friday, March 27, 2015

Turn Wi-Fi Speed into Hi-Fi

Posted By: BackBenchers World - Friday, March 27, 2015
Have the slow Wi-Fi speed troubled you? You want high speed, but you are not getting any solution for this? Now it's time to get rid of this problem. Here are discussed some tips for the same.










Setup the router in centre

For fast speed it's very necessary to setup router at proper place. You should install router at centre or nearby to centre of your home so that signal could reach at each any every corner properly. If there are various floors in your home or office, then it would be better to install router at top floor. Electronic devices produce interference in Wi-Fi signal, so always keep in mind that devices like microwave, TV, refrigerator, cordless phones, halogen lamps etc. are to be kept at least 10 feet away from router.

Boost your Wi-Fi with booster antenna
Generally router has one or two antenna(s), but due to this signal doesn't reach to each any every corner. So, in this situation, it would be apt to install booster antenna for strengthening the signal. It will widen Wi-Fi range and increase speed also.

Not to share Wi-Fi network name (SSID)
Do not share your Wi-Fi Network Name with any of neighbrour or anybody else. For hiding Wi-Fi network name, turn off Service Set Identifier under Broadcasting Option. It would be better if you add password to your Wi-Fi Network Name.

Remove Interference
Interference of one Wi-Fi signal with another Wi-Fi signal causes weakening of signal. To get rid of this problem, Wi-Fi Stumbler or Wi-Fi Analyzer could be used. This will prevent interference of other's Wi-Fi signal with your Wi-Fi signal and in turns it will result in increased Wi-Fi speed along with strengthening the signal.

Latest technology always rocks

The best option for high speed Wi-Fi is to use latest technology. Means always use up-to-date hardware. Wireless 'a', 'b' and 'g' has become old and it works slowly. Wireless 'n' is the latest version and it gives very fast speed. Using wireless n card with your laptop or PC along with wireless n router will give you best possible results in terms of speed.

Sunday, March 15, 2015

K7’s New Security Solution

Posted By: BackBenchers World - Sunday, March 15, 2015
K7 computing has introduced K7 Total Security Pro and K7 Internet Security Technology. In this advanced technology has been used for protection. It works for keeping your virtual assets safe. K7 Secure Transact feature provides security during online transition. Whereas, K7 Serebro is a new scan engine which guarantees 100% security against malware.

Evernote Scannable App

Posted By: BackBenchers World - Sunday, March 15, 2015
Evernote, the popular app for note making, has lunched scannabe app for iPhone and iPad devices. With the help of this app you can not only be able to scan business cards but can also easily scan other documents also. Post scanning documents you can clean, copy etc. the documents. User can save the scanned documents to evernote account, iCloud etc. or can share them via email or message.

                             

LG G Flex2

Posted By: BackBenchers World - Sunday, March 15, 2015

LG has launched its new smartphone G Flex2 with 5.5 inch curved P-OLED capacitive touchscreen. Flex2 is powered by 64-bit Octa-core Qualcomm Snapdragon 810 processor. In this, 2GB RAM and 16 GB internal storage is given. Along with this MicroSD card support is also given with which MicroSD card up to 128GB can be used. Further it has 13MP rear and 2.1MP front camera and 3000mAh battery. It runs on Google's latest O.S., Android 5.0 Lolipop. 

Image source: http://www.androidcentral.com

Tuesday, January 20, 2015

Exception Handling

Posted By: BackBenchers World - Tuesday, January 20, 2015
An Exception is a condition that is caused by a run-time error in the program. There are two types of bugs which are: Logical Errors and Syntax errors
  •  Logical errors occur due to poor understanding of problem and the solution procedure.
  • Syntax errors occur due to poor understanding of the language itself.


The purpose of exception handling is to provide a means to detect and report "Exception Circumstances" so that appropriate action can be taken.

The mechanism incorporates a separate error handling code that performs the following tasks:
  1. Finding the problem (Hit the exception)
  2. Inform that an error has occurred (Throw the exception)
  3. Receive the error information (Catch the exception)
  4. Take corrective actions (Handle the exception)


Basically there are of two types exceptions

  • Synchronous Exceptions are the errors such as "Out-of-range index", "Overflow".
  • Asynchronous Exceptions are errors that are caused by events beyond the control of the program.

 The Error handling Code consists of two segments:
  • One to detect errors and throw the eception
  • Other to catch the exception and take appropriate actions


Syntax for error handling Code:

Try Block
Detects and throws an exception

  Exception Object

Catch Block
Catches and handles an exception


Exception handling is build upon three keywords
  • try
  • throw
  • catch
Try: It is used to preface a block of statements that causes an error condition and "throws" an exception.

Throw: When an exception is detected, it is thrown using throw statement in the try block.

Catch: Catch block is defined by the keyword catch. It catches the exception thrown by the try block and handles it appropriately.

E.g.:
-------------
-------------
try
{
                statements;       //generates an exception
}

catch(exception_type arg)
{
                statements;       //processes an exception
}
The try block can have one or more statements that could generate an exception.

The catch block can have one or more statments that are necessary to process the exception.

If the try block throws an exception and it matches with the exception type in the catch statement, then catch block is executed for handling the exception.

If they do not match, the program is aborted with the help of abort() function which is invoked by default.

When no exception is detected and thrown, the control goes to the statement immediately after the catch block i.e., the catch block is skipped.

E.g.: Try Block throwing an exception
int main()
{
                int a, b;
                cout<<"Enter the values of a and b\n";
               
                cin>>a>>b;

                int x=a-b;

                try
                {
                                if(x!=0)
                                {
                                                cout<<"Result (a/x) = "<<a/x;
                                }

                                else                                                        //There is an exception
                                {
                                                throw(x);                             //Throws int object
                                }

                                catch(int i)
                                {
                                                cout<<"Exception Caught : x = "<<x;
                                }
                }
                cout<<"\nEnd";
                return0;
}

Output

First Run                                                                                                       Second Run
Enter the values of a and b
20
20
Exception Caught : x = 0
End


Enter the values of a and b
20
15
Result (a/x) = 4
End
This program detects and catches a division-by-zero problem. The output of first run shows a successful execution. When no exception is thrown, the catch block is skipped and execution resumes with the first line after the catch. But in the seond run, the denominator x becomes zero and therefore, division by zero situation occurs. This exception is thrown by using object x.


Functions Invoking Exceptions
Exceptions are thrown by functions that are invoked from within the try block. The point which at which throw is executed is called the Throw Point. Once an exception is thrown to the catch block, control can not return to the throw point.


Throwing Mechanism 
When an exception that is desired to be handled is detected, it is thrown using the throw statement in on of the following form:

throw(exception);
OR
throw exception;
OR
throw; //used for re-throwing an exception

When an exception is thrown, it will be caught by the catch statement associated with the try block. That is the control exits the current try block and is transferred to the catch block after that try block.


Catch Mechanism 
The code for handling exceptions is included in catch blocks

Syntax:
catch(type arg)
{
                //statements for managing exceptions
}

Here type indicates the type of exception that this catch block handles. The perameter arg is an optional parameter name.

The catch statement catches an exception whose type matches with the type of catch argument. When it is caught, the code in the catch block is executed.


Multiple Catch Statments
 When a program has more than one condition to throw an exception, multiple catch statements with a try block is used.

Syntax:
E.g.:
try
                {
                                //try block
                }

                catch(type 1 arg)
                {
                                //catch block 1
                }

                catch(type 2 arg)
                {
                                //catch block 2
                }
                ----------------------
                ----------------------          
                catch(type N arg)
                {
                                //catch block N
                }
void test(int x)
{
                try
                {
                            if(x==1) throw x;              //int
                            if(x==0) throw 'x'             //char
                            if(x==-1) throw x              //double
               
                cout<<"\nEnd of try block";
                }

                catch(char c)                      //catch 1
                {
                            cout<<"\nCought a character\n\n";
                }

                catch(int m)                        //catch 2
                {
                            cout<<"\nCought a integer\n\n";
                }

                catch(double d)                  //catch 3
                {
                            cout<<"\nCought a double\n\n";
                }

                cout<<"\nEnd of try-catch system";
}

int main()
{
                cout<<"Testing multiple catches\n\n";

                cout<<"x==1";
                test(1);
               
                cout<<"x==0";
                test(0);

                cout<<"x==-1";
                test(-1);

                cout<<"x==2";
                test(2);

                return 0;
}

When an exception is thrown, the exception handlers are searched in an order for an appropriate match. After executing with the match handler, the control goes to the first statement after last catch block for that try.

Output
Testing multiple catches

x==1
Cought a character

x==0
Cought a integer

x==-1
Cought a double

x==2
End of try block
End of try-catch system

When try block does not throw any exception and it completes normal execution, control passes to the first statement after the last catch handler.


Catching All Exceptions
It is not possible to determine all possible type of exceptions and therefore no independent catch handler can be designed to catch them.

Syntax:
E.g.: Catch All Exceptions
catch(....)
{
       //statements for processing all exception
}


void test(int x)
                {
                                try
                                {
                                  if(x==1) throw x;              //int
                                  if(x==0) throw 'x';            //char
                                  if(x==-1) throw x;            //double
                                }

                                catch(....)                        //Catch all
                                {
                                  cout<<"Caught an Exception\n";
                                }
                }

                int main()
                {
                                cout<<"Testing Generic Catch\n;
                               
                                test(-1);
                                test(0);
                                test(1);

                                return 0;
                }

Output
Here all throws are caught by the catch(....) statement
Testing Generic Catch
Caught an Exception
Caught an Exception
Caught an Exception

Re-throwing an Exception
When the catch block throws an exception, it is termed as re-throwing an Exception. In such a case, throw is invoked without any argument.

Syntax:                                                   throw;

This causes the current exception to be thrown to the next enclosing try-catch sequence and is caught by the catch statement listed after that enclosing try block.

A catch handler itself may detect and throw an exception. The exception thrown will not be caught by any catch statement of that group. It will be passed to the next outer try-catch sequence for processing.

E.g.:
void divide(double x, double y)
                {
                                cout<<"Inside function";

                                try
                                {
                                                if(y==0.0) throw y;

                                                else cout<<"\nDivision = "<<x/y;
                                }

                                catch(double)
                                {
                                                cout<<"\nCaught double inside function";
                                                throw;
                                }
                                               
                cout<<"\nEnd of function\n\n";
                }

                int mian()
                {
                                cout<<"Inside main\n";

                                try
                                {
                                                divide(10.5, 2.0);
                                                divide(20.0,0.0);
                                }

                                catch(double)
                                {
                                                cout<<"\nCaught double inside main";
                                }
               
                cout<<"\nEnd of main;
                return 0;
                }

Output
Inside main
Inside function
Division = 5.25
End of function

Inside function
Caught double inside function
Caught double inside main
End of main

Specifying Exceptions
It is done to restrict a function to throw only certain specified exception. This is achieved by adding a throw list clause to the function definition.

General form of using Exception Specification:
type function(arg-list) throw (type-list)
{
                --------------
                -------------- function body
                --------------
}

Here type-list specifies the type of exceptions that may be thrown. Throwing any other type of exception will cause abnormal program termination.

To prevent function from throwing any exception the type-list is kept empty. E.g.: throw();.

E.g.:
Output
void test( int x) throw( int, double)
                {
                 if(x==1)              throw x;                //int
                 else if(x==-1)     throw 1.0             //double
               
                cout<<"\nEnd of function block";
                }

int main()
{
                try
                {
                             cout<<"Testing throw restrictions\n\n";

                                cout<<"x==1";
                                test(1);

                                cout<<"x==-1";
                                test(-1);

                                cout<<"x==2";
                                test(2);
                }

                catch(int m)
                {
                                cout<<"\nCaught an integer\n\n";
                }

                catch(double d)
                {
                                cout<<"\nCaught an double\n\n";
                }             
Testing throw restrictions

x==1
Caught an integer

x==-1
Caught an double

x==2
End of function block

Copyright © 2013 TechDotHunter™ is a registered trademark.

Designed by Templateism. Hosted on Blogger Platform.