All pastes #918985 Raw Edit

Shreyas Gune's program

public text v1 · immutable
#918985 ·published 2008-02-26 14:47 UTC
rendered paste body
//~ Question 1
//~ This is a simple cryptography problem. Given a string only in the upper case , we encode it in this way : we replace each letter by a letter that is at a fixed distance ahead or behind 
//~ in the alphabetical order. The alphabet is asumed to wrap around (that is 'A' follows 'Z ' ). Similarly we can decode an encoded string. Define a class called Crypto which has an instance variable
//~ char s[] and a method encodeDecode which is described below. Define a constructor if u want.
	//~ char encodeDecode(int move)- replaces each character in 's' by the character which is at a distance of 'move' ahead , if move is positve and if move is 
		//~ -ve then replace the char in the array 's' as the char at'move' distance behind. if move is 0 print the code as it is.
			
		//~ eg : s= "ABCXY" , encodeDecode(2) returns "CDEZAB".
		      //~ s= "ABCDE" , encodeDecode(-3) returns "XYZAB".
		
		
//~ my program:
		
	#include <iostream.h>
#include <conio.h>
#include <string.h>

class Crypto
{	int n;
	char s[30];
	int move;
	int arr[30];
	//initializing everything
	Crypto()
	{
		
		move=0;
		for(int i=0;i<30;i++)
		{
			arr[i]=0;
		strcpy(s[i]," ");
		}
		
		n=0;
	}
	
	void enterstring()
{
	//entry of string
	cout<<"Please enter the code.";
	cin>>s;
	//making sure that the string is Capital
	for(int n=0;n<30;n++)
	{
		s[i]=(toupper(s[i]));
	}
}
		
char encodeDecode (int move)
{
	//to put all the ascii values of the string entered in our self defined array arr.
	for(int i=0;i<30;i++)
	{
		arr[i]=int(s[i]);
	}
	//status : Done
		if(move>0) //Condition chek 1
			{
				for(int j=0;j<30;j++)
				
				{ 
					strcpy(s[i],(char(arr[i+move])));
					
				}
				for(int p=0;p<30;p++)
				return s[p];
			}
			
				if(move<0)
			{
				for(int j=0;j<30;j++)
				
				{ strcpy(s[j],(char(arr[j+move])));
				}
				for(int p=0;p<30;p++)
				return s[p];
			}
			
			if(move=0)
			{
				for(int y=0;y<30;y++)
				{
					cout<<s[y];
				}
				for(int p=0;p<30;p++)
				return s[p];
			}
		}
	};
	void main()
{
	cout<<"enter the damn length:: ";
	cin<<n;
		Crypto c;
	c.enterstring();
	c.encodeDecode(n);
	getch();
}