Programing Logic
//Q1.
public class Main
{
public static void main(String arge[])
{
System.out.println("ab\raba\r");
}
}
Question 1
Answer
Question 1
Q1. What will be the output of the following program?
Answer
ab
aba
TCS NQT MOCK TEST / PRACTICE AET
Click Here!
Question 2
Answer
Question 2
Q2. __________ function is used to show a key pressed by a user will appear on the screen.
A. getche()
B. getsf()
C. gfets()
D. getch()
Answer
Option A
Question 3
Answer
Question 3
Q3. When we implement stack by using linked list then:
A. insertion of node is done from beginning and deletion from beginning
B. insertion of node is done from end & deletion from end
C. insertion of node is done from end & deletion from beginning
D. insertion of node is done from beginning and deletion from end
Answer
Option A
Both A and B can be correct. If insertion and deletion happens at the same end it is stack and if it happens at different ends it is Queue. Here the best among A and B is Option A
Question 4
Answer
Question 4
Q4. The primary mission of an analyst or systems designer is to:
A. calculate the Return on Investment
B. development of Software Evaluation Tool
C. create a Data Flow Diagram
D. extract the physical requirements of the users and convert them to software
Answer
Option C
Question 5
Answer
Question 5
Q5. _______ is a process to identify the key aspects of an entity and hiding the rest.
A. Encapsulation
B. Inheritance
C. Abstraction
D. Polymorphism
Answer
Option B
Question 6
Answer
Question 6
Q6. Among the following loops which is a post tested loop?
A. while
B. do-while
C. for
D. If
Answer
Option B
Question 7
Answer
Question 7
Q7. Which one is not a type of topology?
A. Star-topology
B. Circuit-topology
C. Ring-topology
D. Bus-topology
Answer
Option B
//Q8.
struct emp{
int emp_id;
struct temp *next;
};
struct temp *head,*temp;
temp = head;
while(temp->next!= NULL){
printf("%d", temp -> emp_id);
temp = temp -> next;
}
Question 8
Answer
Question 8
Q8. Assume: Linked list as head -> 2 -> 4 -> 6 -> 8
What will be the output of the given program?
A. 2460
B. 2468
C. 246
D. 246NULL
Answer
Option C
TCS NQT MOCK TEST / PRACTICE AET
Click Here!
//Q9.
class Main{
private int SUM;
public static void main(String args[])
{
Main main = new Main();
}
public void Main(int a, int b){
a = 10;
b = 10;
SUM = a + b;
System.out.println(SUM);
}
}
Question 9
Answer
Question 9
Q9. Predict the output.
A. No output
B. 20
C. 0
D. Compilation Error
Answer
Option D
//Q10.
#include<stdio.h>
void main(){
int count = 11;
for(int i;i <= count; i++){
pritnf("Time Complexity!!");
}
}
Question 10
Answer
Question 10
Q10. What would be the Time Complexity of below Code? Type your answer:
Answer
Answer:
O(11) or O(count)
Coding
Question 1
Question 1
Q1. There are a total number of Monkeys sitting on the branches of a huge Tree. As travelers
offer Bananas and Peanuts, the Monkeys jump down the Tree. If every Monkey can eat k
Bananas and j Peanuts. If Total m number of Bananas and p number of Peanuts offered by
Travelers, calculate how many Monkeys remain on the Tree after some of them jumped down
to eat.
At a time, one Monkey gets down and finishes eating and goes to the other side of the road.
The Monkey who climbed down does not climb up again after eating until the other Monkeys
finish eating. Monkeys can either eat k Bananas or j Peanuts. If for the last Monkey there are
less than k Bananas left on the ground or less than j Peanuts left on the ground, only that
Monkey can eat Bananas (<k) along with the Peanuts (<j).
Write the code to take inputs as n, m, p, k, j and return the number of Monkeys left on the
Tree.
Where, n = Total number of Monkeys
k = Number of eatable Bananas by a single Monkey (Monkey that jumped down last may get
less than k Bananas)
j = Number of eatable Peanuts by a single Monkey (Monkey that jumped down last may get less
than Bananas)
m = Total number of Bananas
p = Total number of Peanuts
Remember that the Monkeys always eat Bananas and Peanuts, so there is no possibility of k
and j having a value zero.
Example 1:
Input Values
20
2
3
12
12
Output Values
Number of Monkeys left on the Tree: 10
Note: Kindly follow the order of inputs as n, k, j, m, p as given in above example. And output
must include the same format as in above example(Number of Monkeys left on the
Tree:<Integer>)
For any wrong input display INVALID INPUT
//solution for Q1 in C++
#include <iostream>
using namespace std;
int main() {
int n, k, j, m, p;
cin >> n >> k >> j >> m >> p;
int ans 0;
if(k<0 || n<0 || k<0 || m<0 || p<0)
{
cout << "INVALID INPUT";
return 0;
}
ans = ans + (m/k);
ans = ans + (p/j);
cout << n - ans;
return 0;
}
Question 2
Answer
Question 2
Q2. Chain Marketing Sales Organization has a scheme for income generation through which its
members generate income for themselves. The scheme is such that suppose A joins the scheme
and makes Rand V to join this scheme then A is Parent Member of R and V who are child
Members. When any member joins the scheme then the parent gets a total commission of 10%
from each of its child members.
Child members receive commission of 5% respectively.
If a Parent member does not have any member joined under him, then he/she gets commission
of 5%.
Take the Name of the Members Joining the Scheme as input.
Display how many members joined the scheme including parent members, Calculate the Total
commission gained by each member in the scheme. The fixed amount for joining the scheme is
Rs.5000 on which commission will be generated.
Scherne Amount=5000
Example 1: When there are more than one child members
Input: (Do not give Input Prompts. Accept values as follows.)
Amit //Enter Parent Member Name as this
Y //Enter Y if Parent Member have child members otherwise enter N
Rajesh, Virat //Enter Name of child members of Amit in comma separated
Output: (Final output must be in format given below.)
TOTAL MEMBERS: 3
COMMISSION DETAILS
Amit: 1000 INR
Rajesh: 250 INR
Virat: 250INR
Example 2: When there is only one child member in the hierarchy
Input:
Amit
Y
Rajesh
Output:
TOTAL MEMBERS: 2
COMMISSION DETAILS
Amit: 500 INR
Rajesh: 250 INR
Answer
Option C
//Q2. Solution in C++
#include <bits/stdc++.h>
#define ll long long;
using namespace std;
int main() {
string par;
cin>>par;
string x;
cin >> x;
if(x == "N"){
cout << "TOTAL MEMBERS:1\n";
cout << "COMMISSION DETAILS\n";
cout << par << ":250 INR\n";
}
else{
string child;
cin >> child;
vector<string>v;
string temp = "";
for(int i = 0l i < child.length(); i++){
if(child[i] == ','){
v.push_back(temp);
temp = "";
}
else if(child[i] != ' ')
temp += child[i];
}
v.push_back(temp);
cout << "TOTAL MEMBERS:" << v.size() + 1 << "\n";
cout << "COMMISION DETAILS\n";
cout << par << ":" << v.size()*500 << " INR\n";
for(auto a : v){
cout << a << ":" << "250 INR\n";
}
}
return 0;
}