TCS NQT - Coding Ability

Test Number 5


1 .Problem Statement

FULLY AUTOMATIC VENDING MACHINE – dispenses your cuppa on just press of button. A vending machine can serve range of products as follows:

Coffee

Espresso Coffee
Cappuccino Coffee
Latte Coffee
Tea

Plain Tea
Assam Tea
Ginger Tea
Cardamom Tea
Masala Tea
Lemon Tea
Green Tea
Organic Darjeeling Tea
Soups

Hot and Sour Soup
Veg Corn Soup
Tomato Soup
Spicy Tomato Soup
Beverages

Hot Chocolate Drink
Badam Drink
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 OUTPUT!

#include <stdio.h>
int main()
{

char c[3][20]={"Espresso Coffee","Cappuccino Coffee","Latte Coffee"};

char t[8][30]={"Plain Tea","Assam Tea","Ginger Tea","Cardamom Tea","Masala Tea","Lemon Tea","Green Tea","Organic Darjeeling Tea"};

char s[4][20]={"Hot and Sour Soup","Veg Corn Soup","Tomato Soup","Spicy Tomato Soup"};

char b[3][20]={"Hot Chocolate Drink","Badam Drink","Badam-Pista Drink"};

char str[]="Welcome to CCD!\nEnjoy your ";

char ch;

int item, i;

scanf("%c",&ch);

scanf("%d",&item);

if(ch=='c')

{

for(i=0; i<3; i++)

{

if(item==i+1)

{

printf("Welcome to CCD!\nEnjoy your %s!",c[i]);

break;

}

}

if(i==3)

{

printf("INVALID OPTION!");

}

}

else if(ch=='t')

{

for(i=0; i<8; i++)

{

if(item==i+1)

{

printf("Welcome to CCD!\nEnjoy your %s!",t[i]);

break;

}

}

if(i==8)

{

printf("INVALID OPTION!");

}

}

else if(ch=='s')

{

for(i=0; i<4; i++)

{

if(item==i+1)

{

printf("Welcome to CCD!\nEnjoy your %s!",s[i]);

break;

}

}

if(i==4)

{

printf("INVALID OPTION!");

}

}

else if(ch=='b')

{

for(i=0; i<3; i++)

{

if(item==i+1)

{

printf("Welcome to CCD!\nEnjoy your %s!",b[i]);

break;

}

}

if(i==3)

{

printf("INVALID OPTION!");

}

}

else

{

printf("INVALID INPUT!");

}

return 0;

}

   

menu = [['Espresso Coffee','Cappuucino Coffee','Latte Coffee'], ['Plain Tea',

'Assam Tea','Ginger Tea','Cardamom Tea','Masala Tea','Lemon Tea','Green Tea',

'Organic Darjeeling Tea'], ['Hot and Sour Soup','Veg Corn Soup','Tomato Soup',

'Spicy Tomato Soup'], ['Hot Chocolate Drink', 'Badam Drink',

'Badam-Pista Drink']]

m = input()

if m=='c' or m=='t' or m=='s' or m=='b':

if m=='c':

submenu = int(input())

if submenu in range(3):

print('Welcome to CCD!\nEnjoy your {}!'.format(menu[0][submenu-1]))

else:

print("INVALID INPUT")

if m=='t':

submenu = int(input())

if submenu in range(8):

print('Welcome to CCD!\nEnjoy your {}!'.format(menu[1][submenu-1]))

else:

print("INVALID INPUT")

if m=='s':

submenu = int(input())

if submenu in range(4):

print('Welcome to CCD!\nEnjoy your {}!'.format(menu[2][submenu-1]))

else:

print("INVALID INPUT")

if m=='b':

submenu = int(input())

if submenu in range(3):

print('Welcome to CCD!\nEnjoy your {}!'.format(menu[3][submenu-1]))

else:

print("INVALID INPUT")

else:

print("INVALID INPUT!")





";

2.Problem Statement

A doctor has a clinic where he serves his patients. The doctor’s consultation fees are different for different groups of patients depending on their age. If the patient’s age is below 17, fees is 200 INR. If the patient’s age is between 17 and 40, fees is 400 INR. If patient’s age is above 40, fees is 300 INR. Write a code to calculate earnings in a day for which one array/List of values representing age of patients visited on that day is passed as input.

Note:

Age should not be zero or less than zero or above 120
Doctor consults a maximum of 20 patients a day
Enter age value (press Enter without a value to stop):
Example 1:

Input
20
30
40
50
2
3
14

Output
Total Income 2000 INR

Note: Input and Output Format should be same as given in the above example.
For any wrong input display INVALID INPUT

Output Format

Total Income <Integer> INR

age = []

for i in range(20):

m = input()

if m == "":

break

elif int(m) in range(0,120):

age.append(int(m))

else:

print("INVALID INPUT")

exit()

fees = 0

for i in age:

if i < 17:

fees+=200

elif i <40:

fees+=400

else:

fees+=300

print("Total Income {} INR".format(fees))