Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
9 views

Program Questions Class 11

The document outlines a series of programming questions for Class 11, each requiring the creation of a specific class with defined data members and methods. Topics include date arithmetic, string manipulation, matrix operations, arithmetic expressions, time calculations, character arrays, octal number handling, and various mathematical concepts such as Fibonacci series, prime numbers, and happy numbers. Each question specifies the class structure and functionality needed to solve the problem presented.

Uploaded by

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

Program Questions Class 11

The document outlines a series of programming questions for Class 11, each requiring the creation of a specific class with defined data members and methods. Topics include date arithmetic, string manipulation, matrix operations, arithmetic expressions, time calculations, character arrays, octal number handling, and various mathematical concepts such as Fibonacci series, prime numbers, and happy numbers. Each question specifies the class structure and functionality needed to solve the problem presented.

Uploaded by

smritighosh8
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 12

PROGRAM QUESTIONS FOR CLASS 11

Question 1
Create a class date to do date arithmetic with date datatype.
Class Name : Date
Data member/instance variables : dd, mm, yy for day, month and year
Member functions/methods:
void input() : input values from keyboard to initialize dd, mm, yy
int leapyear(int y) : return 29 if y is leap year, else 28
boolean isvalid() : return true if dd, mm, yy is in valid format else false.
void increment() : increases the current date by one day
int noofdays(Date d) : returns number of days from the current date to date d. assume date d is
greater than current date.

Question 2
Input s sentence using String to extract the words and print the palindromic words in sentence.
Class Name : Sentence
Data member/instance variables : String sent
Member functions/methods:
Sentence(String s) : constructor
int noofwords() : number of wors in the sentence using String
String extract(int n) : extract nth word from the sentence
String reverse(String word) : reverses the word
void display() : displays the palindromic words in the ‘sent’.

Question 3
A class Matrix is declared as follows.
Class Name : Matrix
Data member/instance variables : integer arr[][] to store number in 2D array
Member functions/methods:
Matrix(int size) : constructor to create square 2D matrix of given size
void input() : input values from user into array
void display() : prints array in matrix format
boolean istranspose(identity b) : returns true if the current matrix is transpose of identity b.
Create two object in void main() and check and print if they are transpose to each other.
Example:
Input m = 4 Transposed matrix
3574 3121
1649 5642
2475 7473
1234 4954

Question 4
A class expression is declared to perform arithmetic operation on a string. The string expression consists of
2 numbers with an operator (+, /, *, -, ^) in between. The program has to extract the two numbers and
evaluate the final expression numerically. For example “12+230” will be evaluated to 242.
Class Name : Expression
Data member/instance variables : String expn
Member functions/methods:
Expression(String jj) : constructor initialize expn
int firstvalue() : returns first (left side of operator) number from sting
int secondvalue() : returns second number from string
char operat() : returns operator in character form
Page 1 of 12
int finalvalue() : returns evaluated value of the expression

Question 5
A manager of an Internet Service Provider company wants to analyze the system usage from the log records
to find the utilization of the system. He wants to know for how long each user used the system. When the
user wants to use the system he must login to the system (start-time E.g. – 12:30) and after finishing the
work, he must log-out off the system (end-time. E.g. – 18:10). The time format is the 24 hour system hours
and minutes. You may also assume that the data is valid and a user will log in for less than 24 hours.
Assume that a user will log-in only once in 24 hours. If end-time (E.g. – 2:30) is less than the start-time (E.g.
– 19:20) it means that the user logged in over the night.

A class called time has been defined to calculate the time related functions.
Class Name : Time
Data member/instance variables : hh – hours, mm – minutes
Member functions/methods:
Time() : constructor
void readtime() : to read the time in 24 hour mode as hh-mm
void disptimeansi() : display time in 24 hour as hh-mm
int timetomin(time) : to find total number of minutes in hh-mm
void mintotime(int) : to convert total number of minutes into hh-mm
void diff(time, time) : to find the difference between end time and start time in hours and minutes.

Question 6
Class ChaArray contains an array of n characters (n<=100). You may assume that the array contains only
the letters of the English alphabet. Some of the member functions/methods are given below:
Class Name : ChaArray
Data member/instance variables:
char ch[] : an array of characters
int size : the size of array of characters
Member functions/methods:
ChaArray() : initialize variables to null
ChaArray(ChaArray b): assign character array b to instance variable
void dispArray() : to display the list of n characters
void move() : to move all the uppercase letters to the right side of the array and the
lowercase letters to the left side of the array without using any sorting techniques
Example:
Input: tDfsXvd
Output: tdfsvXD

Question 7
Create one object using constructor, one object using input() and display the two numbers added as octal
number
Class Name : Octal
Data member/instance variables : int num to store the number in octal format
Member functions/methods:
Octal(int x) : initializes num
void input() : stores the value entered through keyboard in num
void display() : displays the current number
Octal add(Octal b) : adds to octal number and returns the result

Question 8
The class defines a point on a graph paper. It shows if three points are collinear or not. Complete the class
and the function given below.
Class Name : Point
Data member/instance variables:
Page 2 of 12
int x : stores the x-ordinate
int y : stores the y-ordinate
Member functions/methods:
Point(int a,int b) : constructor
int dis(Point p1, Point p2) : finds distance between two points
void coll(Point p1, Point p2, Pointp3): prints if the three points are collinear.

Question 9
Design a class “Prime” to fill an array of size[m] where maximum value of m is 20 with first 10 numbers.
The details of the members of the class as follows:
Class Name : Prime
Data member/instance variables:
int ar[] : to store integer 1D array
int m : to store the size of the array
Member functions/methods:
Prime() : constructor to initialize the size and data members of the array
void fill() : to fill element of array with first 10 numbers
int isprime(int p) : returns 1 if specific number is prime and 0 if not prime
void display() : displays the array

Question 10
Define a class “DeciOct” which allows the user to convert a decimal number to octal equivalent.
Class Name : DeciOct
Data member/instance variables : dec – stores decimal number
Member functions/methods:
DeciOct() : default constructor to initialize the data members
void accept() : to accept a decimal number
void convert() : to convert decimal to octal
void show() : to show the numbers

Question 11
Define a class “Merge” which allows the user to concate two arrays. The details are as follows:
Class Name : Merge
Data member/instance variables:
int a[], b[] : to store two 1D string arrays of size m, n respectively
int c[] : to store merged array
int i, j : to point the indices
Member functions/methods:
Merge() : constructor to initialize data members
void input() : accept two arrays
void merge() : to merge two arrays
void show() : to display two arrays and final array

Question 12
A class “Fibo” is declared as follows to print the Fibonacci series up to N terms
Class Name : Fibo
Data member/instance variables : int n – to store number of terms
Member functions/methods:
Fibo() : constructor to initialize the data members
void accept() : to accept the number of terms
int series(int) : to produce the Fibonacci series using recursion up to n terms
void print() : to print the Fibonacci series

Page 3 of 12
Question 13
A class is defined as follows for calculate the sum of the digits of an integer number
Class Name : Digit
Data member/instance variables : d – to store an integer number
Member functions/methods:
Digit() : constructor to assign initial value to d
int calculate(int n) : to calculate the sum of the digits of the entered number
void display() : to display the sum

Question 14
Define a class RecurFact to calculate factorial value of the number. The details of the class are given below:
Class Name : RecurFact
Data member/instance variables:
int c : store the number
int f : stores factorial value of n
Member functions/methods:
RecurFact() : default constructor
void input() : to accept a number
int fact(int) : calculate factorial value using recursive technique
void display() : to display the factorial value of n

Question 15
Define a class Combination to implement the below formula. The details of the class are given below:
𝑛
𝐶 (𝑛, 𝑘) =
𝑘! (𝑛 − 𝑘!)

Class Name : Combination


Data member/instance variables : int n, k
Member functions/methods:
Combination() : to initialize the data members n=0 and k=0
void read() : to accept the value of the data members
int fact(int) : return the factorial of a number using recursive technique
void compute() : calculate the combination value
void display() : to display the result

Question 16
A class DecBin has been defined to convert a decimal number into its equivalent binary number. The details
of the class are given below:
Class Name : DecBin
Data member/instance variables:
int n : integer to be converted to its binary form
int s : binary equivalent number
int i : incremental value of power
Member functions/methods:
DecBin() : constructor to assign initial value to the data members
void getdata() : to accept the value of n
void recursive(int) : to calculate the binary equivalent of n using the recursive technique
void putdata() : to display the decimal number and its binary equivalent

Question 17
A class Convert has been defined to express digits of an integer in words. The details of the class are given
below:
Class Name : Convert
Data member/instance variables : n – integer whose digits are to be expressed in words
Member functions/methods:
Page 4 of 12
Convert() : constructor to assign initial value to the data members
void inpnum() : to accept the value of n
void extdigit(int) : to extract the digits of n using the recursive technique
void numtowords(int) : to display the digits of an integer n in words

Question 18
A class Revstr defines a recursive function to reverse a string and check whether it is a Palindrome. The
details of the class are given below:
Class Name : Revstr
Data member/instance variables:
str : stores the string
revst : stores the reverse of the string
Member functions/methods:
void getstr() : to accept the string
void recReverse(int) : to reverse the string using the recursive technique
void check() : to display the original string, its reverse and whether the string is a Palindrome
or not

Question 19
Design a class Change to perform string related operations. The details of the class are given below:
Class Name : Change
Data member/instance variables:
str : stores the word
newstr : stores the changed word
len : store the length of the word
Member functions/methods:
Change() : default constructor
void getdata() : to accept a word
char caseconvert(char): converts the case of the character and returns it
void rechange(int) : extracts character using the recursive technique
void display() : to display both the words

Question 20
A class Hifact has been defined to find the HCF of two numbers. This HCF is used to find the LCM of the
two numbers. The details of the class are given below:
Class Name : Hifact
Data member/instance variables : a, b, hcf, lcm
Member functions/methods:
Hifact() : constructor to assign initial value to the data members
void getdata() : to accept the values of a and b
void change() : to swap a and b if a > b
int rechef(int, int) : to find hcf using the recursive technique
int fn_lcm(int,int,int) : to find lcm using a, b and hcf
void result() : to display the lcm and hcf od the two numbers

Question 21
A Happy number is a number in which the eventual sum of the square of the digits of the number is equal to
1.
Example: 28 = 22 + 82 = 4 + 64 = 68
68 = 62 + 82 = 36 + 64 = 100
100 = 12 + 02 + 02 = 1 + 0 + 0 = 1
Hence 28 is a Happy number
Example: 12 = 12 + 22 = 1 + 4 = 5
Hence 12 is not a happy number

Page 5 of 12
Design a class Happy to check if a given number is a happy number. The details of the class are given
below:
Class Name : Happy
Data member/instance variables : n – store the number
Member functions/methods:
Happy() : constructor to assign initial value to the data members
void getdata() : to accept the value of n
int sumdigits(int) : return the sum of the square of the digits of the number using the recursive
technique
void isHappy() : checks if the given number is a Happy number by calling the functions and
displays an appropriate message.

Question 22
An Emirp number is a number which is prime backwards and forwards. Example: 13 and 31 are both prime
numbers. Thus, 13 is an emirp number.
Class Name : Emirp
Data member/instance variables:
n : stores the number
rev : stores the reverse of the number
f : stores the divisor
Member functions/methods:
Emirp(int nn) : to assign n=nn, rev = 0 and f = 2
int isprime(int x) : check if the number is prime using the recursive technique and return 1 if
prime otherwise return 0
void isEmirp() : reverse the given number and check if both the original number and the
reverse number are prime, by invoking the function isprime(int) and display the result with an appropriate
message.

Question 23
A class Series1 has been defined to compute the sum of the following series:
𝑥2 𝑥4 𝑥6 𝑥8 𝑥𝑛
+ + + + . . . . . . . . . . . . . . . . + (𝑛−1)!
1! 3! 5! 7!
Some of the members and functions of the class series are:
Class Name : Series1
Data member/instance variables:
int x : to store the value of x
int n : to store the limit of the series
double sum : to store the sum of the series
Member functions/methods:
Series1(int xx,int nn) : constructor to initialize variables
double findfact(int m) : to return the factorial of m using recursive technique
double power(int x,int y) : to return the x raised to the power of y using recursive technique
void calculate() : to calculate the sum of the series by invoking the recursive functions
respectively
void display() : displays the sum of the series

Question 24
A class Series2 has been defined to compute the sum of the following series:
1 1+1 1+1+2 1+1+2+3 1+1+2+3+5 1+1+2+3+5+8+.....
+ 22 + 23 + 24 + + .......+
21 25 2𝑛
Some of the members and functions of the class series are:
Class Name : Series2
Data member/instance variables:
int n : to store the limit of the series
double sum : to store the sum of the series
Member functions/methods:
Page 6 of 12
Series2() : constructor to initialize variables
long fib(long x) : returns the sum of the Fibonacci series up to x terms
long power(long x) : return the value of 2x i.e. 2 raised to the power of x using recursive technique
void sumseries() : calculates and prints the sum of the given series

Question 25
A class Series3 has been defined to compute the sum of the following series:
1! 2! 3! 4! 5! 𝑛!
2
− 3
+ 4
− 5
+ 6
− . . . . . . . . . . − 𝑛+1
𝑥 𝑥 𝑥 𝑥 𝑥 𝑥
Some of the members and functions of the class series are:
Class Name : Series3
Data member/instance variables:
int x : to store the value of x
int n : to store the limit of the series
double sum : to store the sum of the series
Member functions/methods:
Series3() : constructor to initialize variables
void input() : accepts values of x and n
long fact(long n) : calculate and returns n! using recursive technique
long power(int a,int b): return the value of ab i.e. a raised to the power of b using recursive technique
double term(int p,intq): returns the value of a fact()/power() function
double calsum() : calculates the sum of the given series
void display() : displays the sum of the series

Question 26
Write a program UpperHalf which takes a 2D array A, with size N rows and N columns as argument and
point the upper half of the array.
Example:
Input: Output:
23150 23150
71531 1531
25781 781
01501 01
34915 5

Question 27
Design a class Alpha which enables a word to be arranged in ascending order according to its 10 alphabets.
The details of the members of the class are given below.
Class Name : Alpha
Data member/instance variables : str – to store a word
Member functions/methods:
Alpha() : default constructor
void readword() : to accept the inputted word
void arrange() : to arrange the word in alphabetical order using any standard sorted technique
void display() : displays the word

Question 28
Design a class SaddlePoint to input a 2D matrix and find its saddle point. A saddle point is an element of
the matrix such that it is the minimum element in its row and maximum in its column.
Example:
Input: 1 2 3 Output: 7
456 7 is minimum in its row and maximum in its column.
789

Page 7 of 12
Question 29
Design a class SpiralMatrix to input a 2D matrix and print the inputted matrix in spiral form.
Examples:
Input: Input:
1 2 3 4 1 2 3 4 5 6
5 6 7 8 7 8 9 10 11 12
9 10 11 12 13 14 15 16 17 18
13 14 15 16
Output: Output:
1 2 3 4 8 12 16 15 14 13 9 5 6 7 11 10 1 2 3 4 5 6 12 18 17 16 15 14 13 7 8 9 10 11

Question 30
Design a class CircularMatrix to input the row and column size of a matrix and print the matrix
simultaneously in a circular way (clockwise) with natural numbers from 1 to m*n.
Examples:
Input: m = 4, n = 4 Input: m = 3, n = 4
Output: 1 2 3 4 Output: 1 2 3 4
12 13 14 5 10 11 12 5
11 16 15 6 9876
10 9 8 7

Question 31
Design a class CircularPrime to input a number and check whether the number is circular prime or not.
A prime number is said to be a circular prime if after any cyclic permutations of the digits, it remains a
prime.
Examples:
Input : n = 113
Output : Yes Input : 1193
All cyclic permutations of 113 (311 Output : Yes
and 131) are prime.

Question 32
A wondrous square is an n by n grid which fulfills the following conditions:
(i) It contains integers from 1 to n2, where each integer appears only once
(ii) The sum of integers in any row or column must add up to 0.5*n*(n2+1)
For example the following gird is a wondrous square where the sum of each row or column is 65 when n=5:
17 24 2 8 15
23 5 7 14 16
4 6 13 20 22
10 12 19 21 3
11 18 25 2 9
Write a program to read n (2<=n<=10) and the values stored in these n by n cells and output if the grid
represents a wondrous square or not.
Also output all the prime numbers in the grid along with their row index and column index as shown in the
output. A natural numbers is said to be prime if it has exactly two divisors. E.g. 2, 3, 5, 7, 11……
The first element of the given gird i.e. 17 is stored at row index 0 and column index 0 and the next element
in the row i.e. 24 is stored at row index 0 and column index 1. Test your program for the following data and
some random data.
Example:
Input: N = 4
16 15 1 2
6 4 10 14
9 8 12 5
3 7 11 13
Output: Yes it represents a wondrous square
Page 8 of 12
Prime Row index Column index
2 0 3
3 3 0
5 2 3
7 3 1
11 3 2
13 3 3

Input: N = 3
1 2 4
3 7 5
8 9 6
Output: Not a wondrous square
Prime Row index Column index
2 0 1
3 1 0
5 1 2
7 1 1

Question 33
Given a square matrix list[][] of order ‘n’. the maximum value possible for ‘n’ is 20. Input the value for ‘n’
and the positive integers in the matrix and perform the following tasks:
a) Display the original matrix
b) Print the row and column position of the largest element of the matrix
c) Print the row and column position of the second largest element of the matrix
d) Sort the elements of the rows in the ascending order and display the new matrix
Example:
Input: N = 3
5 1 3
7 4 6
9 8 2
Output:
5 1 3
7 4 6
9 8 2
The largest element 9 is in row 3 and column 1
The second largest element 8 is in row 3 and column 2

Question 34
Write a program to declare a matrix A [] [] of order (m*n) where ‘m’ is the number of rows and ‘n’ is the
number of columns such that both m and n must be greater than 2 and less than 20. Allow the user to input
positive integers into this matrix. Perform the following tasks on the matrix:
a) Sort the elements of the outer row and column elements in ascending order using any standard
sorting technique
b) Calculate the sum of the outer row and column elements
c) Output the original matrix, rearranged matrix and only the boundary elements of the rearranged array
with their sum.
Example:
Input: M = 3 N = 3
1 7 4
8 2 5
6 3 9
Output:
Original Matrix:
1 7 4
Page 9 of 12
8 2 5
6 3 9

Rearranged Matrix:
1 3 4
9 2 5
8 7 6

Boundary Elements:
1 3 4
9 5
8 7 6

Sum of the outer row and column elements: 43

Question 35
Write a program to declare a matrix A [] [] of order (m*n) where ‘m’ is the number of rows and ‘n’ is the
number of columns such that both m and n must be greater than 2 and less than 20. Accept the values of m
and n. check for its validity and display an appropriate message, if invalid.
Accept positive integers into this matrix from the user. Sort the elements of each column of the array in
descending order using any standard sorting technique. Output the original and sorted matrix.
Example:
Input: M = 3 N = 3
1 7 4
8 2 5
6 3 9
Output:
Original Matrix:
1 7 4
8 2 5
6 3 9
Sorted Matrix:
8 7 9
6 3 5
1 2 4

Question 36
Write a program to declare a matrix A [] [] of order (m*n) where ‘m’ is the number of rows and ‘n’ is the
number of columns such that both m and n must be greater than 2 and less than 20. Allow the user to input
integers into this matrix. Perform the following tasks on the matrix:
a) Display the input matrix
b) Find the maximum and minimum value in the matrix and display them along with their position
c) Sort the elements of the matrix in ascending order using any standard sorting technique and
rearrange them in matrix
d) Output the rearranged matrix
Example:
Input: M = 3 N = 4
8 7 9 3
-2 0 4 5
1 3 6 -4
Output:
Original Matrix:
8 7 9 3
-2 0 4 5
1 3 6 -4
Page 10 of 12
Largest Number: 9 Row = 0 Column = 2
Smallest Number: -4 Row = 2 Column = 3
Rearranged Matrix:
-4 -2 0 1
3 3 4 4
6 7 8 9

Question 37
Write a program to declare a square matrix A [] [] of order (m*n) where ‘m’ is the number of rows and ‘n’ is
the number of columns such that both m and n must be greater than 2 and less than 20. Allow the user to
input positive integers into this matrix. Display appropriate error message for an invalid input. Perform the
following tasks on the matrix:
a) Display the input matrix
b) Create a mirror image of the inputted matrix
c) Display the mirror image matrix
Example:
Input: M = 3
4 16 12
8 2 14
6 1 3
Output:
Original Matrix:
4 16 12
8 2 14
6 1 3

Mirror Image Matrix:


12 16 4
14 1 8
3 1 6

Question 38
Write a program to declare a square matrix A [] [] of order (m*n) where ‘m’ is the number of rows and ‘n’ is
the number of columns such that both m and n must be greater than 2 and less than 10. Accept the value of
m as user input. Display an appropriate message for an invalid input. Allow the user to input integers into
this matrix. Perform the following tasks:
a) Display the original matrix
b) Check if the given matrix is symmetric or not.
A square matrix is said to be Symmetric, if the element of the ith row and jth column is equal to the element
of the jth row and ith column. Find the sum of the elements of left diagonal and the sum of the elements of
right diagonal of the matrix and display them.
Example:
Input: M = 3
1 2 3
2 4 5
3 5 6
Output:
Original Matrix:
1 2 3
2 4 5
3 5 6
THE GIVEN MATRIX IS SYMMETRIC
The sum of the left diagonal = 11
The sum of the right diagonal = 10

Page 11 of 12
Question 39
Write a program to declare a square matrix A [] [] of order (m*n) where ‘m’ is the number of rows and ‘n’ is
the number of columns such that both m and n must be greater than 2 and less than 20. Allow the user to
input positive integers into this matrix. Display appropriate error message for an invalid input. Perform the
following tasks on the matrix:
a) Display the input matrix
b) Rotate the matrix 90o clockwise as shown below:
Original Matrix: Rotated Matrix:
1 2 3 7 4 1
4 5 6 8 5 2
7 8 9 9 6 3
c) Find the sum of the elements of the four corners of the matrix
Example:
Input: M = 3
3 4 9
2 5 8
1 6 7
Output:
Original Matrix:
3 4 9
2 5 8
1 6 7
Matrix After Rotation:
1 2 3
6 5 4
7 8 9
Sum of the corner elements = 20

Question 40
Consider the sequence of natural numbers.
1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25 ………………….

Removing every second number produces the sequences


1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 23 ………………………….

Removing every third number produces the sequences


1, 3, 7, 9, 13, 15, 19, 21, 25 ………………………….

This process continues indefinitely by removing the fourth, fifth…and so on, till after a fixed number of
steps, certain natural numbers remain indefinitely. These are known as Lucky Numbers.

Write a program to generate and print lucky numbers less than a given number N.
SAMPLE INPUT: N = 10
OUTPUT: The Lucky numbers less than 10 are: 1 3 7

SAMPLE INPUT: N = 25
OUTPUT: The Lucky numbers less than 25 are: 1 3 7 13 19

Page 12 of 12

You might also like