Join Regular Classroom : Visit ClassroomTech

TCS NQT Previous Year Solve | Day 2 | Slot 1 (V) | Codewindow.in

TCS NQT

Coding

Question 1:

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

Solution: In c

#include
int main()
{
    int ni,ne,i=0;
    float ip=18,ep=12,fcost=0.0,temp;
    scanf("%d %d",&ni,&ne);
    for(i=0;i<ni;i++)
    {
        scanf("%f",&temp);
        fcost+=ip*temp;
    }
    for(i=0;i<ne;i++)
    {
        scanf("%f",&temp);
        fcost+=ep*temp;
    }
    printf("Total estimated cost : %.1f INR",fcost)
}

Question 2:

A City Bus is a Ring Route Bus which runs in circular fashion. That is, the Bus once started at Source Bus Stop, halts at each Bus Stop in its Route and at the end it reaches to Source Bus stop again. If there are n number of Stops and if bus starts at Bus Stop number 1, then after nth Bus Stop, the next stop in the Route will be Bus Stop number1 always. If there are n stops, there will be n paths. One path connects 2 stops. Distances (in meters) for all paths in Ring Route is given in array Path[] as 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 d 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 meters, then fare= 5 INR – (When calculating fare for other distances, the calculated fare containing any fraction value should be ceiled. For example, for distance 900, when fare initially calculated is 4.5 which must be ceiled to 5) Path is circular in function. Value at each index indicate distance till current stop from previous one. And each index positions 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 Bus Stops. Bus Stops =[“TH”, “GA”, “IC”, “HA”, “TE”, “LU”, “NI”, “CA”). Write a code with function getFare(String Source, String Destination) which takes Input as source and destination stops(in the format containing first 2 characters of Name of the Busstop) and calculate and return travel fare.


Example 1:

Input Values:
ca
Ca

Output Values:

INVALID INPUT

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.

Solution: In Python 3

def face(s,d):
    p=[800,600,750,900,1400,1200,1100,1500]
    stp=['TH','GA','IC','HA','TE','LU','NI','CA']
    sum=0
    r=0
    if(s==d):
        return "INVALID INPUT"
    else:
        s=s.upper()
        d=d.upper()
        mini=min(stp.index(s),stp.index(d))
        maxi=max(stp.index(s),stp.index(d))
        for i in range(mini,maxi+1):
            sum=sum+p[i]
        r=(sum/1000)*5
        r=str(r)
        return r+' INR'
        
s=input()
d=input()
print(face(s,d))

Also Checkout

Recent Posts
Categories
Pages