Sapient Placement Questions


CAN SOMEBODY HELP ME SOLVING THESE QUES



Program 1. Reservation. there are 67 seats in train . there are only 5 seats in a row and in last row there are only 2 seats. One person can reseve only 5 seat at a time. If person reserving seat , the care is atken that he may get all in row. if seats are not available in row then the arrangement is so that person group get nearby seats. the following class is given public class seat { char name; int seat; boolean isSeatempty } 1.Draw require class digram and object diagram. 2.Write function seatallot(int noofperson) to allocate seat with seat nuber printed for the each name.

Program 2. Stringreplace The forum is going on and administartor find that some people use abusing or bad lnaguage in discussion.so he decided that when he uses such language it was replacedc with beap. question: 1. draw class digram,and use appropriate data structure. 2. write function replacestring()


1) Write a program for the problem: the array of
inetegers indicating the marks of the students is
given, U have to calculate the percentile of the
students aaccording to this rule: the percentile of a
student is the %of no of student having marks less
then him. For eg:
suppose

Student Marks
A 12
B 60
C 80
D 71
E 30
F 45

percentile of C = 5/5 *100 = 100 (out of 5 students 5
are having marks less then him)
percentile of B = 3/5*100 = 60% (out of 5, 3 have
markses less then him)
percentile of A = 0/5*100 = 0%.

2) The code was given for a problem and u have to
identitfy the logical error in it. That was simple.
The code was to merge the Danagrams of 2 words. The
danagram of a word is the letters of word arranfed in
sequential order. eg danagram of abhinav is aabhinv.
merging of danamagram is to merge the danagrams of 2
or more words such that the highest no of occurance
are coming for each alphabet.eg

merging of aabhinv and abbhhixz is aabbhhinvxz.


Showing Answers 1 - 41 of 41 Answers

avinash

  • Apr 2nd, 2006
 

well for the program 1) integer array-percentile, we can sort the array in descending/ascending order and then the percetile would be easy to find.

  Was this answer useful?  Yes

avi2code

  • Apr 15th, 2006
 

well no need of sorting

use 2 loops.

outer loop....say i = 0 to n-1

{ c=0; //count for storing scores less than a[i]

  inner loop.....say j = 0 to n-1

   {if(a[i]<a[j])   c=c+1;}

 percentile = (c*100)/(n-1);

}

  Was this answer useful?  Yes

Hi everyone

  • Apr 19th, 2006
 

I am going for sapient interview this weekend for the Associate QA position (testing) one year experience if any one of you have any clues about the interview process please post your comment or you can mail me at vpathania@gmail.com.Thank you

  Was this answer useful?  Yes

varun

  • Apr 30th, 2006
 

PLEASE MAIL ME THE UPDATED QUESTIONS OF SAPIENTWITH REPLY

  Was this answer useful?  Yes

mukesh kumar

  • May 17th, 2006
 

I would also like to have the solution of the questins asked.

  Was this answer useful?  Yes

bharti

  • Jun 22nd, 2006
 

I am going to appear for sapient exam on this Tuesday.

Plz send me question papers with answers and some tips.

with regards

bharti

  Was this answer useful?  Yes

onkar

  • Jul 21st, 2006
 

#include<stdio.h>
#include<iostream.h>
#include<string.h>
#include<conio.h>
struct railres{
           int seatno;
            int isempty;
            char name[10];
                   }seat[14][5];

     static int arr[15];
      void reserve(int);
       void main()
       {
      int i,j;
      clrscr();
       for(i=0;i<=13;i++)
    for(j=0;j<5;j++)
    {
    seat[i][j].seatno=(i*5)+j+1;
     seat[i][j].isempty=1;
    }
       for(i=0;i<=12;i++)
     arr[i]=5;
     arr[13]=2;
     arr[14]=67;
       char res='y';
       do
  {
     int n;
     printf("enter number of seats requested ");
      scanf("%d",&n);
     if(n>5)
    {
      printf("cant book more than 5 at a time ");
      getch();
      return;
     }
   reserve(n);
   printf("ndo u want to book more seats ");
   cin>>res;
   }while(res!='n');
   getch();
      }
    void reserve(int num)
      {
        int flag=0,i,j,k=0;
        if(num>arr[14])
  {
  printf("cant book seats" );
  getch();
  return;
  }

  for(i=0;i<=13&&flag==0;i++)
      {

         if(arr[i]>=num)
       {
         flag=1;
      printf("nseats allottedn" );
    for(j=0;j<5;j++)
       {
      if(seat[i][j].isempty==1)
          {
        k=k+1;
        printf("nenter name ");
        scanf("%s",seat[i][j].name); 
        seat[i][j].isempty=0;
        printf("%dt",seat[i][j].seatno);
        if(k==num)       

        break;

          }
       }

      arr[i]=arr[i]-num;
      arr[14]=arr[14]-num;


      }
     }


         }

  Was this answer useful?  Yes

NEHA MAKKAR

  • Jul 31st, 2006
 

can anyone pls send me solutions to these sapient problems.

It's urgent i m going to appear after 2 days i.e. on 3aug.

pls it's urgent

thamk you in advance

  Was this answer useful?  Yes

Pranay Prasoon

  • Aug 3rd, 2006
 

Hello Neha,Can u plzz post the questions being asked to u today....As the company is visiting here on 5th Aug.Thnx. in advance...

  Was this answer useful?  Yes

richa

  • Aug 3rd, 2006
 

hi friends

i am having my sapient exam on 12th aug,so please send me palcement papers of sapient as soon as possible

  Was this answer useful?  Yes

shruti

  • Aug 4th, 2006
 

hey neha and pranay can u plzz post the questions asked to u .......plz do that as soon as possible...my test is on 13th

i will be obliged if u give me questions

thx

  Was this answer useful?  Yes

vinod

  • Aug 6th, 2006
 

sapient is coming in our campus and noone is clear abt the selection crieteria and the pattern of exam i ll b very thankful to u if u guide me hope u ll rply soon as the company is coming on 13th
bye

  Was this answer useful?  Yes

rauhl

  • Sep 12th, 2006
 

hi all this is rahul here if anybody of u have the solution of reservation problem comes in sapient placement exam in java thn pls send it to me. M in great need of thet solution.

  Was this answer useful?  Yes

Chaitanya M Bhatt)(RNSIT)

  • Nov 2nd, 2006
 

/*
Reservation.
there are 67 seats in train . there are only 5 seats in a row and in last
row there are only 2 seats.
One person can reseve only 5 seat at a time.
If person reserving seat , the care is atken that he may get all in row. if
seats are not available in row then the arrangement is so that person group
get nearby seats.

SOLUTION

Author:Chaitanya M Bhatt
Date:3-11-2007
Yahoo chat ID-rush_hangar
This is the most common question in sapient placement test.
This program has been tested and works without any hassel.
But i have simplified the program so that you can understand the logic easily.
*/

#include<iostream.h>
#include<ctype.h>
#include<fstream.h>
#include<conio.h>
#include<stdlib.h>
#include<stdio.h>


class train
{

int seats;
char name[30];

public:

void io();
void reservation(int seats,char name[]);
};

void train::io()
{

seats=0;

cout<<"Enter your name"<<endl;
cin>>name;

cout<<"Enter the number of seats you want to reserve"<<endl;
scanf("%d",seats);

reservation(seats,name);

}

void train::reservation(int seats,char name[])
{
    int seatcount=0;

    ifstream inf("seatcount.txt");
    inf>>seatcount;
    int seatcount1=seatcount;

if((seatcount+seats)>67)
{

 inf.close();
 cout<<"TRAIN is completelly filledn";
 getch();
 exit(1);
}

if(seats>5)    //To check if total number of seats exceeds 5
{
 cout<<"total seats that u r trying to reserve is exceeding company limits"<<"n";
 getch();
 exit(1);

}
else
{


 ofstream outf("train.txt",ios::app);//opens a file and appends new information           
 outf<<name<<"|";
 for(int seatco=seatcount1;seatco<=(seatcount1+seats);seatco++)//
 {

  outf<<seatco<<",";

 }
 ofstream ouf;
 ouf.open("seatcount.txt",ios::trunc);
 ouf<<seatco<<"n";
 ouf.close();

 cout<<"THANK YOU";
 getch();

 outf.close();
 system(edit train.txt);     //Shows the file which contains customer details


}

}


void main()
{

clrscr();
train ob;

ob.io();


}


 

  Was this answer useful?  Yes

Deck80

  • Mar 21st, 2007
 

Just a fast comment to the last code portion, I've read in 10 seconds, so sorry if I miss something...to be honest reading the problem I figured out a different solution, because I think that "in a row" means "in the same group" so, at least, you have to check if there are enough seats in same row, so that there is something like that

- - - - -    - - - - -    - - - - -   Add 2

x x - - -    - - - - -    - - - - -  Add 5

x x - - -    x x x x x    - - - - - Add 4

x x - - -    x x x x x    x x x x -
 And so on...
You should add then a counter
int seatreq=0, freeseats=0;
[...]
i=0;
while(freeseats<seatreq && i<67)

{
       if(i%5==0) freeseats=0;
       if(seat[i].isempty==1) freeseats++;
       else                             freeseats=0;
        i++;
}

if(freeseats!=seatreq)
{
    freeseats=0;
    i=0;
    while(freeseats<seatreq && i<67) /*obv. this part can be partially merged with previous one*/

    {
  
       if(seat[i].isempty==1) freeseats++;
       else                             freeseats=0;
        i++;
    }
}

if(freeseats==seatreq)
{
    for(j=i-seatreq;j<i;j++)
    seat[i].isempty=0;
}
don't have time to check if I wrote something right...
By the way, today I've signed for Sapient.

  Was this answer useful?  Yes

Deck80

  • Mar 24th, 2007
 

Obviously this solution DOESN'T reserve any seat if there aren't enough contiguous seats, even if they span through two row

  Was this answer useful?  Yes

ankur_usit

  • Apr 15th, 2007
 

****Solution to that percentile pblm....*****#include#include#include#includestruct stud{ int roll,marks; struct stud *next;}stptr;typedef struct stud *student;struct hnode{ int tnos; struct stud *first;};typedef struct hnode *head;void place(head list,student temp){ student p,q; q=NULL; for(p=list->first;p!=NULL && (temp->marks)>(p->marks);p=p->next) q=p; if (q==NULL){ temp->next=p; list->first=temp; } else{ temp->next=q->next; q->next=temp; } list->tnos++;}void addstud(head list){ int marks,roll; printf("nnEnter Roll no.t"); scanf("%d",&roll); printf("Enter markst"); scanf("%d",&marks); student temp; temp=(student)malloc(sizeof(struct stud)); temp->roll=roll; temp->marks=marks; if (list->tnos==0){ list->first=temp; temp->next=NULL; list->tnos=1; } else place(list,temp); printf("nnSTUDENT ADDED SUCCESSFULLY");}//void perc();void traverse(head list){ clrscr(); student temp; temp=list->first; int x=list->tnos; printf("TOTAL:%dn",x); for(int i=0;iroll,temp->marks); temp=temp->next; }}void perc(head list){ int roll,pos=0; float perc; int x; x=list->tnos; printf("nntEnter the Roll No.t"); scanf("%d",&roll); student temp; for(temp=list->first;(temp->roll!=roll)&&(temp->next!=NULL);temp=temp->next){ pos++; if (temp->next==NULL && temp->roll!=roll){ printf("nnttInvalid Roll No."); return; } } perc=((float)pos/(x-1))*100; printf("nnRoll No.:t%dn",roll); printf("Percentile.:t%f %n",perc);}void main(){ clrscr(); head list; list=(head)malloc(sizeof(struct hnode)); list->tnos=0; int ch; char ch1='y'; do{ clrscr(); printf("tt**************MENU**************n"); printf("tt* *n"); printf("tt* 1.Add student *n"); printf("tt* 2.Find Percentile *n"); printf("tt* 3.List All(in asc. order) *n"); printf("tt* 4.EXIT *n"); printf("tt* *n"); printf("tt********************************nn"); printf("nnt Enter your choicet"); scanf("%d",&ch); switch(ch) { case 1: addstud(list); break; // case 2: // delstud(); // break; case 2: perc(list); break; case 3: traverse(list); break; case 4: exit(0); default: printf("Wrong Choice"); } printf("nnDo you wana continue(Y/N)???t"); //gets(ch1); scanf("%s",&ch1); }while (ch1=='y'|| ch1=='Y'); printf("nnttBBYE!!!"); getch();}

  Was this answer useful?  Yes

vikram raghuwanshi

  • Jul 22nd, 2007
 



The code was given for a problem and you have to identitfy the logical error in it. That was simple.
The code was to merge the Danagrams of 2 words. The danagram of a word is the letters of word arranged in sequential order. eg danagram of abhinav is aabhinv.
Merging of danamagram is to merge the danagrams of 2 or more words such that the highest no of occurance are coming for each alphabet. eg merging of aabhinv and abbhhixz is aabbhhinvxz.

ans: by vikram raghuwanshi mca ips academy indore

#include
#include
void main()
{
?char a[]="aabhinv";
?char b[]="abbhhixz";
?char p[20];
?clrscr();
?fun(a,b,p);
?printf("nn%s",p);
?getch();
}
fun(char *a,char *b,char *p)
{
?int i=0;

?while(*a!=''&&*b!='')
?{
??if(*a==*b)
??{
???p[i]=*a;
???i++;
???a++;
???b++;
??}
??else
??{
???if(*a<*b)
???{
????p[i]=*a;
????a++;
????i++;
???}
???else
???{
????p[i]=*b;
????b++;
????i++;
???}
??}
??if(*a=='')
??{
???while(*b!='')
???{
????p[i]=*b;
????b++;
????i++;
???}
??}
??if(*b=='')
??{
???while(*a!='')
???{
????p[i]=*a;
????a++;
????i++;
???}
??}

?}
}

  Was this answer useful?  Yes

amit gupta

  • Sep 8th, 2007
 

A company has some clients and some officers. Also it
has some rooms to be used for meetings between client
and officers. one officer is responsible for each
room. and room has unique room id. a meeting will be
arranged only when the officer and client are free and
room is also free. the officer and clients must be
registered to the system which will give them unique
email ids. arrange the meetings.

write a program for the given situation.
also draw the class diagram for the same.

  Was this answer useful?  Yes

PRASHANT JAIN

  • Nov 9th, 2007
 

percentile:- no. of students having less %  then him

first put all the students details in an array:-
then
 do this thing in a for loop-------
closest_percentile=100-percentile;
highest_percentile=100-closest percentile;
}


-------this is the algorithm not the source code actually

  Was this answer useful?  Yes

#include"iostream.h"
#include"conio.h"
#define MAX 5


class cal{
     float percentage;
     int p;
    
  public:
    
     int percent();
     int calculate(float,int, int);
} percent;

int percent::percent(){
   
      p = 0;
      percentile = 1; }     
      
int percent::calculate(float marks[max], int reg, int n){
 


      for(int i=0;i<n;i++){
           if(marks[reg]>=marks[i] && i != reg){
                 p++;                          } }                     

      percentile = p/n * 100;
      return percentile;
}
      

void main(){
      
       float marks[max], per;
       int n,reg;
       percent a;

       clrscr();
        
       cout<<"pls specify the no of students writing the exam ?"<<endl;
      
       scanf<<n;
      
      


       cout<<"Enter marks one by one according to the reg no"<<endl;
       for(int i=0;i<=n;i++){
       
            cin>>marks[i];  }
      
      
       cout<<"Enter the reg no"<<endl;
       cin>>reg;
       cout<<"The percentile of the student of the given reg no is "<<per<<"%"<<endl;
       per = a.calculate(marks, reg, n);
}  

  Was this answer useful?  Yes

Sorry guy, the program given had some errors, the corrected version is:


#include"iostream.h"
#include"conio.h"
#define MAX 5


class cal{
     float percentage;
     int p;
    
  public:
    
     void percent();
     int calculate(float,int, int);
} percent;

void percent::percent(){
   
      p = 0;
      percentile = 1; }     
      
int percent::calculate(float marks[max], int reg, int n){
 


      for(int i=0;i<n;i++){
           if(marks[reg]>=marks[i] && i != reg){
                 p++;                          } }                     

      percentile = p/n * 100;
      return percentile;
}
      

void main(){
      
       float marks[max], per;
       int n,reg;
       percent a;

       clrscr();
        
       cout<<"pls specify the no of students writing the exam ?"<<endl;
      
       cout<<n;
      
      


       cout<<"Enter marks one by one according to the reg no"<<endl;
       for(int i=0;i<=n;i++){
       
            cin>>marks[i];  }
      
      
       cout<<"Enter the reg no"<<endl;
       cin>>reg;
       cout<<"The percentile of the student of the given reg no is "<<per<<"%"<<endl;
       per = a.calculate(marks, reg, n);
}  

  Was this answer useful?  Yes

anas alam

  • Oct 19th, 2009
 

heres the code for the reservation question:


public class Seat {
    String name;
    int seat;
    boolean isSeatempty;
    }

class SeatAlloc{
   
    static Seat[][] seatArray= new Seat[14][5];
    static int seatsOccupied =0;
   
    public static void seatallot(int noofperson){
        Integer seatno=seatsOccupied+1;
        seatsOccupied = seatsOccupied + noofperson;
        int seatsOcc = seatsOccupied;
        for(int i=0; i<14; i++){
            for(int j=0; j< 5 && seatno<68 && seatsOcc >0; j++, seatsOcc--){
                if(seatArray[i][j].isSeatempty){
                    seatArray[i][j].isSeatempty = false;
                    seatArray[i][j].name = "pass" + seatno.toString();
                    seatno++;
                }
            }
        }   
    }
   
    public static void initSeats(){
        int seatno =1;
        for(int i=0; i<14; i++){
            for(int j=0; j< 5 && seatno<68; j++){
                seatArray[i][j] = new Seat();
                seatArray[i][j].seat = seatno;
                seatArray[i][j].isSeatempty = true;
                System.out.println(seatno);
                seatno++;
            }
        }
    }
   
    public static void display(){
        Integer seatno =1;
        for(int i=0; i<14; i++){
            for(int j=0; j< 5 && seatno<68; j++){
                System.out.println("Seat no " + seatArray[i][j].seat);
                System.out.println("Is seat empty " + seatArray[i][j].isSeatempty);
                System.out.println("Passenger name " + seatArray[i][j].name);
                seatno++;
            }
        }
    }
   
    public static void main(String args[]){

        initSeats();
        seatallot(5);
        seatallot(60);
        display();
    }
}

  Was this answer useful?  Yes

Give your answer:

If you think the above answer is not correct, Please select a reason and add your answer below.

 

Related Answered Questions

 

Related Open Questions