Monday, January 31, 2011

C++ Constructor Concept

/*
 * Devices.cpp
 *
 *  Created on: Jan 27, 2011
 *      Author: Karthikeyan.D
 */

#include "Devices.h"

Devices::Devices() {
    // TODO Auto-generated constructor stub
cout<<"Hello World1"<<endl;

}

Devices::~Devices() {

    // TODO Auto-generated destructor stub
    cout<<"Hello World2"<<endl;
}


int main()
{
    Devices Obj;
    Obj.chair();


return 0;
}
---------------------------------------------------------------------------------------------------------
/*
 * Devices.h
 *
 *  Created on: Jan 27, 2011
 *      Author: Karthikeyan.D
 */

#ifndef DEVICES_H_
#define DEVICES_H_
# include
class Devices {
public:
    //int Chair();
    int chair()
    {
        cout << "This method is used to understand the Object creation in the C++ "<<endl;
        return 0;
    }
    Devices();
    virtual ~Devices();

};

#endif /* DEVICES_H_ */



________________________________________________________________________________

OUTPUT:









Hello World1
This method is used to understand the Object creation in the C++
Hello World2

Saturday, November 13, 2010

How to display the message box through Command Prompt



How to display the message box through Command Prompt

Procedure:

Step 1: Go to “Start” Menu and Click Run option.
Step 2: Enter “cmd” in drop down box.

Step 3: In CMD window, Type as “msg Console [User Content]”.

Ex: msg console Enjoy life with new technology!!!

OUTPUT:
 

Monday, November 1, 2010

How to find the variable size without using Sizeof function

/*
 * sizeofVariable.c
 * Author : karthikeyan.D
 * Date: 1-Nov-2010
 *
 */
/* please refer this following statements.
#ifndef __SIZE_T
#define __SIZE_T
typedef unsigned int size_t;
#endif
.... meaning that on this particular implementation `size_t' is
an `unsigned int'.

*/


# include <stdio.h>
# include <stdlib.h>
//user definition
# define size_var( var ) ((size_t)(&(var)+1)-(size_t)(&(var)))

int main()
{
    int nVal;
    char cChar;
    printf("size of :%d\n",size_var(nVal));
    printf("size of :%d",size_var(cChar));
    return 0;
}

Friday, October 29, 2010

structure inside the another structure

/*
 * Structure inside the another structure.c
 *
 *  Created on: Oct 19, 2010
 *      Author: Karthikeyan.D
 */

# include <malloc.h>
struct employee
{
    int nage;
    int nsex;

};

struct NetSim
{
    int nTest;
    struct employee *pstruEmp;
};

struct NetSim *pstruNetsimDepartment =NULL;


# include <stdio.h>
int main()
{
  //To create  a memory for first structure
    pstruNetsimDepartment = (struct NetSim * )malloc (sizeof(struct NetSim *));

  //To create  a memory for second structure
    pstruNetsimDepartment->pstruEmp = (struct employee * )malloc (sizeof(struct employee *));

    // To assign the employee age as ten

    pstruNetsimDepartment->pstruEmp->nage =10;
// echo this meesge
    printf("%d",pstruNetsimDepartment->pstruEmp->nage);
    return 0;
}

Wednesday, October 20, 2010

netsh command usage

Sample:

INPUT:

netsh interface ip show address "Local Area Connection 2"

OUTPUT:

Tuesday, October 19, 2010

Sample make File

myprogram:
g++ stack.c -o stack.exe
g++ revfile.c -o revfile.exe
clean:
rm -rf *.o *.exe

Friday, October 15, 2010

Memory Reference Problem

/*
* StruMem.c
*
* Created on: Oct 15, 2010
* Author: KArthikeyan.D
*
*/
# include <stdio.h>
# include <malloc.h>
# include <string.h>
typedef struct struture1
{
int a;
int b;

}stru;

int main()
{
stru *Memory = (stru*)malloc(sizeof(stru));
//Memory = NULL;

Memory->a=12;
Memory->b = 21;

free(Memory);
printf("%d ",Memory->b);
return 0;
}

Note: View last two lines. Memory freed . After that we are trying to get the value.

OutPut: Garbage value

Sunday, October 10, 2010

How to print the single linked list in reverse order without using array or memory?

/*
* list1.c
* Display the single linked list in reverse order
* Created on: Oct 11, 2010
* Author: Karthikeyan.D
*/

#include<stdio.h>
#include<conio.h>
#include<malloc.h>
typedef struct struNode
{
int nVal;
struct struNode *pstruNext;
}pstruStart;

int fnReversePrint(pstruStart* nTempLoation);

int fnReversePrint(pstruStart* nTempLoation)
{

if(nTempLoation->pstruNext != NULL)
{
fnReversePrint(nTempLoation->pstruNext);
printf("-->%d",nTempLoation->nVal);
}
else
{
printf("NULL-->%d",nTempLoation->nVal);
}

return 0;

}
int main()
{
struct struNode *pstruStart=NULL;
struct struNode *pstruNewnode,*pstruCurrent;

int nN;
int nI;

printf("enter the number of nodes\n");
scanf("%d",&nN);
for(nI=0;nI<nN;nI++)
{
pstruNewnode=(struct struNode*)malloc(sizeof(struct struNode));
printf("enter the data\n");
scanf("%d",&pstruNewnode->nVal);
pstruNewnode->pstruNext=NULL;
if(pstruStart==NULL)
{
pstruStart=pstruNewnode;
pstruCurrent=pstruNewnode;
}
else
{
pstruCurrent->pstruNext=pstruNewnode;
pstruCurrent=pstruNewnode;
}
}
printf("the linked list is\n");
pstruNewnode=pstruStart;
while(pstruNewnode!=NULL)
{
printf("%d----->",pstruNewnode->nVal);
pstruNewnode=pstruNewnode->pstruNext;
}
printf("NULL\n");


fnReversePrint(pstruStart);

return 0;

}

INPUT:

enter the number of nodes: 5
enter the data: 10
enter the data: 20
enter the data: 30
enter the data: 40
enter the data: 50

OUTPUT:
the linked list is
10----->20----->30----->40----->50----->NULL
NULL-->50-->40-->30-->20-->10

Sunday, October 3, 2010

Counting bits

/*
* To count the number bits used for the value representation.
*/

# include <stdio.h>
# include < stdlibb.h>

int bitcount(unsigned char x)
{ int count;
for (count=0; x != 0; x>>=1)
if ( x & 01) count++;
return count;
}
int main()
{
int BitCount;


BitCount = bitcount(10);

printf("Number of BitCount = %d\n ",BitCount);


return 0;
}

Timer Problem

/* timer.c */
/* Computes the time in seconds to do a computation */
#include <stdio.h>
#include <sys/types.h>
#include <time.h>
main()
{ int i;
time_t t1,t2;
(void) time(&t1);
for (i=1;i<=1000;++i)
printf(``%d %d %dn'',i, i*i, i*i*i);
(void) time(&t2);
printf(``n Time to do 1000 squares and
cubes= %d secondsn'', (int) t2-t1);
}