Q 1:
The Caesar cipher is a type of substitution cipher in which each alphabet in the plaintext
or messages is shifted by a number of places down the alphabet.
For example,with a shift of 1, P would be replaced by Q, Q would become R, and so on.
To pass an encrypted message from one person to another, it is first necessary that
both parties have the ‘Key’ for the cipher, so that the sender may encrypt and the
receiver may decrypt it.
Key is the number of OFFSET to shift the cipher alphabet. Key can have basic shifts from
1 to 25 positions as there are 26 total alphabets.
As we are designing custom Caesar Cipher, in addition to alphabets, we are considering
numeric digits from 0 to 9. Digits can also be shifted by key places.
For Example, if a given plain text contains any digit with values 5 and keyy =2, then 5
will be replaced by 7, “-”(minus sign) will remain as it is. Key value less than 0 should
result into “INVALID INPUT”
Example 1:
Enter your PlainText: All the best
Enter the Key: 1
The encrypted Text is: Bmm uif Cftu
Write a function CustomCaesarCipher(int key, String message) which will accept
plaintext and key as input parameters and returns its cipher text as output.
Q2.
We want to estimate the cost of painting a property. Interior wall painting
cost is Rs.18 per [Link]. and exterior wall painting cost is Rs.12 per [Link].
Take input as
1. Number of Interior walls
2. Number of Exterior walls
3. Surface Area of each Interior 4. Wall in units of square feet
Surface Area of each Exterior Wall in units of square feet
If a user enters zero as the number of walls then skip Surface area values as
User may don’t want to paint that wall.
Calculate and display the total cost of painting the property
Example 1:
6
3
12.3
15.2
12.3
15.2
12.3
15.2
10.10
10.10
10.00
Total estimated Cost : 1847.4 INR
Note: Follow in input and output format as given in above example
Q3.
A City Bus is a Ring Route Bus which runs in circular [Link] is, Bus once starts at
the Source Bus Stop, halts at each Bus Stop in its Route and at the end it reaches the
Source Bus Stop again.
If there are n number of Stops and if the bus starts at Bus Stop 1, then after nth Bus
Stop, the next stop in the Route will be Bus Stop number 1 always.
If there are n stops, there will be n [Link] path connects two stops. Distances (in
meters) for all paths in Ring Route is given in array Path[] as given below:
Path = [800, 600, 750, 900, 1400, 1200, 1100, 1500]
Fare is determined based on the distance covered from source to destination stop as
Distance between Input Source and Destination Stops can be measured by looking at
values in array Path[] and fare can be calculated as per following criteria:
If d =1000 metres, then fare=5 INR
(When calculating fare for others, the calculated fare containing any fraction
value should be ceiled. For example, for distance 900n when fare initially
calculated is 4.5 which must be ceiled to 5)
Path is circular in function. Value at each index indicates distance till current stop from
the previous one. And each index position can be mapped with values at same index in
BusStops [] array, which is a string array holding abbreviation of names for all stops as-
“THANERAILWAYSTN” = ”TH”, “GAONDEVI” = “GA”, “ICEFACTROY” = “IC”,
“HARINIWASCIRCLE” = “HA”, “TEENHATHNAKA” = “TE”, “LUISWADI” = “LU”,
“NITINCOMPANYJUNCTION” = “NI”, “CADBURRYJUNCTION” = “CA”
Given, n=8, where n is number of total BusStops.
BusStops = [ “TH”, ”GA”, ”IC”, ”HA”, ”TE”, ”LU”, ”NI”,”CA” ]
Write a code with function getFare(String Source, String Destination) which take Input
as source and destination stops(in the format containing first two characters of the
Name of the Bus Stop) and calculate and return travel fare.
Example 1:
Input Values
ca
Ca
Output Values
INVALID OUTPUT
Example 2:
Input Values
NI
HA
Output Values
23.0 INR
Note: Input and Output should be in format given in example.
Input should not be case sensitive and output should be in the format INR
Q4.
FULLY AUTOMATIC VENDING MACHINE – dispenses your cuppa on just press of
button. A vending machine can serve range of products as follows:
Coffee
1. Espresso Coffee
2. Cappuccino Coffee
3. Latte Coffee
Tea
1. Plain Tea
2. Assam Tea
3. Ginger Tea
4. Cardamom Tea
5. Masala Tea
6. Lemon Tea
7. Green Tea
8. Organic Darjeeling Tea
Soups
1. Hot and Sour Soup
2. Veg Corn Soup
3. Tomato Soup
4. Spicy Tomato Soup
Beverages
1. Hot Chocolate Drink
2. Badam Drink
3. Badam-Pista Drink
Write a program to take input for main menu & sub menu and display the
name of sub menu selected in the following format (enter the first letter to
select main menu):
Welcome to CCD
Enjoy your
Example 1:
Input:
c
1
Output
Welcome to CCD!
Enjoy your Espresso Coffee!
Example 2:
Input:
t
9
Output
INVALID INPUT