Page 667 - Computer science 868 Class 12
P. 667
void inputArray()
{ Scanner sc=new Scanner(System.in);
System.out.println("Enter first number");
arr[0]=sc.nextInt();
for(int i=1;i<size;)
{ do{
System.out.println("Enter next number");
arr[i]=sc.nextInt();
if(arr[i]<arr[i-1])//if not sorted
System.out.println("Not in sorted order..reenter");
}while(arr[i]<arr[i-1]);
i++;
}}
Pack delDuplicate(Pack P)
{ Pack ob=new Pack(P.size);
int s=1,n;
ob.arr[0]=P.arr[0];
for(int i=1;i<P.size;i++)
{ if(P.arr[i-1]!=P.arr[i])//if not duplicate
{ ob.arr[s++]=P.arr[i];}
}
ob.size=s;
return ob;
}
void dispArray()
{ for(int i=0;i<size;i++)
{ System.out.print(arr[i]+" ");}
}
public static void main(int ss)
{ Pack o1=new Pack(ss);
Pack o2=new Pack(ss);
o1.inputArray();
System.out.println("Initial array");
o1.dispArray();
o2=o1.delDuplicate(o1);
System.out.println("\nFinal array");
o2.dispArray();
}}
Question 8. [10]
A class Encrypt has been defined to replace only the vowels in a word by the previous occurring consonant and form a new word.
i.e. A → Z, E → D, I → H, O → N and U → T
Example: Input: LAPTOP Output: LZPTNP
Some of the members of the class are given below:
Class name : Encrypt
Data Members/Instance variables
word : to store a word
len : integer to store the length of the word
wordn : to store the encrypted word
Methods/Member functions
Encrypt( ) : default constructor to initialize data members with legal initial values
void acceptword( ) : to accept a word in UPPER CASE
int add( ) : adds the ascii equivalent of the characters in variable ‘word’ and
return their sum. Eg. In LAPTOP the sum of their ascii values is
76+65+80+84+79+80=464
void changeCons( ) : replaces only the vowels from variable ‘word’ by the previous occurring
consonants, with the remaining alphabets unchanged in variable
‘wordn’
665
Sample Paper 665

