Computer Appications
Computer Appications
21. Display the information in the given format. Also at the end print
the total number of cities where the temperature is more then 35 degree
centigrade and the city name with maximum temperature.
City Name Fahrenheit Temperature Centigrade Temperature
--------- ---------------------- ----------------------
Number of cities more then 35-degree centigrade temperature:
Name of the city with maximum temperature:
22. Write a program in JAVA that reads the following list of countries
and their respective cities into two separate one-dimensional arrays. The
program should accept the name of a country as input and give the name
ASSIGNMENT
Computer Applications Arrays
of the corresponding city as an output. The program should be designed
to give an error message where a city is asked for a country whose name
is not given in the list. To stop the program, "XXX" is to be entered as
input.
GERMANY BERLIN
NEPAL KATMANDU
JAPAN TOKYO
CANADA MONTREAL
IRAQ BAGHDAD
SRI LANKA COLOMBO
BRAZIL BRAZILIA
AUSTRALIA PERTH
INDIA DELHI
SOUTH AFRICA PRETORIA
23. Write a program in JAVA to store 20 names, address and phone
number in three separate arrays. Depending on the user's choice either
locates name or phone number and prints all the information.
24. Write a program in Java to stores names of the 10 politicians and
their party to which they belong to in two separate arrays. Ask the users
to enter the name of the party. Printout all the names of the politicians
who belong to that party. Repeat the process according to user choice.
25. A metropolitan hotel has ten floors numbered from 1 to 10, each
floor having fifty rooms. Using a single subscripted variables for the name
of the customer and a double subscripted variable R[F][I] where F & I
represents floor and room numbers. Write a program for the room
allocation work. The program should automatically display the name of all
customer, room and floor number.
26. Accept numbers into an array of size 3X4. Then display the array
properly.
27. Accept numbers into an array of size 4X4. Then display the
diagonals and also display the sum of numbers present in the diagonal
position.
28. Write a program to accept number into a 3X4 matrix. Display the
original array. Then calculate and display the each row total.
29. Write a program to accept number into a 3X4 matrix. Display the
original array. Then calculate and display the each column total.
30. Write a program to accept number into a 10X5 matrix. Then display
the original array and the array sorted on each column.
31. Accept numbers into an array of size 5X5. Then display the numbers
present in upper portion of the left diagonal of the matrix.
ASSIGNMENT
Computer Applications Arrays
32. Accept numbers into an array of size 5X5. Then display the numbers
present in below portion of the left diagonal of the matrix.
33. Write a program to accept numbers into a 4X3 matrix. Display the
original matrix and display the matrix in transpose form.
34. Write a program to generate a Pascal triangle in which each number
in the row is the sum of the two numbers immediately above it. The
program should print the first six rows of the triangle.
(Hints: E[J.I] = P[I-1,J-1] + P[I-1,J] is true for all elements but the
boundary elements which are all equal to 1)
35. Write a program to generate a Pascal triangle in which each number in
the row is the sum of the two numbers immediately above it. The
program should accept the number of rows to be print.
1
11
121
1331
14641
36. Write a program to perform MATRIX multiplication of two Matrixes.
Where size of two matrixes is given by user, also check MATRIX
multiplication possible or not.
37. Accept a name and print it in reverse form. (If name is AMIT, then
output is TIMA).
38. WAP to accept a name. Then display the ASCII value of each
character present in that name.
39. WAP to read a word. Print the position of the first vowel occurring in
the word. If there is no vowel in the word then print 'Sorry no vowel'.
40. WAP in BASIC to take a proverbial statement (like 'Failure are the
pillars of success') as an input from the user and then output the
frequency of the vowels occurring in the statement.
41. WAP to enter any sentence and calculate the following:
a) Total number of digits present in it.
b) Total number of small letters and capital letters present in it.
c) Total number of alphabets used in it.
d) Total number of special character used in it.
e) Total number of vowels presents in it.
f) Total Number words present in that sentence.
42. Write programs to accept any word and check whether the word is
palindrome or not.
ASSIGNMENT
Computer Applications Arrays
43. WAP to accept a name (in first name & last name format), then
display that name in short format. (Example - SACHIN TENDULKAR
becomes S. TENDULKAR)
44. WAP to accept a person's first, middle and last names in a string
variable and then display in short form. (Example - ARUP KUMAR DAS
becomes A. K. DAS)
45. WAP to converting all capital letters of a string into small letters
(without using library function). For example: Input: MY NAME IS SUMIT
Output: my name is sumit
46. WAP to accept any name (full name) and convert it to Proper Case.
47. WAP to accept any string and then convert each 'A' to 'AN' present
in that string. Then print the string. (Note: remember 'A' should not be a
part of a word?).
48. Sankalp has a terrible habit of deleting the last two letters of a word
beginning with 'E' and adding a single letter 'O' in their place. WAP to
convert a given word Exterminate or Ellipse according to Sankalp habit.
49. In Piglatin a word such as KING becomes INGKAY, TROUBLE
becomes OUBLETRAY as so on. The first vowel of the original word
becomes the starting of the translation and proceeding letter being
shifted towards the end and followed by AY. Word that begins with a
vowel is left unchanged. WAP to accept a word and convert in to Piglatin
word.
50. Accept two strings, a word and a sentence. Then find number of
times the word is present in given string. If I enter 'THE' and 'THE BIG
FAT THE ODORE', then the computer should display 2.
51. WAP to accept a sentence then convert each character to second
next character. The character A becomes C, Y becomes A and Z becomes
B.
52. A name is to be said as odd name if the ASCII code of each
character become an odd number. Write a program to accept a name and
check whether the given name is odd name or not.
53. Write a program for converting a sentence in reverse. (Input: BASIC
IS PROGRAMMING Output: PROGRAMMING IS BASIC)
54. Write a program to accept a binary number and convert it to
decimal number. Also convert each binary digit to its compliment and
then convert it to decimal number.
55. Write a class to check whether a given number is Armstrong or not
using a function name int checkArmstrong(int num). Function should
return a value 1 if number is Armstrong otherwise it return 0 if not.
ASSIGNMENT
Computer Applications Arrays
56. Write a class using a function primeCheck(int num) to check
whether a given number is Prime or not. Function should return a value 1
if number is prime otherwise it return 0 if not.
57. Write a class using a function as follows: int num (int) the function
accepts a number and finds whether it is even and divisible by 8 or not.
It returns '1' if condition is satisfied otherwise '0'. Use a main program to
pass the number by value to the function.
58. Write a menu driven program (using switch case) to find the areas
of circle, square or rectangle. Use function overloading for each of the
given shapes.
59. Develop a class "Array" with the following Specifications:
instant Variables- int a[20], k
Member functions-
public void input() To input integer members to array A and a number
separately to variable k.
public void search() To find and print 'Search Successful' if number is
found 'Search Unsuccessful' otherwise.
60. Define a subclass sub1 in which define a method f1() to calculate
and print hcf (highest common factor) by division method of any two
given numbers entered by user in the main class. Define another
subclass sub2 in which define a method f2() to calculate and print the
area and perimeter of a rectangle by using the required parameters
accepted in main class. Define main class to input the parameters
required in the above two methods and also call the two functions.
61. Define a subclass str1 in which define a method rev1() to input a
word and display it in reverse order. Define another method rev2() in the
same subclass to input any 10 words and display the words having odd
number of characters. Define main class to execute two functions.
62. Write a program to print the few lines of the following patter
(number of lines is given by user). Use one function for printing
alphabets and another function to print the number.
AAAAA1
BBBB12
CCC123
DD1234
E12345
63. The number 151 is a prime palindrome, because it is both a prime
number and a palindrome. Write a class that find all prime palindromes
between two given numbers a and b. Accept the values for a and b from
the user in function main(). Use two function in your class, boolean
ASSIGNMENT
Computer Applications Arrays
isPrime(int) for check number is prime or not, int isPalindrome(int) to
check number is palindrome or not.
64. Create a class BubbleSort to arrange 20 integer type values in
ascending order or descending order using the function "void
bubbleSort(int n[],int so)". Here "so" stands for the sort order i.e. +1 for
ascending and -1 for descending.
65. In Piglatin a word such as KING becomes INGKAY, TROUBLE
becomes OUBLETRAY as so on. The first vowel of the original word
becomes the starting of the translation and proceeding letter being
shifted towards the end and followed by AY. Word that begins with a
vowel is left unchanged. Write a class to accept a word and convert in to
Piglatin word. Define a function int vowelPos(String) to find out the
position of first vowel in the given word.
66. Write a MENU Driven program using separate function to calculate
and return the answer of the following options from a given sentence:
a) Total number of digits present in it.
b) Total number of small letters and capital letters present in it.
c) Total number of alphabets used in it.
d) Total number of vowels presents in it.
e) Total Number words present in that sentence.
67. Write a class to display each word of the string in reverse order.
e.g. If input is "India is my Country" output is "aidnI si ym yrtnouC". Use
following function in your class:
public String reverse(String word) which will return the reverse word.
public void newstr(String Sentence) Receive a sentence and reverse the
each word in the sentence.
68. N is a perfect number if the sum of all factors of the number
(including 1 but excluding the number) is equal to N. For e.g. 6 =
1+2+3. The class numberProblem below contains some methods that
help you to work with perfect number. Study the class and then answer
the following questions.
Public class numberProblem
{
int sumOfFactors(int N)
{
// which return sum of all the factors of the number N.
}
boolean isPerfect(int N)
{
// return true if the number N is perfect and false otherwise.
ASSIGNMENT
Computer Applications Arrays
}
void nosBelow(int lim)
{
// which prints out all perfect numbers less then lim.
}
}
Define the class numberProblem and the definitions of all the methods
given in that class.
69. A number is called Armstrong number if the sum of cube of each
digit of the number is equal to that number. (e.g. 153 is a Armstrong
number because 153 = 13 + 53 +33).
Define a class armStrong that has the following functions.
private int sumOfDigit(int N) -> which return the sum of cube of each
digits present in N.
public static void main(int x, int y) -> which display all the arm strong
number between the range x and y.
70. Write a program to accept a sentence then convert it to Title Case.
That means first character of each word should be capital and remaining
are small letter. (e.g. MY NAME IS AMITABH become My Name Is
Amitabh)
Define a class that has the following functions.
private String properWord(String word) -> which convert the word to
proper case (AMIT becomes Amit) and return it.
public void main(String Sentence) -> which print the given sentence to
in the above mention format.
71. Write a program to determine if the input number is a lucky number
or not. A lucky number is a number whose digits when added (till a single
digit is obtained) it equals to 1. For example,
4567 = 7+6+5+4 = 22 22 = 2+2 = 4 4 is not = 1
So 4567 is not a lucky number.
4627 = 7+6+2+4 = 19 19 = 1+9 = 10 10 = 1+0 = 1
So 4627 is a lucky number.
Define a class luckyNumber that has the following functions.
private int sumOfDigit(int N) -> which return the sum of digits present
in N.
public void isLucky(int number) -> which check and display a proper
message, if the given number is Lucky number or not.
72. A class clock has following members:
Instance variable: hour and minute of integer type.
Member function/methods:
ASSIGNMENT
Computer Applications Arrays
public clock(int,int) -> constructor to initialize hour and min.
public void showTime() -> to display the time.
public void addTime(clock,clock) -> to add to clock objects.
Write another class time with main() function which create two different
objects FT, ST print their sum using the above clock class function. If FT
= 6 Hrs 35 Min and ST = 3 Hrs 45 Min then output 10 Hrs 20 Min.
73. Convert each ward to Piglatin word in a sentence.
Define a class that has the following functions.
private static int vowelPos(String word) -> which find and return the
first vowel position in the word.
private static String Piglatin(String word) -> which convert the word to
Piglatin word and return it.
public void main(String Sentence) -> which print the sentence after
converting each word to Piglatin word.
74. N is a perfect number if the sum of all factors of the number
(including 1 but excluding the number) is equal to N (for e.g. 6 =
1+2+3). N is a prime number if it is divisible by 1 and itself.
Define a class numProblem that has the following functions.
int nthPrime(int N) -> which return the nth prime number(first prime
number is 2) (e.g. 3rd prime number is 5)
void perfectNosBelow(int N) -> which first print out the nth prime
number and then print out all perfect numbers less then the nth prime
number.
75. Your computer science teacher is trying to analyze the performance
of the class in the previous exam. He has a class called performance that
contains the marks of 50 students. These are not sorted. He wants to
find two quantities. (i) Mode - The most frequently occurring mark in the
class. If two or more marks occur equally frequently then the highest of
these marks is the mode. (ii) Mode frequently - Frequency at mode.
Important: You are not allowed to sort the marks.
Some of the instance variable and member functions of the performance
class are given below.
mark[] -> an array to store Marks of 50 students
mode -> to store the Mode
freqatmode -> the frequency at mode.
void readmarks() -> for reading the marks into the array.
void calcmodeandFrequency() -> a single function that calculates both
mode and frequency at mode.