# Chain Marketing Coding Question

## TCS Coding Question Day 2 Slot 2 : Question 2

This question has been asked in the TCS NQT 2020 Day 2 Slot 1

Topic : Conditional Statement

Time Given : 30 Minutes

Difficulty : 3/5 stars

Chain Marketing Organization has 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 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 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 gets commission of 5%.
Take name of the members joining the scheme as input.
Display how many members joined the scheme including parent member.Calculate the Total commission gained by each members in the scheme. The fixed amount for joining the scheme is Rs.5000 on which commission will be generated
SchemeAmount = 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 as this
Y                           //Enter Y if  Parent member has child members otherwise enter N
Rajesh,Virat        //Enter names of child members of Amit in comma separated
Output:(Final Output must be in format given below.)
TOTAL MEMBERS:3
COMISSION DETAILS
Amit: 1000 INR
Rajesh :250 INR
Virat: 250 INR

Example 2: When there is only one child member in the hierarchy
Input :
Amit
Y
Rajesh
Output:
Total Members: 2
Comission Details
Amit: 500 INR
Rajesh: 250 INR

`using namespace std;int main(){    string par;    cin >> par;    string x;    cin >> x;    if (x == "N") {        cout << "TOTAL MEMBERS:1\n";        cout << "COMISSION DETAILS\n";        cout << par << ":250 INR\n";    } else {        string child;        cin >> child;        vector<string>v;        string temp = "";        for (int i = 0; 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 << "COMISSION DETAILS\n";        cout << par << ":" << v.size() * 500 << " INR\n";        for (auto a : v) {            cout << a << ":" << "250 INR\n";      }   }}`
`parent = input()Yes_No = input()if Yes_No == "N":    print("TOTAL MEMBERS:1\nCOMMISSION DETAILS\n{0}: 250 INR".format(parent))elif Yes_No == "Y":    child=list(map(str,input().split(",")))    print("TOTAL MEMBERS:{}".format(len(child)+1))    print("COMMISSION DETAILS \n{0}:{1} INR".format(parent,len(child)*500))    for i in child:        print("{0}:250 INR".format(i))`

## Day 2 Slot 2 Question 1

Click on the below button to study Day 2 Slot 2 Question 1 of TCS NQT Coding 2020 exam

Code

## TCS Coding Questions

Click on the below button to study more TCS Coding Question

TCS Coding Question

### 2 comments on “Chain Marketing Coding Question”

• Shreyas

import java.util.Scanner;
public class ChainMarketing {

public static void main(String args[]) {

Scanner sc = new Scanner(System.in);
String parent = sc.next();
char yn = sc.next().charAt(0);
int pcomm=0;
if(yn== ‘N’) {
pcomm = 250;
System.out.println(“Total members: 1”);
System.out.println(“Commission details\n”+parent+” “+pcomm);
}
else if(yn == ‘Y’) {
int chComm1,chComm2;
String child[] = new String[2];
child = sc.next().split(“,”);
pcomm = 1000;
chComm1 = 250;
chComm2 = 250;

System.out.println(“Total members: 3”);
System.out.println(“Commission details\n”+parent+” “+pcomm);

System.out.println(child[0]+” “+chComm1);
System.out.println(child[1]+” “+chComm2);

}
else
System.out.println(“INVALID INPUT”);
}
}

• Ankita

package PrepInsta;

import java.util.Scanner;

public class Commision {

public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
String Parent=sc.nextLine();
char ch=sc.next().charAt(0);

int count=1;
int schemeAmt=5000;
int ParentCom=0;

if(ch==’Y’)
{
String Child=sc.next();
String[] member=Child.split(“,”);
count=member.length;
System.out.println(“Total member: “+(count+1));

System.out.println(“Commision Details: “);
int x=count*5000;
ParentCom=(x*10)/100;
System.out.println(Parent+”:”+ParentCom+”INR”);

for(int i=0;i<member.length;i++)
{

int memberCom=(5*5000)/100;
System.out.println(member[i]+":"+memberCom+"INR");

}
}
if(ch=='N')
{
System.out.println("Total member:1");
System.out.println("Commision Details: ");
System.out.println(Parent+":"+ 250 +"INR");
}
}

}