Skip to main content

Zoho Interview | Set 1 Question 5

Given a two dimensional array of string like

<”luke”, “shaw”> 

 <”wayne”, “rooney”>

 <”rooney”, “ronaldo”> 

<”shaw”, “rooney”>

Where the first string is “child”, second string is “Father”. And given “ronaldo” we have to find his no of grandchildren Here “ronaldo” has 2 grandchildren.

 

 So our output should be 2..

 

My solution ::

#include <iostream>
#include<cstdlib>
using namespace std;
int count=0;
string a[4][2]={
   {"luke", "shaw"},
   {"wayne", "rooney"},
   {"rooney", "ronaldo"},
   {"shaw", "rooney"}
 };
void grandchi(string x){
  for(int i=0;i<4;i++){
 if(x==a[i][1]){
  count++;
 }
  } 
}
int main() {
 string s,s1;
  
 for(int i=0;i<4;i++){
  for(int j=0;j<2;j++){
   cout<<a[i][j]<<"\n";
  }
  
 }
 cout<<"enter string"<<"\n";
 cin>>s;
 cout<<s;
 for(int i=0;i<4;i++){
  if(s==a[i][1]){
   s1=a[i][0];
   grandchi(s1);
  }
 }
 cout<<"grand children:"<<count;
 return 0;
}

 

Comments

  1. Hi, in line 5, is "string" a data type in C++? I tried running on Borland C++ and it shows error.
    Also, what is the use of "using namespace std" ?

    Thanks in advance !!!

    ReplyDelete
    Replies
    1. When you use "using namespace std" Then you don't need to scope resolute every c++ object you are using in your program like std::

      If you still have a doubt refer this link:https://www.quora.com/What-does-using-namespace-std-mean-in-C++

      Delete

Post a Comment

Popular posts from this blog

C Questions

C Questions
C Questions

Note : All the programs are tested under Turbo C/C++ compilers.
It is assumed that,
Programs run under DOS environment, The underlying machine is an x86 system, Program is compiled using Turbo C/C++ compiler.
The program output may depend on the information based on this assumptions (for example sizeof(int) == 2 may be assumed).
Predict the output or error(s) for the following:

void main()
{
int const * p=5; printf("%d",++(*p));
}
Answer:
Compiler error: Cannot modify a constant value.
Explanation:
p is a pointer to a "constant integer". But we tried to change the value of the "constant integer".
main()
{
char s[ ]="man"; int i;
for(i=0;s[ i ];i++)
printf("\n%c%c%c%c",s[ i ],*(s+i),*(i+s),i[s]);
}
Answer: mmmm
aaaa nnnn
Explanation

Zoho Interview | Set 1 (Advanced Programming Round)

Third Round: (Advanced Programming Round) Here they asked us to create a “Railway reservation system” and gave us 4 modules. The modules were:
    1. Booking
    2. Availability checking
    3. Cancellation
    4. Prepare chart
We were asked to create the modules for representing each data first and to continue with the implementation phase.

 My Solution :

#include<stdio.h>#include<conio.h>#include<stdlib.h>#include<string.h>#include<iostream.h>#include<time.h>#include<iomanip.h>#include<fstream.h>char f[10]="f";char s[10]="s";int addr,ad,flag,f1,d,m,i,amt;float tamt; class login {public:char id[100];char pass[100];char*password;void getid(){ cout<<"Enter your id:";gets(id); password=getpass("Enter the password:");strcpy(pass,password);}void displayid(){ cout<<"Id:";puts(id); cout<<"Password:";puts(pass);}}; class detail {public:in…

ORACLE 9i practice solutions

Created by BCL easyConverter SDK 3 (HTML Version)