# TCS NQT Chain Marketing Coding Question

TCS NQT Chain Marketing Coding Question

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

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 R and V 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 a commission of 5% respectively. If a Parent member does not have any member joined under him, then he/she gets a 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.

Scheme Amount=5000

Examples

1. When there are more than one child members

– **Input:** (Do not give Input Prompts. Accept values as follows.)

“`c

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 the format given below.)

“`

TOTAL MEMBERS: 3

COMMISSION DETAILS

Amit: 1000 INR

Rajesh: 250 INR

Virat: 250INR

“`

2. When there is only one child member in the hierarchy

Input:

“`c

Amit

Y

Rajesh

“`

– Output:

“`

TOTAL MEMBERS: 2

COMMISSION DETAILS

Amit: 500 INR

Rajesh: 250 INR

“`

Algorithm

“`

3. if head has child (y), do

count = number of commas in children

Print TOTAL MEMBERS: (count + 2)

Print COMMISSION DETAILS

Print (head) ((commas + 1) * 500) “INR”

children = split children with ‘, ‘ as delimiter

for every child in children, do

Print (child): 250 INR

else do,

print TOTAL MEMBERS: 1

print COMMISSION DETAILS

Program In C Language

``````#include <stdio.h>

int count_commas(char children[])
{
int count = 0, i = 0;
while(children[i] != '\0')
{
if (children[i] == ',')
count++;
i++;
}
return count;
}
int main()
{
scanf(" %c", &has_child);
char children[100];
if (has_child == 'Y' || has_child == 'y')
{
scanf(" %[^\n]s", children);
int commas = count_commas(children);
printf("TOTAL MEMBERS: %d\n", commas + 2);
printf("COMMISSION DETAILS\n");
printf("%s: %d INR\n", head, (commas + 1) * 500);
commas = 0;
while(1)
{
if (children[commas] == '\0')
{
printf(": 250 INR");
break;
}
if (children[commas] == ',')
{
printf(": 250 INR\n");
commas += 2;
continue;
}
printf("%c", children[commas]);
commas++;
}
}
else
{
printf("TOTAL MEMBERS: 1\n");
printf("COMMISSION DETAILS\n");
}
return 0;
}
``````

Program In C++

``````#include <iostream>
#include <algorithm>
#include <string>

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

int main() {
char has_child;
if ( has_child == 'Y' || has_child == 'y' )
{
string children;
cin.ignore();
getline(cin, children);
size_t commas = count (children.begin(), children.end(), ',');
cout << "TOTAL MEMBERS: " << commas + 2;
cout << endl << "COMMISSION DETAILS" << endl;
cout << head << ": " << (commas + 1) * 500 << " INR" << endl;
int start;
while(1)
{
start = children.find(", ");
if (start == -1)
{
cout << children << ": 250 INR" << endl;
break;
}
cout << children.substr(0, start) << ": 250 INR" << endl;
children.erase ( 0, start + 2 );
}
}
else
{
cout  << "TOTAL MEMBERS: 1" << endl;
cout  << "COMMISSION DETAILS" << endl;
cout  << head << ": 250 INR" << endl;
}
return 0;
}
``````

Program in Java

``````import java.util.Scanner;
class Main
{
public static void main(String[] args)
{
Scanner in = new Scanner(System.in);
char has_child = in.next().charAt(0);
in.nextLine();
String children="";
int comm = 1;
String[] children_arr = {};
if (has_child == 'Y' || has_child == 'y')
{
children = in.nextLine();
children_arr = children.split(", ");
comm += children_arr.length;
}
System.out.println("TOTAL MEMBERS: " + comm);
System.out.println("COMMISSION DETAILS");
if (has_child == 'Y' || has_child == 'y')
{
System.out.println(head + ": " + (comm - 1) * 500 + " INR");
for (String child : children_arr)
System.out.println(child + ": 250 INR");
}
else
}
}
``````

Program in Python

``````if __name__ == "__main__":
has_child = input()
children = []
if has_child is 'Y' or has_child is 'y':
children = input().split(', ')
print ("TOTAL MEMBERS:", len(children) + 1)
print ("COMMISSION DETAILS")
if has_child is 'Y' or has_child is 'y':
print (head + ": " + str(len(children) * 500) + " INR")
for i in children:
print(i + ": 250 INR")
else: