Sunday, July 31, 2011

java code for character count framing........

import java.io.*;
import java.util.*;
class Charcount
{
    public static void main(String args[])
    {
        Scanner k=new Scanner(System.in);
        System.out.print("enter a string\t");
        String str=k.next();
        Character c = new Character(str.charAt(0));
   String s = c.toString();
  int p = Integer.parseInt(s);
    int i;
        int m=str.length();
        for(i=0;(p+i)<=m;)
        {
            if(p==((str.substring(i,p+i).length())))
            {
               
                Character c1 = new Character(str.charAt(p));
                 String s1 = c1.toString();
                i+=p;
                p=Integer.parseInt(s1);
            }
        }
        if(i==m)
        {
            System.out.println("the bits are received correctly");
        }
        else
        {
            System.out.println("not received correctly");
        }
    }

}
           

Monday, July 25, 2011

guyys.....just try it out :)

1. Which operator has the least priority?
a) Semicolon
b) Assignment
c) Comma
d) Conditional
2. What is the value of j in the following expression?
i=1;
j=i<<1%2;
a) –2
b) 2
c) 10
d) 0
3. What is the value of ‘ i ‘ in the following expression?
i=1;
i=(i<<=1%2)
a) 2
b) 1
c) syntax error
d) 0
4. From the following code
char a,b;
scanf(“%c %s”,&a,&b);
What are the values assigned to a and b, if x and y are given as inputs?
a) a=x and b=blank
b) a=x and b is not assigned
c) a=x and b=y
d) a=x and b=x
5. From the following code:
int i=20;
printf(“%x”,i);
What will be the output of the above printf statement?
a) x14
b) 14
c) 20
d) none of the above
6.
main()
{
int i=0;
for(; ++i;)
printf(“%d”,i);
}
How many times the for loop is executed
a) 0
b) 32767
c) infinite
d) The maximum unsigned integer value
7. The minimum number of inputs and outputs for a program are
a) 0,0
b) 0,1
c) 1,0
d) 1,1
8. The purpose of main () function in a C program is to
a) Initialize all variables
b) Accommodate all input/output statements
c) Initialize necessary variable and open/close files
d) Initialize necessary variables, open/close files and maintain the overall control structures
9. Which of the following are the valid character constants?
a) ‘\n’
b) ‘\\’
c) ‘\0\’
d) All the above
10. What would be the value of x after executing the following program segment?
int x,y=10; char t=’b’;
x=y+t;
a) 108
b) 10
c) 12
d) Error
11. Given a=5, b=6
What is the value of c, if C=a++ + ++b;
a) 11
b) 12
c) 10
d) 13
12. What is the output of the following statements ?
int n=64;
printf(“%04d”,n);
a) 64
b) 6400
c) 0064
d) none of the above
13. What will be the values of a, b and c printed out to the display from the following statements ?
scanf(“%2d %*d %d”,&a,&b,&c);
printf(“a=%d,b=%d,c=%d”,a,b,c);
when the values entered are 1004, 25, 64.
a) a=10, b=25, c= garbage value
b) a=10, b=4, c=25
c) a=1004, b=25, c=64
d) a=1004, b=64, c=garbage value
14. What is the output of the following program ?
int a=5;
printf(“%d, %d, %d”,a++,a,++a);
a) 5,6,7
b) 5,5,5
c) 6,6,6
d) 7,6,6
15. What would be the output of the following program?
main()
{
int i=32,j=0x20,k,l,m;
k=i j;
l=i & j;
m=k^l;
printf(“%d %d %d %d %d”,i,j,k,l,m);
}
a) 32 32 32 32 0
b) 0 0 0 0 0
c) 0 32 32 32 32
d) 32 32 32 32 32

Friday, July 22, 2011

program code for character stuffing and destuffing in java

import java.io.*;
import java.util.*;
import  java.lang.*;
class Charstuff
{   
    public static void main(String args[])
    {
        Scanner k =new Scanner (System.in);
        System.out.println("enter the string\t");
        String s=k.nextLine();
         String str1;
         String str2="";
        int i,m,j;
        m=s.length();  
        System.out.println("original data     "+s);
       str1="dlestx";
       for(i=0;i<=m-1;i++)
       {
         if((s.charAt(i)=='d')&&(s.charAt(i+1)=='l')&&(s.charAt(i+2)=='e'))
        {
        str1=str1+"dle";
        }
        str1=str1+s.substring(i,i+1);
    }
    str1=str1+"dleetx";
    int p=str1.length();
    System.out.println("transmitted data      "+str1);
    for(i=6;i<p-6;i++)
    {
        if((str1.charAt(i)=='d')&&(str1.charAt(i+1)=='l')&&(str1.charAt(i+2)=='e')&&(str1.charAt(i+3)=='d')&&(str1.charAt(i+4)=='l')&&(str1.charAt(i+5)=='e'))
        {
            i=i+3;
        }
        str2=str2+str1.substring(i,i+1);
    }
    System.out.println("received data is         "+str2);
    }
}       

character stuffing program code in c++

#include<iostream>
#include<cstdio>
using namespace std;
void charc();
int main()
{int choice;
while(1)
{printf("\n\n\n1.character stuffing");

printf("\n\n2.exit");
printf("\n\n\nenter choice");
scanf("%d",&choice);
printf("%d",choice);
if(choice>2)
printf("\n\n invalid option....please renter");
switch(choice)
{case 1:
      charc();
break;
case 2:
_exit(0);
}}
system("pause");
return 0;}

void charc()
{

char c[50],d[50],t[50];
int i,m,j;
printf("enter the number of characters\n");
scanf("%d",&m);
printf("\n enter the characters\n");
for(i=0;i<m+1;i++)
{scanf("%c",&c[i]);
}printf("\n original data\n");

for(i=0;i<m+1;i++)
printf("%c",c[i]);
d[0]='d';
d[1]='l';
d[2]='e';
d[3]='s';
d[4]='t';
d[5]='x';
for(i=0,j=6;i<m+1;i++,j++)

{if((c[i]=='d'&&c[i+1]=='l'&& c[i+2]=='e'))
{d[j]='d';
j++;
d[j]='l';
j++;

d[j]='e';
j++;
m=m+3;
}d[j]=c[i];
}m=m+6;

m++;
d[m]='d';
m++;
d[m]='l';
m++;
d[m]='e';
m++;
d[m]='e';
m++;
d[m]='t';
m++;
d[m]='x';
m++;
printf("\n\n transmitted data: \n");
for(i=0;i<m;i++)
{printf("%c",d[i]);

}for(i=6,j=0;i<m-6;i++,j++)
{if(d[i]=='d'&&d[i+1]=='l'&&d[i+2]=='e'&&d[i+3]=='d'&&d[i+4]=='l'&&d[i+5]=='e')
i=i+3;
t[j]=d[i];
}printf("\n\nreceived data:");

for(i=0;i<j;i++)
{printf("%c",t[i]);
}
}