Write an interactive c program that will encode or decode a
line of text. To encode a line of text, proceed as follows:

Convert each character, including blank spaces, to its
ASCII equivalent.
Generate a positive random integer. Add this integer to the
ASCII equivalent of each character. The same random integer
will be used for the entire line of text.
Suppose that N1 represents the lowest permissible value in
the ASCII code, and N2 represents the highest permissible
value. If the number obtained in step 2 above exceeds N2,
then subtract the largest possible multiple of N2 from this
number, and add the remainder to N1. Hence the encoded
number will always fall between N1 and N2, and will
therefore always represent some ASCII character.
Display the characters that correspond to the encoded ASCII
values.
The procedure is reversed when decoding a line of text. Be
certain, however, that the same random number is used in
decoding as was used in encoding.






Write an interactive c program that will encode or decode a line of text. To encode a line of text..

Answer / sss


#include<iostream.h>

#include<string.h>



void main()

{

char str1[]="Testing";

char str2[40];



strcpy(str2, str1);



cout<<"str1="<<str1<<endl;

cout<<"str2="<<str2<<endl;



int i=0;



while(str1[i]!='\0')

{

cout<<(int)str1[i]<<" ";

str2[i]=(char)((int)str1[i]+2);

i++;

}



cout<<endl;



i=0;



while(str2[i]!='\0')

{

cout<<(int)str2[i]<<" ";

i++;

}



cout<<endl;



cout<<str2<<endl;



i=0;



while(str2[i]!='\0')

{

cout<<(char)((int)str2[i]-2);

i++;

}


cout<<endl;

}

Is This Answer Correct ?    14 Yes 32 No

Post New Answer

More C Interview Questions

Write a function expand(s1,s2) that expands shorthand notations like a-z in the string s1 into the equivalent complete list abc...xyz in s2 . Allow for letters of either case and digits, and be prepared to handle cases like a-b-c and a-z0-9 and -a-z. z-a:zyx......ba -1-6-:-123456- 1-9-1:123456789987654321 a-R-L:a-R...L a-b-c:abbc

0 Answers  


Juxtapose the use of override with new. What is shadowing?

1 Answers  


What is getch () for?

0 Answers  


wat is output of the following int main() { const int j=2; int i; switch(i) { case 1:break; case j:break; default:break; } }

2 Answers  


How many data structures are there in c?

0 Answers  






What are the storage classes in C?

0 Answers  


Describe the modifier in c?

0 Answers  


What is a file descriptor in c?

0 Answers  


What is the difference between char array and char pointer?

0 Answers  


What is n in c?

0 Answers  


Here is a good puzzle: how do you write a program which produces its own source code as output?

0 Answers  


What is the right type to use for boolean values in c? Is there a standard type?

0 Answers  


Categories