BidVertiser

Wednesday, October 17, 2012

-: Chat with Friends through MS-DOS Command Prompt :-



1) All you need is your friend's IP Address and your Command Prompt.

2) Open Notepad and write this code as it is.....!
@echo off
:A
Cls
echo MESSENGER
set /p n=User:
set /p m=Message:
net send %n% %m%
Pause
Goto A

3) Now save this as "Messenger.Bat".

4) Open Command Prompt.

5) Drag this file (.bat file) over to Command Prompt and press Enter.


7) Now, type the IP Address of the computer you want to contact and press enter

8) Now all you need to do is type your message and press Enter.
Start Chatting.......!

Tuesday, October 16, 2012

A File-Copy Program in C

#include<stdio.h>
main( )
{
FILE *fs, *ft ;
char ch ;
fs = fopen ( "pr1.c", "r" ) ;
if ( fs == NULL )
{
puts ( "Cannot open source file" ) ;
exit( ) ;

}
ft = fopen ( "pr2.c", "w" ) ;
if ( ft == NULL )
{
puts ( "Cannot open target file" ) ;
fclose ( fs ) ;
exit( ) ;
}
while ( 1 )
{
ch = fgetc ( fs ) ;
if ( ch == EOF )
break ;
else
fputc ( ch, ft ) ;
}
fclose ( fs ) ;
fclose ( ft ) ;
}

Thursday, May 31, 2012

Example of Multiple Inheritance in C++:

#include<iostream.h>
#include<conio.h>
class student
{
int roll_number;
char name[20];
char course[10];
char mobile_number[11];
char semester[5];
int c_plus_plus;
int data_structure;
int comp_architecture;
int discrete_maths;
int dbms;
int sum;
float percentage;
public:
void input_data()
{
cout<<endl<<"Enter Student's Name:";
cin>>name;
cout<<endl<<"Enter Roll No.:";
cin>>roll_number;
cout<<endl<<"Course enrolled in:";
cin>>course;
cout<<endl<<"Semester:";
cin>>semester;
cout<<endl<<"Mobile No.:";
cin>>mobile_number;
}
void output_data()
{
cout<<endl<<endl<<"Student's Name:"<<name;
cout<<endl<<"Roll No.:"<<roll_number;
cout<<endl<<"Course Enrolled in:"<<course;
cout<<endl<<"Semester:"<<semester;
cout<<endl<<"Mobile No.:"<<mobile_number;
}
void marks_obtained()
{
cout<<endl<<endl<<"Enter Marks Obtained in:"<<endl;
cout<<endl<<"C++:";
cin>>c_plus_plus;
cout<<endl<<"Data Structure Using C:";
cin>>data_structure;
cout<<endl<<"Computer Architecture:";
cin>>comp_architecture;
cout<<endl<<"Discrete Maths:";
cin>>discrete_maths;
cout<<endl<<"DBMS:";
cin>>dbms;
}
void percentage_()
{
cout<<endl<<endl<<"Marks Obtained in:";
cout<<endl<<"C++:"<<c_plus_plus;
cout<<endl<<"Data Structure Using C:"<<data_structure;
cout<<endl<<"Computer Architecture:"<<comp_architecture;
cout<<endl<<"Discrete Maths:"<<discrete_maths;
cout<<endl<<"DBMS:"<<dbms<<endl;
sum=c_plus_plus+data_structure+comp_architecture+discrete_maths+dbms;
percentage=sum/10;
cout<<endl<<"Total Marks Obtained in "<<semester<<" Semester="<<sum;
cout<<endl<<"Percentage of Marks="<<percentage;
}
};
class faculty
{
char name[20];
char subject[30];
char mobile_number[11];
public:
void get_data()
{
cout<<endl<<endl<<"Enter Faculty's Name:";
cin>>name;
cout<<endl<<"Subject:";
cin>>subject;
cout<<endl<<"Mobile No.:";
cin>>mobile_number;
}
void put_data()
{
cout<<endl<<endl<<"Name of Faculty:"<<name;
cout<<endl<<"Subject:"<<subject;
cout<<endl<<"Mobile No.:"<<mobile_number;
}
};
class inherit:public student,public faculty
{
public:
void display()
{
cout<<endl<<endl<<"Inherit class is inheriting both student & faculty classes.";
}
};
void main()
{
clrscr();
inherit i;
i.input_data();
i.output_data();
i.marks_obtained();
i.percentage_();
i.get_data();
i.put_data();
i.display();
getch();
}

Thursday, May 3, 2012

FUNCTIONS IN C:

Introduction:

Functions are used to provide modularity to the software. By using functions, you can divide complex tasks into small manageable tasks. The use of functions can also help avoid duplication of work. For example, if you have written the function for calculating the square root, you can use that function in multiple programs.

Program:

#include <stdio.h>
int add (int x, int y)      //A
{
    int z;           //B
    z = x + y;
    return (z);      //C
}
main ()
{
    int i, j, k;
    i = 10;
    j = 20;
    k = add(i, j);        //D
    printf ("The value of k is%d\n", k);   //E
}

Explanation:

  1. This function adds two integers and returns their sum.
  2. When defining the name of the function, its return data type and parameters must also be defined. For example, when you write
    int add (int x, int y)
    
    int is the type of data to be returned, add is the name of the function, and x and y are the parameters of the type int. These are called formal parameters.
  3. The body of a function is just like the body of main. That means you can have variable declarations and executable statements.
  4. A function should contain statements that return values compatible with the function's return type.
  5. The variables within the function are called local variables.
  6. After executing the return statement, no further statements in the function body are executed.
  7. The name of the function can come from the arguments that are compatible with the formal parameters, as indicated in statement D.
  8. The arguments that are used in the call of the function are called actual parameters.
  9. During the call, the value of the actual parameter is copied into the formal parameter and the function body is executed.
  10. After the return statement, control returns to the next statement which is after the call of the function.

Points to Remember:

  1. A function provides modularity and readability to the software.
  2. To define the function, you have to define the function name, the return data type and the formal parameters.
  3. Functions do not require formal parameters.
  4. If the function does not return any value, then you have to set the return data type as void.
  5. A call to a function should be compatible with the function definition.

Pointers in ‘C’ Language:
Introduction:
In C, a pointer is a variable that points to or references a memory location in which data is stored. Each memory cell in the computer has an address that can be used to access that location so a pointer variable points to a memory location we can access and change the contents of this memory location via the pointer.
Pointer declaration:
A pointer is a variable that contains the memory location of another variable. The syntax is as shown below. You start by specifying the type of data stored in the location identified by the pointer. The asterisk tells the compiler that you are creating a pointer variable. Finally you give the name of the variable.
type * variable name
Example:
int *ptr;
float *string;
Address operator:
Once we declare a pointer variable we must point it to something we can do this by assigning to the pointer the address of the variable you want to point as in the following example:
ptr=&num;
This places the address where num is stores into the variable ptr. If num is stored in memory 21260 address then the variable ptr has the value 21260.
/* A program to illustrate pointer declaration*/
main()
{
int *ptr;
int sum;
sum=45;
ptr= ∑
printf (“\n Sum is %d\n”, sum);
printf (“\n The sum pointer is %d”, ptr);
}
we will get the same result by assigning the address of num to a regular(non pointer) variable. The benefit is that we can also refer to the pointer variable as *ptr the asterisk tells to the computer that we are not interested in the value 21260 but in the value stored in that memory location. While the value of pointer is 21260 the value of sum is 45 however we can assign a value to the pointer * ptr as in *ptr=45.
This means place the value 45 in the memory address pointer by the variable ptr. Since the pointer contains the address 21260 the value 45 is placed in that memory location. And since this is the location of the variable num the value also becomes 45. this shows how we can change the value of pointer directly using a pointer and the indirection pointer.
/* Program to display the contents of the variable their address using pointer variable*/
#include< stdio.h >
{
int num, *intptr;
float x, *floptr;
char ch, *cptr;
num=123;
x=12.34;
ch=’a’;
intptr=&x;
cptr=&ch;
floptr=&x;
printf(“Num %d stored at address %u\n”,*intptr, intptr);
printf(“Value %f stored at address %u\n”,*floptr, floptr);
printf(“Character %c stored at address %u\n”,*cptr, cptr);
}
Pointer expressions & pointer arithmetic:
Like other variables pointer variables can be used in expressions. For example if p1 and p2 are properly declared and initialized pointers, then the following statements are valid.
y=*p1**p2;
sum=sum+*p1;
z= 5* - *p2/p1;
*p2= *p2 + 10;
C allows us to add integers to or subtract integers from pointers as well as to subtract one pointer from the other. We can also use short hand operators with the pointers p1+=; sum+=*p2; etc.,
we can also compare pointers by using relational operators the expressions such as
 p1 >p2 , p1==p2 and p1!=p2 are allowed.

/*Program to illustrate the pointer expression and pointer arithmetic*/
#include< stdio.h >
main()
{
int ptr1,ptr2;
int a,b,x,y,z;
a=30;b=6;
ptr1=&a;
ptr2=&b;
x=*ptr1+ *ptr2 –6;
y=6*- *ptr1/ *ptr2 +30;
printf(“\nAddress of a +%u”,ptr1);
printf(“\nAddress of b %u”,ptr2);
printf(“\na=%d, b=%d”,a,b);
printf(“\nx=%d,y=%d”,x,y);
ptr1=ptr1 + 70;
ptr2= ptr2;
printf(“\na=%d, b=%d”,a,b);
}
Pointers and function:
The pointer are very much used in a function declaration. Sometimes only with a pointer a complex function can be easily represented and success. The usage of the pointers in a function definition may be classified into two groups.
1. Call by reference
2. Call by value.
Call by value:
We have seen that a function is invoked there will be a link established between the formal and actual parameters. A temporary storage is created where the value of actual parameters is stored. The formal parameters picks up its value from storage area the mechanism of data transfer between actual and formal parameters allows the actual parameters mechanism of data transfer is referred as call by value. The corresponding formal parameter represents a local variable in the called function. The current value of corresponding actual parameter becomes the initial value of formal parameter. The value of formal parameter may be changed in the body of the actual parameter. The value of formal parameter may be changed in the body of the subprogram by assignment or input statements. This will not change the value of actual parameters.
/* Include< stdio.h >
void main()
{
int x,y;
x=20;
y=30;
printf(“\n Value of a and b before function call =%d %d”,a,b);
fncn(x,y);
printf(“\n Value of a and b after function call =%d %d”,a,b);
}
fncn(p,q)
int p,q;
{
p=p+p;
q=q+q;
}
Call by Reference:
When we pass address to a function the parameters receiving the address should be pointers. The process of calling a function by using pointers to pass the address of the variable is known as call by reference. The function which is called by reference can change the values of the variable used in the call.
/* example of call by reference*/
/* #Include< stdio.h >
void main()
{
int x,y;
x=20;
y=30;
printf(“\n Value of a and b before function call =%d %d”,a,b);
fncn(&x,&y);
printf(“\n Value of a and b after function call =%d %d”,a,b);
}
fncn(p,q)
int p,q;
{
*p=*p+*p;
*q=*q+*q;
}
Reference :
http://www.exforsys.com/tutorials/c-language/c-pointers.html
/*Program in C++ to check if given word is a palindrome or not*/
#include<iostream.h>
#include<conio.h>
#include<string.h>
void main()
{
char str[100],str1[100];
clrscr();
cout<<endl<<"Enter the word:";
cin.get(str,100);
cout<<endl<<"The given string is:"<<str;
strcpy(str1,str);
strrev(str);
if(strcmp(str,str1)==0)
 cout<<endl<<"This word is a palindrome!!!!!";
else
 cout<<endl<<"This word is not a palindrome.";
getch();
}