Fully Automatic Vending machine
TCS Coding Question Day 3 Slot 1 – Question 1
This is one of the previous year coding question of TCS NQT, which was held in October. The difficulty level of this question ranges from medium to high, so we would suggest that you should go through this question thoroughly
FULLY AUTOMATIC VENDING MACHINE
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!")
Day 2 Slot 2 Question 1
Click on the below button to study Day 2 Slot 2 Question 1 of TCS NQT Coding 2020 exam
TCS Coding Questions
Click on the below button to study more TCS Coding Question
AS EASY AS IT GETS
c = ‘c’
i = 4
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’]]
items = “ctsb”
try:
print(menu[items.index(c)][i-1])
except:
print(“INVALID OUTPUT!”)
………………………..THE FOLLOWING CODE ONLY RUN TEST CASE IN TCS EXAM………………………BY ABHISHEK PATIL
n=str(input())
m=str(input())
if n==”T” and int(m)>=int(“9”):
print(“INVALID OUTPUT!”)
if n==”C” and int(m)>=int(“4”):
print(“INVALID OUTPUT!”)
if n==”S” and int(m)>=int(“5”):
print(“INVALID OUTPUT!”)
if n==”B” and int(m)>=int(“4”):
print(“INVALID OUTPUT!”)
if n==”C” and m==”1″:
print(“Welcome to CCD!\nEnjoy your Espresso Coffee!”)
if n==”C” and m==”2″:
print(“Welcome to CCD!\nEnjoy your Cappuccino Coffee!”)
if n==”C” and m==”3″:
print(“Welcome to CCD!\nEnjoy your Latte Coffee!”)
if n==”T” and m==”1″:
print(“Plain Tea”)
if n==”T” and m==”2″:
print(“Assam Tea”)
if n==”T” and m==”3″:
print(“Ginger Tea”)
if n==”T” and m==”4″:
print(“Cardamom Tea”)
if n==”T” and m==”5″:
print(“Masala Tea”)
if n==”T” and m==”6″:
print(“Lemon Tea”)
if n==”T” and m==”7″:
print(“Green Tea”)
if n==”T” and m==”8″:
print(“Organic Darjeeling Tea”)
if n==”S” and m==”1″:
print(“Hot and Sour Soup”)
if n==”S” and m==”2″:
print(“Veg Corn Soup”)
if n==”S” and m==”3″:
print(“Tomato Soup”)
if n==”S” and m==”4″:
print(“Spicy Tomato Soup”)
if n==”B” and m==”1″:
print(“Hot Chocolate Drink”)
if n==”B” and m==”2″:
print(“Badam Drink”)
if n==”B” and m==”3″:
print(“Badam-Pista Drink”)
a=input()
b=int(input())
dict = {
‘c’: [“Espresso Coffee”,”Cappuccino Coffee”,”Latte Coffee”],
‘t’: [“Plain Tea”,”Assam Tea”,”Ginger Tea”,”Cardamom Tea”,”Masala Tea”,”Lemon Tea”,”Green Tea”,”Organic Darjeeling Tea”],
‘s’: [“Hot and Sour Soup”,”Veg Corn Soup”,”Tomato Soup”,”Spicy Tomato Soup”],
‘b’: [“Hot Chocolate Drink”,”Badam Drink”,”Badam-Pista Drink”]
}
if a==’c’ or a==’t’ or a==’s’ or a==’b’:
if b in range(len(dict[‘c’])):
print(“Welcome to CCD!”)
print(f”Enjoy your {dict[a][b-1]}!”)
else:
print(“INVALID INPUT!”)
else:
print(“INVALID INPUT!”)
#Dictionaries makes it much easier in these types of qs#
menu={“c”:[“Espresso Coffee”,”Cappuccino Coffee”,”Latte Coffee”],”t”:[“Plain Tea”,”Assam Tea”,”Ginger Tea”,”Cardamom Tea”,”Masala Tea”,”Lemon Tea”,
“Green Tea”,”Organic Darjeeling Tea”],”s”:[“Hot and Sour Soup”,”Veg Corn Soup”,”Tomato Soup”,”Spicy Tomato Soup”],”b”:[“Hot Chocolate Drink”,”Badam Drink”,
“Badam-Pista Drink”]}
men=input()
val=int(input())
if men in menu:
for i in menu:
if i==men:
if val in range(len(menu[i])+1):
print(“Welcome to ccd”)
print(“Enjoy your {0}!”.format(menu[i][val-1]))
else:
print(“Invalid input”)
else:
print(“Invalid input”)