Message on Whatsapp 8879355057 for DSA(OA + Interview) + Fullstack Dev Training + 1-1 Personalized Mentoring to get 10+LPA Job
0 like 0 dislike
63,989 views
in Service-based-companies by Expert (108,100 points) | 63,989 views

2 Answers

0 like 0 dislike
Best answer

Join https://t.me/Tcsexplores for productive discussions on TCS Xplore and joining in 2021.

Previous year coding questions and solutions :  https://github.com/topics/tcs-xplore 

IPA coding questions of Python : 

(26th Jan)

1st question of 15 marks was : 

Take an integer as input . Calculate the sum of its digit . If the sum is divisible by 3 , then print True , else print False . 

2nd question of 35 marks was :  

Create a class pan . Make attributes id , material , brand , price and capacity . 

Write getters , setters and constructor having argument in same order as above . 

Write the solution class and write main method , implement two static functions namely (costliest pan) and (discounted price) in it. 

Costliest pan function : It accepts 2 arguments , namely the array of pan class objects and material of a pan . It return the costliest pan of the given material . 

Discounted price : It accepts 2 arguments , namely , array of pan objects and brand of pan . 

If capacity of given brand > 500 ml , update price to 20% discount . 

If capacity > 1000 ml , then update price to 26% discount . 

In the main function , take input of variable for 4 class objects . 

Take material as input , then take brand as input for passing to different functions. 

Call the costliest pan function , print the id of the object returned. 

Call the discounted price function , print the new value after updating . 

For solutions to these questions and more details on tcs-nqt/xplore/joining process , join : https://t.me/Tcsexplores 

 

OPA question of Java : 

Code  : 

 

import java.util.Scanner;
public class Solution {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        TravelAgencies[] ta = new TravelAgencies[4];
        for (int i = 0; i < ta.length; i++) {
            int regNo = sc.nextInt();
            sc.nextLine();
            String agencyName = sc.nextLine();
            String packageType = sc.nextLine();
            int price = sc.nextInt();
            boolean flightFacility = sc.nextBoolean();
            ta[i] = new TravelAgencies(regNo, agencyName, packageType, price, flightFacility);
        }

        int getRegNo = sc.nextInt();
        sc.nextLine();
        String getPackageType = sc.nextLine();
        sc.close();

        int highestPackagePrice = findAgencyWithHighestPackagePrice(ta);
        TravelAgencies travelAgencies = agencyDetailsForGivenIdAndType(ta, getRegNo, getPackageType);

        System.out.println(highestPackagePrice);
        if (travelAgencies == null)
            System.out.println("A string value should be printed here!");
        else
            System.out.println(travelAgencies.getAgencyName() + ":" + travelAgencies.getPrice());
    }
    public static int findAgencyWithHighestPackagePrice(TravelAgencies[] agencies) {
        int maxPrice = agencies[0].getPrice();
        for (int i = 1; i < agencies.length; i++) {
            if (agencies[i].getPrice() > maxPrice)
                maxPrice = agencies[i].getPrice();
        }
        return maxPrice;
    }
    public static TravelAgencies agencyDetailsForGivenIdAndType(TravelAgencies[] agencies, int regNo, String packageType) {
        for (int i = 0; i < agencies.length; i++) {
            if (agencies[i].getFlightFacility()) {
                if (agencies[i].getRegNo() == regNo && packageType.equalsIgnoreCase(agencies[i].getPackageType())) {
                    return agencies[i];
                }
            }
        }
        return null;
    }
}

class TravelAgencies {
    int regNo;
    String agencyName;
    String packageType;
    int price;
    boolean flightFacility;
    TravelAgencies(int regNo, String agencyName, String packageType, int price, boolean flightFacility) {
        this.regNo = regNo;
        this.agencyName = agencyName;
        this.packageType = packageType;
        this.price = price;
        this.flightFacility = flightFacility;
    }
    int getRegNo() {
        return regNo;
    }
    String getAgencyName() {
        return agencyName;
    }
    String getPackageType() {
        return packageType;
    }
    int getPrice() {
        return price;
    }
    boolean getFlightFacility() {
        return flightFacility;
    }
}
by Expert (108,100 points)
selected by
0 like 0 dislike

OPA coding question of TCS Xplore : 

(12th Feb) 

Code : 


class Passenger:
    def __init__(self,name,age,distance):
        self.name=name
        self.age=age
        self.distance=distance
        
def Cal_tick_price(pass_list,rate_pkm):
    t_price=0
    for passe in pass_list:
        price=0
        price+=passe.distance*rate_pkm
        tax=0
        if(passe.age>=60 or passe.age<12):
            tax=0
        elif(59>passe.age>21):
            tax=0.12*price
        elif(12>=passe.age>=20):
            tax=0.1*price
        price+=tax
        t_price+=price
    print(t_price)

def Countseniorjunior(pass_list):
    count=0
    for passe in pass_list:
        if(passe.age<12 or passe.age>=60):
            count+=1
    print(count)

    

        
count=int(input())
pass_list=[]
for i in range(count):
    nam=input()
    ag=int(input())
    dist=int(input())
    pass_list.append(Passenger(nam,ag,dist))
rate_per=int(input())

    
Cal_tick_price(pass_list,rate_per)
Countseniorjunior(pass_list)
by Expert (108,100 points)