Anda di halaman 1dari 3

RULES

1.Refer to rules in set 1 questions.

2.This is the 2nd set.

3.u have to answer both 1st and second set.

4.If there are no errors specify NOERROR in the form text box.

5.There will be only logical questions and no syntactical errors(if present,ignore them).

5.For filling the answers for set2,a separate form has been provided.

6.Incase of any doubt please contact:

Simon D 9884993229
S.Kannan 9884812861

7 Answer all questions


QUESTIONS
5)HUGENUM is a class with attributes int length, char oper and a char array a[].
a operator OP is overloaded and the code snippet is given.

HUGENUM HUGENUM::operator OP(int M)


{
if (M<0)
return -((*this)/(-M));
HUGENUM c;
c.oper=oper;
c.length=length;
int t=0;
for (int i=c.length;i>=1;i--)
c.a[i]=(t=(t%M*10000+a[i]))/M;
return c;
}

here M is 1024;

OUTPUT (c.a[i]) is:


3081030810308103081030810308103081030810

identify the other input?(i.e. Find a[i])


if you are good enough with huge numbers u dont hav to worry abt the HUGENUM class.

6)Give two pairs of strings for which the program won't work:

#include<iostream.h>
#include<conio.h>
#include<string.h>

void main()
{
clrscr();
char name1[40],name2[40];
cin>>name1;
cin>>name2;

int count=strlen(name1)+strlen(name2);

int i,j;
cout<<count<< "is the initial total no of characters\n";
for(i=0;i<strlen(name1);i++)
for(j=0;j<strlen(name2);j++)
if(name1[i]==name2[j])
{
name1[i]='/';
name2[j]='/';
count-=2;
}

cout<<count<<"is the remaining total no of characters after cancellation of common


cahracters in the two words";
getch();
}

7)What are the bugs in the program:

#include<stdio.h>
#include<conio.h>
#include<string.h>
void main()
{
clrscr();
int i=-1;
char c;
char password[100];
for(;;)
{
c=getch();
password[++i]=c;
if(c==13) break;
printf("*");
}
password[++i]='\0';
if(strcmp(password,"code")==0) printf("\nvalid password");
else printf("\ninvalid password");

getch();
}

8)Does this algorithm fail?Suggest a correction (if any)

int XXXXX(int a[],int value,int left,int right)


{
if(right<left)
return -1;
int mid =(int)ceil((left+right)/2);
if(a[mid]==value)
return mid;
if(value<a[mid])
XXXXX(a,value,left,mid-1);
else
XXXXX(a,value,mid+1,right);
}

Anda mungkin juga menyukai