TCS NQT Fully Automated Vending Machine Coding Problem

Automated Vending Machine TCS NQT Coding Problem Solution

TCS NQT Fully Automated Vending Machine Coding Problem

We at gradjobopenings.com provide free job alerts of freshers job drives. In this website we list on campus job openings for freshers and off campus job openings for freshers and also work from home job openings. This is the best website to apply for off campus drive in India. Visit our website for government job alerts and private job alerts. We also list free interview notes and study materials, one of the best interview study website.comfortable to face the interviews:

Problem Statement

FULLY-AUTOMATIC VENDING MACHINE dispenses your cuppa with just the press of a button. A vending machine can serve a 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 the main menu & sub-menu and display the name of submenu selected in the following format (enter the first letter to select the main menu):

Welcome to CCD

Enjoy your <name of sub menu>

Example 1:

Input

    c

    1

Output

    Welcome to CCD!

    Enjoy your Espresso Coffee!

Example 2:

Input

    t

    9

Output

    INVALID OPTION!

**Algorithm**

1. Declare and initialise main_menu array with the following values:

    {‘C’, ‘T’, ‘S’, ‘R’}

2. Declare and initialise C array with the following values:

    {“Espresso Coffee”, “Cappuccino Coffee”, “Latte Coffee”}

3. Declare and initialise T array with the following values:

    {“Plain Tea”, “Assam Tea”, “Ginger Tea”, “Cardamom Tea”, “Masala Tea”, “Lemon Tea”, “Green Tea”, “Organic Darjeeling Tea”}

4. Declare and initialise S array with the following values:

    {“Hot and Sour Soup”, “Veg Corn Soup”, “Tomato Soup”, “Spicy Tomato Soup”}

5. Declare and initialise R array with the following values:

    {“Hot Chocolate Drink”, “Badam Drink”, “Badam-Pista Drink”}

6. Declare and initialise sub_menu_len array with the following values:

    {3, 8, 4, 3}

7. Read the values of main_menu_choice and sub_menu_choice.

8. Capitalise the main_menu_choice if in lower case.

9. For every item in main_menu, do

    if item == main_menu_choice and sub_menu_len[item] >= sub_menu_choice, do

        Print Welcome to CCD!

        Print Enjoy your ((main)[sub_menu_choice – 1])

        exit

10. Print INVALID CHOICE

Program Solution in C

#include <stdio.h>
#define main_menu_length 4
int main()
{
    char main_menu[] = {'C', 'T', 'S', 'R'}, main;
    int sub_menu_len[] = {3, 8, 4, 3}, sub;
    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 R[4][21] = {"Hot Chocolate Drink", "Badam Drink", "Badam-Pista Drink"};
    scanf("%c%d", &main, &sub);
    main = main < 90 ? main : main - 32;
    for ( int i = 0 ; i < main_menu_length ; i++ )
        if ( main_menu[i] == main && sub_menu_len[i] >= sub )
        {
            switch(main)
            {
                case 'C': printf("Welcome to CCD!\nEnjoy your %s", C[ sub - 1 ]); break;
                case 'T': printf("Welcome to CCD!\nEnjoy your %s", T[ sub - 1 ]); break;
                case 'S': printf("Welcome to CCD!\nEnjoy your %s", S[ sub - 1 ]); break;
                case 'R': printf("Welcome to CCD!\nEnjoy your %s", R[ sub - 1 ]);
            }
            return 0;
        }
    printf("INVALID CHOICE");
}

Program In C++

#include <iostream>
#include <vector>

using std::cin;
using std::cout;
using std::endl;
using std::vector;
using std::string;

int main()
{
	const vector <char> main_menu {'C', 'T', 'S', 'R'};
	char main;
	const vector <string> C {
					"Espresso Coffee", "Cappuccino Coffee", "Latte Coffee"
				};
	const vector <string> T {
					"Plain Tea", "Assam Tea", "Ginger Tea", "Cardamom Tea", "Masala Tea", 
					"Lemon Tea", "Green Tea", "Organic Darjeeling Tea"
				};
	const vector <string> S {
					"Hot and Sour Soup", "Veg Corn Soup", "Tomato Soup", "Spicy Tomato Soup"
				};
	const vector <string> R {
					"Hot Chocolate Drink", "Badam Drink", "Badam-Pista Drink"
				};
	const vector <size_t> sub_menu_len {C.size(), T.size(), S.size(), R.size()};
	size_t sub;
	cin >> main >> sub;
	main = toupper(main);
	for ( size_t i = 0 ; i < main_menu.size() ; i++ )
		if ( main_menu.at(i) == main && sub_menu_len.at(i) >= sub )
		{
			switch(main)
			{
				case 'C': cout << "Welcome to CCD!" << endl << "Enjoy your " << C.at( sub - 1 ); break;
				case 'T': cout << "Welcome to CCD!" << endl << "Enjoy your " << T.at( sub - 1 ); break;
				case 'S': cout << "Welcome to CCD!" << endl << "Enjoy your " << S.at( sub - 1 ); break;
				case 'R': cout << "Welcome to CCD!" << endl << "Enjoy your " << R.at( sub - 1 );
			}
			return 0;
		}
	cout << "INVALID CHOICE";
	return 0;
}

Program in Java

import java.util.Scanner;
class Main
{
    public static void main(String[] args)
    {
        char main_menu[] = {'C', 'T', 'S', 'R'};
        int sub_menu_len[] = {3, 8, 4, 3};
        String C[] = {
            "Espresso Coffee", "Cappuccino Coffee", "Latte Coffee"
        };
        String T[] = {
            "Plain Tea", "Assam Tea", "Ginger Tea", "Cardamom Tea", 
            "Masala Tea", "Lemon Tea", "Green Tea", "Organic Darjeeling Tea"
        };
        String S[] = {
            "Hot and Sour Soup", "Veg Corn Soup", "Tomato Soup", "Spicy Tomato Soup"
        };
        String R[] = {
            "Hot Chocolate Drink", "Badam Drink", "Badam-Pista Drink"
        };
        Scanner in = new Scanner(System.in);
        char main = in.next().toUpperCase().charAt(0);
        int sub = in.nextInt();
        for ( int i = 0 ; i < main_menu.length ; i++ )
        {
            if ( main_menu[i] == main && sub_menu_len[i] >= sub )
            {
                System.out.print("Welcome to CCD!\nEnjoy your ");
                switch(main)
                {
                    case 'C': System.out.print(C[ sub - 1 ]); break;
                    case 'T': System.out.print(T[ sub - 1 ]); break;
                    case 'S': System.out.print(S[ sub - 1 ]); break;
                    case 'R': System.out.print(R[ sub - 1 ]);
                }
                System.exit(0);
            }
        }
        System.out.print("INVALID CHOICE");
    }
}

Program in Python

if __name__ == "__main__":
    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"]
    }
    main = input().upper()
    sub = int(input())
    if len(main) == 1 and main in menu and sub <= len(menu[main]) and sub >= 0:
        print("Welcome to CCD!")
        print("Enjoy your", menu[main][sub-1])
    else:
        print("INVALID OPTION")

FOR MORE TCS NQT CODING QUESTIONS SOLUTION 👉👉👉👉 CLICK HERE

MORE PROGRAMS & SOLUTION 👉👉👉👉 CLICK HERE
LATEST JOB OPENINGS 👉👉👉👉 CLICK HERE
INTERVIEW NOTES & STUDY MATERIALS 👉👉👉👉 CLICK HERE

1 thought on “TCS NQT Fully Automated Vending Machine Coding Problem”

  1. Pingback: TCS NQT CODING QUESTIONS WITH SOLUTIONS - GRAD JOB OPENINGS

Leave a Comment

Your email address will not be published. Required fields are marked *

error: Content is protected !!