0% found this document useful (0 votes)
2 views

assignment1

The document outlines several class definitions and their functionalities in a programming context, including classes for encoding and decoding strings, formatting strings with case variations, converting and concatenating vowels, removing duplicates from an integer array, checking for triangular numbers, and determining perfect numbers. Each class specifies data members and methods for various operations, such as storing values, displaying results, and performing recursive checks. Additionally, it includes tasks related to linked lists and binary trees, detailing methods for searching, displaying, and traversing tree structures.

Uploaded by

tutor nag
Copyright
© © All Rights Reserved
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views

assignment1

The document outlines several class definitions and their functionalities in a programming context, including classes for encoding and decoding strings, formatting strings with case variations, converting and concatenating vowels, removing duplicates from an integer array, checking for triangular numbers, and determining perfect numbers. Each class specifies data members and methods for various operations, such as storing values, displaying results, and performing recursive checks. Additionally, it includes tasks related to linked lists and binary trees, detailing methods for searching, displaying, and traversing tree structures.

Uploaded by

tutor nag
Copyright
© © All Rights Reserved
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
You are on page 1/ 3

Ass1.

class encode
data members :
string str.
int len.
functions :
encode() constructor initialize string by null
public void store(string temp) store the value of temp in str
public void decode(int n) decode the string by sifting each character with n no of characters.
if the string is “cat” AND N IS 3 then “fdw”
if n is -3 then “zxq”
Ass2.
class format
data members :
string str.
int len.
functions :
format() constructor initialize string by null
public void store() store the value of using scanner class
public void gencase(int ) format the string with upper and lower using recursive . if the cAt then display
CaT.
public void display () display the formatted string.
Ass3.
class convert
data members :
string str.
int len.
functions :
convert() constructor initialize string by null
public void store() store the value of using Buffered Reader
public char vowel(int ) return the char if its vowel.
Public String concat(String temp,int p) concat all vowel from str within temp recursively , by calling vowel
function
public void display () display the string.

Ass4.
Define a class Duplicate to pack an array of 10 integers which are stored (To pack
means to remove all duplicates from the array). For e.g., if the given array has the
following sorted numbers:
1233444566
the resultant array should contain each element once. The output should be :
123456
Some of the members of the class are given below:
Class name :Duplicate
Data members:
num[] :integer array with 10 integers sorted.
Member functions:
void readList(): to enter elements of the array in sorted order.
void packList():to remove the duplicates fro the array.
void dispList(int ):to display the array of integers without the
duplicates.
Specify the class Duplicate giving the details of the functions void readList(), void
packList() and void dispList(int). The main function need not be written.
Ass 5.
A class Numbers contains the following data members and member functions to
check for triangular numbers. [A triangular number is formed by the addition of a
consecutive sequence of integers starting from 1].
e.g. 1+2=3
1+2+3=6
1+2+3+4=10
1+2+3+4+5=15
Therefore, 3.6.10,15 etc. are triangular numbers.
Class Name :Numbers
Data members/instance variables:
n :integer to be checked for whether it is
triangular or not.
Member functions/methods:
void getnum() :to accept integer n.
int check(int) :to check if ‘n’ is triangular using recursive .
void dispnum() :to display message whether ‘n’ is triangular ornot.
Specify the class Numbers giving details of the functions void getnum(), int
check(int) and void dispnum(). The main function need not be written.

Ass6.
a) The following is a function of some class. It returns 1 if the number is a perfect number otherwise
it returns 0.
/* A perfect number is a number which is equal to the sum of its factors other than the number
itself.*/
int perfectNo(int n)
{
int ?1?
for(int j=1;?2?;j++)
{
if( ?3? )
sum?4?;
}
if( ?5? )
return 1;
else
return 0;
}
i) What is the expression/value at ?1? [1]
ii) What is the expression/value at ?2? [1]
iii) What is the expression/value at ?3? [1]
iv) What is the expression/value at ?4? [1]
v) What is the expression/value at ?5? [1]

b) The following functions show( ) and calling( ) are a part of some class. Assume that the parameter
n is greater than 1 when the function is invoked. It returns the value 1 when true otherwise it returns 0.
Show the dry run/working.
void calling()
{
int f=2;
show(n,f);
}
int show(int n, int f)
{
if(n= =f)
return 1;
if(n % f = = 0 || n = = 1)
return 1;
else
return show(n,f+1);
}
i) What will the function show() return when the value of n is 11? [2]
ii) What will the function show() return when the value of n is 27? [2]
iii) In one line state what the function show(…) is doing. [1]

Ass 7.
class node
{
Int nm;
node nxt;
public void getnum() accept data
public void dis() display data
public int search(int n) search the value of n in the list if found display other wise return 0
}
Write main function to generate list as per user choice and search item from that list

Ass 8.
Generate a tree using following values 34,65,23,21,42,56,78,12,79,47,32,15,17
Display the In Order ,Pre Order and Post Order
Depth of tree
No of siblings and display the siblings

You might also like