Q1). Write a program to implement the following logic using inheritance.
Create a parent
class and implement the fun method. In the method, get the individual digits of the entered
number, store it in an array, and find their sum. Create the main class that inherits the parent
class and call the fun method inside the parent function.
Q13). Mukesh and his friends have set out on a vacation to Coorg. They have booked
accommodation in a resort and the resort authorities organize Campfires every night as a
part of their daily activities. Mukesh volunteered himself for an activity called the "Adjacent
Stick Game" where sticks of different lengths will be placed in a line and Mukesh needs to
remove a stick from each adjacent pair of sticks. He then has to form a bigger stick by
combining all the remaining sticks.
Mukesh needs to know the smallest length of the bigger stick so formed and needs your help
to compute the same. Given the number of sticks N and the lengths of each of the sticks,
write a program to find the smallest length of the bigger stick that is formed.
Q2). Write a program to implement function overloading.
Ram is given two or three inputs as an integer, if he has two integers then add the two
numbers. If he has three inputs, then multiply the three numbers.
Function Header:
public void fun1(int a,int b,int c)
public void fun1(int a,int b)
Q14). An array is filled with one of the values 1, 2, or 3.
Find the value that occurs the most in the array.
If two or more values occur the most number of times print the lower value.
Q3.Write a program to find that whether the given number(x) is even or odd if it is even then
print the cube(x)+square(x) else print cube(x)-square(x).
Create a base class with a virtual function void print(). print the result by implementing this
virtual function in the derived class.
Q15). The Pan Am 73 flight from Bombay to New York en route to Karachi and Frankfurt
was hijacked by a few Palestinian terrorists at the Karachi International Airport. The senior
flight purser Neerja Banhot withered her fear and helped evacuate the passengers on board.
Neerja very well knew that she would not be able to evacuate all passengers dodging the
hijackers. So she wanted to hand over the responsibility of evacuating the senior
citizens(above 60 years of age) and children(below 18 years of age) in the flight to the mid-
aged passengers seated in the diagonals
Given n the number of rows of seats and the number of seats in a row and the ages of
passengers in each seat can you find the number of mid-aged passengers seated in the
diagonals.
Q4) You have to enter four letters for each uppercase letter you will get 10 marks and for
each lowercase letter, you will get -5 marks.
Write a program to calculate the total score.
Create a base class with a virtual method void game(). Define this method in the Derived
class and calculate the total score.
Q16).Nurikabe logical game (sometimes called Islands in the Stream) is a binary
determination puzzle. The puzzle is played on a typically rectangular grid of cells, some of
which contain numbers. You must decide for each cell if it is white or black (by clicking on
them) according to the following rules:
• All of the black cells must be connected.
• Each numbered cell must be part of a white island of connected white cells.
• Each island must have the same number of white cells as the number it contains
(including the numbered cell).
• Two islands may not be connected.
• There cannot be any 2x2 blocks of black cells.
Unnumbered cells start out grey and cycle through white and black when clicked. Initially
numbered cells are white in color.
Problem Statement:
Write a program to find the number of white cells in the final configuration of the board, given
a valid initial configuration. Below figure is the sample valid initial configuration.
Q5). Write a Program to calculate the current bill.
Create a class currentBill with a virtual method double amount().
Create a Fan
Create a class Fan that extends currentBill with watts and hours as its public attributes and
overrides the virtual function.
Create a class Light that extends currentBill with watts and hours as its public attributes and
overrides the virtual function.
Create a class TV that extends currentBill with watts and hours as its public attributes and
overrides the virtual function.
In the main method, prompt the user to enter the power rate of the appliance and the total
hours used then create the necessary objects and call the methods.
Q17).It is IPL season and the first league match of Dhilip’s favorite team, "Chennai Super
Kings". The CSK team is playing at the IPL after 2 years and like all Dhoni lovers, Dhilip is
also eagerly awaiting to see Dhoni back in action.
After waiting in long queues, Dhilip succeeded in getting the tickets for the big match. On the
ticket, there is a letter code that can be represented as a string of upper-case Latin letters.
Dhilip believes that the CSK Team will win the match in case exactly two different letters in
the code alternate. Otherwise, he believes that the team might lose. Please see the note
section for the formal definition of alternating code. You are given a ticket code. Please
determine, whether CSK Team will win the match or not based on Dhilip’sconviction. Print
"YES" or "NO" (without quotes) corresponding to the situation.
Note: Two letters x, y where x != y are said to be alternating in a code if the code is of the
form "xyxyxy...".
Q6).You are required to compute the power of a number by implementing a calculator.
Create a class MyCalculator which consists of a single method long power(int, int). This
method takes two integers, n and p, as parameters and finds np. If either n or p is negative,
then the method must throw an Exception that says "n and p should be non-negative". Also,
if both n and p are zero, then the method must throw an Exception that says “ n and p
should not be zero”. Complete the function power in class MyCalculator and return the
appropriate result after the power operation or an appropriate exception as detailed above.
Q18.)Sunil is a little scientist. Sunil has planned to design a wildcard pattern matcher to
exhibit at the "Young Inventors", a tech talent show organized at his school.
Sunil wanted to design the wildcard pattern matcher supporting the wildcard character '?'.
The wildcard character '?' can be substituted by any single lower case English letter for
matching. He has two strings X and Y of equal length, made up of lower case letters and the
character '?'.
Sunil wants your help in designing the device, to know whether the strings X and Y can be
matched or not. Write a program to check whether the given strings can be matched or not.
Note : Print 'No' if the length of strings are not equal.
Q7). Write a program to get two time periods which are stored using structure and write it to
file. Read them from file to compute the difference between them.
Q19).Write a program to sort a set of strings using pointers.
Q8).Create an array of size n and add elements to it. Get a position and a value and modify
the same.
If the position exceeds the size of the array, throw and catch an exception, and print "Index
out of bounds".
Q20).The much-awaited event in the entertainment industry every year is the "Screen
Awards". This year the event is going to be organized on December 25 to honor the Artists
for their professional excellence in Cinema. The Organizers of the event, J&R Events,
decided to design the logo of the Screen Awards as a digitized image and display it on the
LED panel boards for the show promotions all across the venue. The Event team wanted to
border the logo with right triangles which will describe it better.
For this purpose, the Event development team is in the task to find if N dots can make a right
triangle or not (all N dots must be used). Given N dots, we can make it look like a Right
Triangle (45-45-90 triangle) exactly with N dots. Rearrange the given N dots, like this:
Your task is to help the team write a program using functions to find if N dots can make a
right triangle or not.
Function Specifications:
Use the function name, return type, and the argument type as:
int find(int)
The function must return 1 if you can make a right triangle using N dots, else return 0.
Note: The main function is already provided and well defined. The function mentioned above
is to be defined by you to solve this problem
Q9). Using the sort algorithm of STL, write a program that sorts a user-defined character
array in ascending order.
Q21).The simple measure of body fitness is the BMI or Body Mass Index. It depends only on
the height L and weight W of a person. It is defined as BMI = [weight / height^2] where
weight is taken in kilograms and length in meters. Four general grades are proposed:
Underweight[U] - when BMI < 18.5
Normal weight[N] - 18.5
Heavyweight [H] - 25.0
Overweight [O] - above or equal to 30.
Write a program that takes in the Weight (in Kg) and Length (in meters) of an individual and
displays the grade as U, N, H, O.
Note: Bind the data members and the member functions inside the class
Q9).Using the sort algorithm of STL, write a program that sorts a user-defined character
array in ascending order.
Q22). Create a structure student with the following members
Roll Number
Five subject marks
Average
Grade
Given the five subject marks, Calculate the average and grade.
GRADE CALCULATION:
1)if avg>70 the grade will be 1
2)if avg 50 to 70 the grade will be 2
3)if avg is below 50 the grade will be 3 (Note: rn- Roll Number, s-Subjects, avg- Average)
Q11). Fibonacci series starts from 0,1 and the next number should be the sum of the
previous two numbers.
• 0+1=1, so the next number in the Fibonacci series in the c program is 1.
• 0 1 1 2 3 5 8.. and so on.
Write a program to generate Fibonacci series up to n terms using while loop
Q14). An array is filled with one of the values 1, 2, or 3.
Find the value that occurs the most in the array.
If two or more values occur the most number of times print the lower value.
Q12) Write a program to print the following pattern.
7654321
765432
76543
7654
765
76
7
Q24.) Create a structure named DEPT with the following fields: Name, emp-id,
years_of_experience, and Basic salary. Define an array of structures for ‘n’ employees and
check the following constraints and print the results.
- Increase 10% to the salaries of those employees who have worked for 10 years or
more
- Increase 5% to the salaries of those employees who have experienced between 5 to 9
years.
- Increase 2% to the salaries of those employees who have experienced between 1 to 4
years.