TCS NQT PAINTING JOB CODING QUESTION

TCS NQT Painting Job 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:

We want to estimate the cost of painting a property. Interior wall painting cost is Rs.18 per square feet and exterior wall painting cost is Rs.12 per square feet. Take input as:

1. Number of Interior walls

2. Number of Exterior walls

3. Surface Area of each interior wall in units of square feet

4. 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:**

Input

6

3

12.3

15.2

12.3

15.2

12.3

15.2

10.10

10.10

10.00

**Output**

1847.4

Note: Follow in input and output format as given in the above example.

**Algorithm**

“`

1. Read Number of Interior walls

2. Read Number of Exterior walls

3. Initialise cost to 0

3. For each Interior wall, do

    Read surface_area

    cost = cost + surface_area * 18

4. For each Exterior wall, do

    Read surface_area

    cost = cost + surface_area * 12

5. Print cost

Program in C

#include <stdio.h>
int main()
{
    int intr, extr;
    float surface_area, cost = 0;
    scanf("%d%d", &intr, &extr);
    for(int i = 0 ; i < intr ; i++)
    {
        scanf("%f", &surface_area);
        cost += surface_area * 18;
    }
    for(int i = 0 ; i < extr ; i++)
    {
        scanf("%f", &surface_area);
        cost += surface_area * 12;
    }
    printf ("%f", cost);
    return 0;
}

Program in C++

#include <iostream>

using std::cout;
using std::cin;

float calculate_cost ( int no_of_walls, const int cost_per_area )
{
	float cost {0}, surface_area;
	while ( no_of_walls-- )
	{
		cin >> surface_area;
		cost += surface_area * cost_per_area;
	}
	return cost;
}

int main() {
	const int interior_cost {18};
	const int xterior_cost {12};
	int intr, extr;
	cin >> intr >> extr;
	float cost { calculate_cost ( intr, interior_cost ) };
	cost += calculate_cost ( extr, xterior_cost );
	cout << cost;
	return 0;
}

Program in Java

import java.util.Scanner;
class Main
{
    public static void main(String[] args)
    {
        Scanner in = new Scanner(System.in);
        int intr = in.nextInt();
        int extr = in.nextInt();
        float surface_area, cost = 0;
        for(int i = 0 ; i < intr ; i++)
        {
            surface_area = in.nextFloat();
            cost += surface_area * 18;
        }
        for(int i = 0 ; i < extr ; i++)
        {
            surface_area = in.nextFloat();
            cost += surface_area * 12;
        }
        System.out.print(cost);
    }
}

Program in Python

if __name__ == "__main__":
    cost = 0
    intr = int(input())
    extr = int(input())
    while intr:
        surface_area = float(input())
        cost += surface_area * 18;
        intr -= 1
    while extr:
        surface_area = float(input())
        cost += surface_area * 12;
        extr -= 1
    print (cost)

FOR MORE TCS NQT CODING PROBLEMS 👉👉👉👉 CLICK HERE

1 thought on “TCS NQT Painting Job 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 !!