Saturday, February 2, 2008

Computer Applications Model Paper

Try Solving These Questions

More Coming Soon !!




Q7 .(a) Write a program to input the number of a week and print the corresponding day. Assume 1 for Monday, 7 for Sunday, etc. also give the proper message for the wrong number input.

(b). Write a program to enter the name and convert its each lower case letters to uppercase and vice versa.

Example : Input - Subhash Chandra Bose

Output- sUBHASH cHANDRA bOSE

Q8. Write a program to input a sentence. Create a function convert(int n), where n is an integer value in positive or negative. This function is used to encode or decode the given string by shifting each character of a string the number of times as specified by user.

Ex.- Input- Good Boy

Shift value3

Output – Jrrg Erb

You can see that this function does not affect the spaces. Also if it reaches end of the alphabet list it starts the list again.(see the state of ‘y’ in “Boy” above, it changes to ‘b’). in the similar manner if the entered shift value of n is in negative then all the characters in a string will shift backwards.

Q9. The distance between two cities is measured in Kilometers(km) and Meters(m). Thus to add distance of two cities from the current city we need to add its km and m of one city with the km and m of other city. You must remember that 1000 meters makes one(1) Kilometer. Write a class with the following data members to add the distance of two cities from the current city.:

Class name : distance

Data members

Integer : km ,m

Methods

Distance Run(distance,distance) : to input two distances and to add them into the third

Display : to display the total distance.

Display the constructor required to initialize the objects.

Q10. Write a program to create a double dimensional array[4*4] to store 16 elements and to perform the following operations as per user choice-

1. To print the position of largest and least element

2. To print the sum of its diagonal elements

3. To print the sum of all the elements.

Q11. Design a class named “Database”. It has name, address, city, pin code and basic salary as data members. it also has member functions to input data, print data and calculate Dearness allowance which is 150% of basic salary, House rent which is 40% of basic salary and gross salary which is sum of basic, D.A. and H.R.A. A parameterized constructor is used to pass initial values to arguments by implicit call method.

Define the class “ Database”. Also create an object of the class.

Q12. Write a program to initialize an array of 5 names and initialize another array with their respective telephone numbers. Search for a name input by the user, in the list. If found, display “Search Successful” and print the name along with the telephone number, otherwise display “Search unsuccessful. Name not listed”.

Sunday, January 20, 2008

Program To Print All the NON Fibonacci Numbers


Write a function print() that accepts two numbers and print all the numbers between them,except those two numbers
Using this function, write a program to print all the non-fibonacci numbers from 1-100

Quadratic Equation

Wap to input the values of three coefficients of a quadratic equation
AX(Square)+BX+C=0
Find the roots of the Equation and display them , stating wether they are real,imaginary or equal
Also print the value of X

import java.io.*;
class Quadratic
{
public int a,b,c;
public void Quadratic()throws IOException
{
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
System.out.println(" Enter the value A");
int a = Integer.parseInt(br.readLine());
System.out.println(" Enter the value B ");
int b = Integer.parseInt(br.readLine());
System.out.println(" Enter the value C ");
int c = Integer.parseInt(br.readLine());
}
public void Values()
{
double x1,x2;
int z = (b*b)-(4*a*c);
if(z>0)
{
System.out.println(" Real Roots ");
x1=(-b+Math.sqrt(b*b-4*a*c))/(2*a);
System.out.println( " Root 1 " + x1);
x2=(-b-Math.sqrt(b*b-4*a*c))/(2*a);
System.out.println( " Root 2 " + x2);
}
else if(z==0)
{
System.out.println(" Equal Roots ");
x1= (b)/(2*a);
System.out.println(" Root = " +x1);
}
else if(z<0)
{
System.out.println(" Imaginary Roots ");
}
}
public static void main(String args[])throws IOException
{
Quadratic Q = new Quadratic();
Q.Quadratic();
Q.Values();
}
}

Saturday, January 19, 2008

String based Program

Write a Program to accept a String and print it in following manner
Input - Harsh Kumar Agrawal ( Just an Example)
Output - H.K.Agrawal






Frequency Of Vowels In the String

Q Write a Program to Find the Number of times vowels Occure in a given String

Method 1 - Of anshul
import java.io.*;
class vowels{ public static void main()throws IOException
{
BufferedReader in=new BufferedReader(new InputStreamReader(System.in));
String str;
int i,c=0,j;
System.out.println("Enter a string");
str=in.readLine();
str=str.toLowerCase();
for(i=0;i<=str.length()-1;i++)
{
j=str.charAt(i);
if(j==' ')
{
if((j+1)=='a'(j+1)=='e'(j+1)=='i'(j+1)=='o'(j+1)=='u')
c++;
}
}
if(str.charAt(0)=='a'str.charAt(0)=='e'str.charAt(0)=='i'str.charAt(0)=='o'str.charAt(0)=='u')
c++;
System.out.println("\n no. of words starting with vowels::::"+c);
}
}

Method 2 (By Harsh)(me :))
import java.io.*;
class Proverbial
{
public static void main(String args[])throws IOException
{
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
System.out.println(" Enter a String ");
String s=br.readLine();
char ch;
s=s.toLowerCase();
int c=0,l=s.length();
for(int i=0;i
{
ch=s.charAt(i);
if(ch=='a'||ch=='e'||ch=='i'||ch=='o'||ch=='u')
c++;
}
System.out.println(" Frequency of Vowels is "+ c);
}
}





Wednesday, January 16, 2008

Perfect Number

A perfect Integer is a number which is equal to the sum of all its factors
eg - 28 is a perfect integer as it is the sum of all its factor -
1 + 2 + 4 + 7 + 14 = 28
Wap to display perfeect integers form 1 to 1000
Evergreen Publications Model Paper1 Q9


[2D Array] Sum of diagonals

Wap To input numbers into a array of 3 rows And 3 coloumns . find the sum of the numbers in the diagonal elements . no element should be repeated twice
Evergreen Publication Model paper 1 Q8

import java.io.*;
class SumDiagonal
{
public static void main(String args[])throws IOException
{
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
int a[][]=new int[3][3];
int Sum=0;
System.out.println(" Enter 6 elements for array one :");
for(int i=0;i<3;i++)
{
for(int j=0;j<3;j++)
{
a[i][j]=Integer.parseInt(br.readLine());
}
}
System.out.println(" Matrix ");
for(int i=0;i<3;i++)
{
for(int j=0;j<3;j++)
{
System.out.print(a[i][j]+"\t");
}
System.out.println();
}
for(int i=0;i<3;i++)
{
for(int j=0;j<3;j++)
{
if(i==j)
Sum = Sum + a[i][j];
if(i+j==2&&i!=j)
Sum = Sum + a[i][j];
}
}
System.out.println("Sum of Diagonal = "+Sum);
}
}