Sie sind auf Seite 1von 6

# 1. Write a program that can fill an array of 10 elements by randomly generated Integers, range (1100).

Sort the array by using bubble sort. (Read bubble sort from any book or from net)
2. Write a Program that can generate prime numbers from 0 to 1000.
3. Write a program that can generates 100 random characters but prints only Vowels.
4. Write a program that can fill an array of 10 elements by randomly generates Integers, range (1100). Find the Minimum and Maximum values without sorting the array.
5. Write a program that can create an array of 10 elements, fill the array randomly range (11000). Sort the array by using bubble sort then search any value in the array by using binary
search. The program must show the index number if the value is in the array or a message of
6. Write a program that can take 2 integer values as input between1 to 50000 (or assign them).
Add the values and then write the sum of the 2 values in vertical order. Example: If the Inputs are
23459 + 36937; the sum 60396, will be displayed vertically (Each Digit per Line)
7. Write a program that can take an Input as positive integer (call it Z) and displays the positive
integers X and Y if the following Equation is satisfied by X and Y:
X^2 + Y^2 = Z^2
For example consider the positive integer Z = 5. There exist positive integers X = 3 and Y = 4
such that 5^2 = 3^2 + 4^2 = 9 + 16 = 25 (=5^2). So if the user inputs 5, your program must
display 3 and 4. However, there are many positive integers Z for which NO POSITIVE INTEGERS
X AND Y EXISTS THAT SATISFY THE ABOVE EQUATION. So for a given positive integer Z
there are two possibilities. One possibility is that there may exist two positive integers X and Y
such that X^2 + Y^2 = Z^2. The second possibility is that there may not exist any pair of positive
integers X and Y satisfying the equation.
IF NO POSITIVE INTEGERS X AND Y EXIST SATISFYING THE EQUATION FOR A POSITIVE
INTEGER Z WHICH WAS INPUT TO YOUR PROGRAM, THEN YOUR PROGRAM MUST
DISPLAY THE MESSAGE NO X AND Y EXIST . OTHERWISE YOUR PROGRAM MUST
DISPLAY THE VALUES OF X AND Y SATISFYING THE EQUATION.
Another example of an integers Z, X, Y satisfying the equation is 15,9,12 because 15^2 = 9^2 +
12^2 = 81 + 144 = 225 (=15^2). Examples of integers Z for which no such X and Y exist are
Z=17, Z=38, Z=67 etc.
8. It is assumed that you are familiar with hexadecimal numbers. Normally the numbers (integers
or real numbers) that we use are decimal (base 10) numbers. This means that as we move from
rightmost towards leftmost digit of a decimal number, the power of 10 that the digit needs to be
multiplied with, INCREASES BY 1 each time we move 1 position to the left. Thus, for example,
the VALUE OF the decimal integer 340942 is calculated as 3 * 105 + 4 * 104 + 0 * 103 + 9
*
102 + 4 * 101 + 2 * 100 = 3 * 100000 + 4 * 10000 + 0 * 1000 + 9 * 100 + 4 * 10 + 2 * 1(100 = 1)
= 300000 + 40000 + 0 + 900 + 40 + 2 = 340942. The powers of 10 were used in calculating the
value of 340942 because the number system of 340942 was the decimal number system (base10 number system). Because the decimal number system is a base-10 system, therefore there
are 10 digits (0, 1, 2, 3, 4, 5, 6, 7, 8. 9) in the decimal number system.
Similarly, because the hexadecimal number system is a base-16 number system, therefore there
are 16 hexadecimal digits in it. The hexadecimal digits, in increasing order of value starting from
0, are 0,1,2, 3, 4, 5, 6 , 7, 8 , 9, A(=10), B(=11), C(=12), D(=13), E(=14), and F(=15). Powers of
16 are used in calculating the value of a hexadecimal integer. Thus, for example, the value of the
hexadecimal integer 5CA06F2 is calculated as 5 * 166 + 12 * 165 + 10 * 164 + 0 * 163 + 6 * 162
+ 15 * 161 + 2 * 160 = 92126130. In a similar way, the value of any hexadecimal INTEGER
could be calculated.

Write a program that inputs a hexadecimal number CONSISTING OF NOT MORE THAN 7
HEXADECIMAL DIGITS AND DISPLAYS IT'S VALUE IN DECIMAL
9. Write a program that inputs a decimal integer and displays its value in hexadecimal.
10. Take a Paragraph as a String. Create a String Array equal to the number of words in the
Paragraph. Fill the Array with the words and sort them in Ascending Order. The program must be
dynamic i.e. change in the Paragraph will not affect the Program.
11. Write a program that extracts username and the domain information from an E-mail address.
For example, if the email address is user@mydomain.com, your program will print
User name

= user

Domain

= mydomain

Extension

= com

12. A PALINDROME is a word which has SAME SPELLING whether it is read from Left to Right
or from Right to Left. Example: MOM, DAD, DEED, PEEP and NOON. Other words which are
not PALINDROME are HELLO, DOOR and FEET. Write a program that can take a String as user
input in Capital Letters and then Print YES as Output if the Input is a PALINDROME otherwise
NO.
13. Write a program that can take an English sentence as input, having some special
characteristics. Your program MUST NOT BE CONCERNED with whether the sentence is
grammatically correct or not. One special property of the sentence would be that there WOULD
NOT BE ANY INTERVENING SPACES BETWEEN THE WORDS OF THE SENTENCE. The
second property would be that EACH WORD of the sentence would START WITH A CAPITAL
LETTER, and the remaining letters of each word would be small letters. This means that, for
example, the sentence The wild cat ran over the lazy dog would be input from the keyboard
in the following form:
TheWildCatRanOverTheLazyDog
YOUR PROGRAM CAN SAFELY ASSUME that the sentence does NOT CONTAIN punctuation
marks (.,?,_,,(,) etc.), numeric digits or any symbols other than letters of the English alphabet.
AFTER INPUTTING the sentence in the form described above, your program must SEPARATE
the individual words of the sentence and display each word on a SEPARATE LINE. Thus, for
example, after inputting the sentence IAmAVeryBravePerson, your program must display the
following:

I
Am
A
Very
Brave

Person
14. Encryption and Decryption: The operation of transforming a secret message to hide it from
third persons is called ENCRYPTION and the operation of acquiring the actual secret message
from a transformed message is called DECRYPTION.
In this assignment you are required to write a program that encrypts a message and decrypts it
again. Assume that the message consists of at most 12 CAPITAL LETTERS and that the number
of letters in the message would always be even. Thus the message could only consist of 2, 4, 6,
8, 10, or 12 capital letters. The transformation rules to be applied to the message, for this
assignment are:
Suppose the message X = "ABCDEFGHIJ" is to be sent. The message would be transformed by
applying the same operation TWO TIMES. After applying the operation once, the message would
become:
After first cycle = "AFBGCHDIEJ"
Similarly, if the message was "ABCDEF" or "BNMPYT" it would become: "ADBECF" or
"BPNYMT" respectively.
In order to encrypt a message the operation described above must be applied TWO TIMES. This
means that if the message from person A, X = "ABCDEFGH" was to be sent to person B it would
first be transformed into Y = "AEBFCGDH" and then into Z = "ACEGBDFH". On receiving Z =
ACEGBDFH person B, would decrypt Z by applying reverse transformation (Two Times) to
get X (the original message).
Similarly, the user can decrypt the message by reversing the process.
15. The operation of transforming a secret message to hide it from third persons is called
ENCRYPTION and the operation of acquiring the actual secret message from a transformed
message is called DECRYPTION.
In this assignment you are required to write a program that encrypts a message and decrypts it
again. Assume that the message consists of a paragraph of any length. The transformation rules
to be applied to the message, for this assignment are:
The user inputs a paragraph with a key (a number) for the Encryption purpose. The program will
use the key. Example: Text = "ADGJL", Key= 3. The output will be "DGJMO" (Add 3 to the ASCII
of each character)
The program must be circular (C for Z). Decrypt the encrypted text by using the same key.
16. In this assignment you are required to do some string processing. Consider the English word
"CONTAMINATION". This word consists of 13 letters. However, some of the letters occur more
than once. There are ONLY 7 DISTINCT letters occurring in the string which are {A, C, I, M, N, O,
T}. So, although, the total number of letters in the word is 13, there are ONLY 7 DISTINCT letters
of the English alphabet in the string. Similarly, consider the word "RETREAT". It consists of 7
letters. However, there are only 4 DISTINCT letters in it which are {A, E, R, T}. Similarly the word
"NEEDLE" consists of 6 letters but it contains ONLY 4 DISTINCT letters which are {D, E, L, E}.
Now consider the word "FLASHING". It consists of 8 letters. But since no letter is repeated, the
number of DISTINCT letters occurring in it is ALSO 8. Similarly the number of DISTINCT letters
occurring in the word "PROMISE" is the SAME (7) as the TOTAL number of letters occurring in it.
Write program which inputs a word (having not more than 15 letters) from the keyboard and
displays the number of DISTINCT letters occurring in it.
17. In this assignment you are required to perform a simple task. Write a program which inputs
three integers SEPARATELY. The first integer would represent the Day of the month, the second
integer would represent the Month of the year, and the third integer would represent the calendar

Year. After inputting the Day, Month, and Year, your program must DISPLAY "Yes" on the screen
if the three values represent a VALID DATE and must DISPLAY "No" on the screen if the three
values do not represent a valid date. The value for Day can lie in the range 1-30, 1-31, 1-28, or 129, depending upon the month and year. The value for month can lie in range 1-12. The value for
year can lie in the range 2000-2099.
Examples of valid dates are (in D-M-Y format) 10-7-2001, 29-2-2004 and 31-8-2007. Examples of
invalid dates are 31-4-2005, 29-2-2005, 40-13-2003 etc.
18. Sequences of characters are called STRINGS in the domain or area of computers and
computer programming. Strings are usually represented by enclosing the sequence of characters
in a pair of double quotation marks. Examples of strings are "How are you?", "good123sound"
etc.
In this assignment you are required to write a program which inputs two strings, string X and
string Y from the keyboard. Your program can assume that each string consists of ONLY
CAPITAL LETTERS (e.g. K, V, B etc.) of the English alphabet. This means that the string
CANNOT CONTAIN small letters, punctuation marks, or any other characters!! Your program can
ALSO ASSUME that the string DOES NOT CONTAIN MORE THAN 30 CAPITAL LETTERS.
After inputting the strings X and Y, your program must scan each string and DISPLAY the word
"SAME" on the screen IF THE STRING X CONTAINS EXACTLY THE SAME SET OF CAPITAL
LETTERS AS THE STRING Y. Your program will have to scan both strings by using some logic in
order to find out.
Let us look at an example. Suppose X = "YUDGEYPUEPPGB" and let Y = "UPBYUGDPEEB".
The string x contains the letters {B, D, E, G, P, U, Y} and the string y contains the letters {B, D, E,
G, P, U, Y}. So in this case both strings contain the same set of capital letters. Therefore, in this
case, your program must display the word "SAME". However, if x = "SNBSEMNP" and y =
"EMMNPPPEXXP", the sets are {B, E, M, N, P, S} and {E, M, N, P, X} respectively. The two sets
are not the same. So in this case your program should DISPLAY "DIFFERENT" on the screen.
19. In this assignment you are required to write a program that inputs a String consisting of
CAPITAL LETTERS ONLY and displays ONLY VOWELS WHICH OCCUR IN THE STRING.
Remember that the vowels in the English alphabet are A,E,I,O, and U. Assume that the input
string DOES NOT CONTAIN any punctuation marks, small (lower-case) letters, or any other
symbols except capital letters. Also assume that the input string is not more than 30 characters
(all of which would be capital letters) long. For example, suppose that the input String is
"TMACVUDAGGHADUUFEH". In this case your program must display A E U. Remember that
the vowels occurring in the string should be DISPLAYED IN ALPHABETICAL ORDER! This
means that for the above example the outputs U E A or E U A or A U E etc. would NOT BE
ACCEPTABLE. ALSO NOTE THAT NO VOWEL SHOULD BE DISPLAYED MORE THAN ONCE,
even if it occurs more than once in the String, this means that outputs like A A E I I O O O U U are
not acceptable!!
20. Write a program that can display the number of occurrences of every character in a String
paragraph of minimum 150 characters.
21. Write a program that can take two 5 digits numbers input as String at rum time. Convert the
two numbers in numeric form and show the result of their addition. For example: first number is
12345 and second is 56789. Convert these 2 in numbers, add them and print the result.
22. Write a class BankAccount in which use an instance variable with a name balance. Write
three methods having names of deposit (), withdraw () and display () and use these to manipulate
and display balance of an account. Write methods to view and change the information of the
Bank Account holder.
23. Define a class Math with four methods min for minimum, max for maximum, ceil for ceiling
and abs for absolute. Use 2 integers for minimum and maximum, 1 for absolute and 1 double for

ceiling in calling of methods after making an object of class Math from class Test. Use appropriate
return types in all methods. (Don't use Math class)
24. Create a class Point, with two properties x and y. Write all the methods to manipulate the
values of Point. Write a method that can check two Objects of Point class for Equality.
25. Create a Class Line. Line Objects will be created by 2 Point Objects. Create 2 Line objects
and check their equality by calling Point class equals function from Line class equals function.
26. Create a class named Distance that can store measurement of distances in two possible
units, kilometers and meters. The distances in kilometers are to be stored as double values
whereas any distance in meters is to be stored as int. Create an equals() method so that any two
objects of Distance class can be compared. Also, create a detail() method to display the content
of Distance object with its proper units.
27. Create a class with a name Calculate. Add two basic arithmetic functions to it, such as add()
and subtract() to perform mathematical calculations. Now overload these methods so that they
can take three types of values, an int, a double or a char. Note that if characters are passed to a
method, it should return char, if double is sent to a method it should give its answer in double, and
so on. Use this class from a test class stored in a separate file.
28. Create a class Card, and its children classes are Valentine, Holiday, and Birthday. A card
class will have a greeting () method that writes out a greeting. Each type of card contains an
appropriate greeting. The Holiday card says "Season's Greetings." The Birthday card says
"Happy Birthday." The Valentine card says "Happy Valentine Day". Create objects of the three
child classes: Valentine, Holiday, and Birthday and show the polymorphic behavior (call the
greeting methods from each object).
29. Develop a registration system for a University. It should consist of three classes namely
Student, Teacher, and Course. For our example, a student needs to have a name, roll number,
address and GPA to be eligible for registration. Therefore choose appropriate data types for
encapsulating these properties in a Student object/s. Similarly a teacher needs to have name,
address, telephone number, and a degree (or a list of degrees) he has received. Finally courses
must have a name, students (5 students) registered for the course, and a teacher assigned to
conduct the course. Create an object of Course with 5 Students and a Teacher. A call to a
method, say printDetails(), of the selected course reference should print name of the course,
details of the teacher assigned to that course, and names and roll numbers of the students
enrolled with the course.
30. Create a class/abstract class/interface Shape with three child classes Circle, Square and
Rectangle. Create a method Draw in the Parent override in each class. E.g. in Circle "This is a
Circle". Create an array variable of type Shape of 10 elements in main class. Fill the Shape array
with the child classes Objects randomly. Call the Draw method of each object filled in the array.
31. Create an inheritance hierarchy of Vehicle: Car, Bus and Truck, with the SchoolBus further
extending the hierarchy through the Bus. Each of the derived class objects should be packaging
information about category and passenger carrying capacity of that vehicle. Provide a method
that is common to all derived classes, such as getPassengerCapacity (), with class Truck having