Documenti di Didattica
Documenti di Professioni
Documenti di Cultura
1X,
IITBombayX.
Q1
(2 points possible)
Consider the following expression used in a C++ program
a+b-c*d
If the types of a, b, c, and d are int, long int, float, and double respectively, then the type of the
expression is:
- unanswered
int
long int
float
double
Q2
(2 points possible)
What will be the output produced by the following program segment?
int varx;
varx = 13 > 10 ? 1 : 0;
cout<<varx;
- unanswered
13
10
Q3
(2 points possible)
A Chinese credit card company named Gooda Banka offers some credit points on a certain
amount of purchase made by the customer.
Select from the following which are INVALID. Assume credit purchase is always positive.
- unanswered
The program computes the credit points correctly, if the customer is associated with the bank
for 6 years, and the credit purchase is between 200 and 750
points correctly, if the number of years of the customer associated with the bank is greater than
two years
Irrespective of the positive credit purchase amount entered by the user, the
program computes the credit points correctly if the customer is associated with the bank for less
than or equal to two years.
None of these
You have used 0 of 1 submissions
Q4
(2 points possible)
What will be the output produced by the following program segment?
int i,j,sum=10;
for(i=0;i<5;i++)
if(i%2)
for(j=0;j<=3;sum+=j,j++){ }
else
for(j=3;j>0;sum+=j,j--){ }
cout<<sum;
- unanswered
You have used 0 of 1 submissions
Q5
(2 points possible)
What will be the output produced by the following program segment?
int x=1,i,y;
for(i=0;i<5;i++)
x+=3;
x%=5;
if(x%2==0)
cout<<"x is even";
else
cout<<"x is odd";
- unanswered
x is even
x is odd
Q6
(2 points possible)
In the following program, how many times is the function Recursive called, including the call
from the main function? Also, what will be the output of this program?
#include<iostream>
using namespace std;
int Recursive (int n) {
if (n == 0)
return 1;
if (n == 1)
return 2;
return ( Recursive (n - 1) * Recursive (n - 2) );
}
int main () {
int value = Recursive (5);
cout << " Result : " << value << endl ;
return 0;
}
- unanswered
The recursive function will be called 15 times and the following output is produced: Result:
32
The recursive function will be called 14 times and the following output is produced:
Result: 32
The recursive function will be called 13 times and the following output is
produced: Result: 28
is produced: Result: 18
The recursive function will be called 14 times and the following output
None of these
Q7
(2 points possible)
What will be the output produced by the following program segment?
int tmp, i, j=0, n=8, y=12;
int A[8]={5,7,12,15,20,2,0,30};
for(i=0;i<n;i++){
if(A[i] < y){
int tmp = A[j];
A[j] = A[i];
A[i] = tmp;
j++;
}
}
int s=0;
for(i=0;i<n;i++){
s=s+A[i];
}
cout<<s/n;
- unanswered
You have used 0 of 1 submissions
Q8
(2 points possible)
What will be the output produced by the following program segment?
#include<iostream>
using namespace std;
int main() {
int N = 5, i, j, a[11], b[11];
a[0]=3;
b[0]=0;
a[1]=2;
for( i=1; i<N ; i=i+1) {
b[i] = a[i-1] + b[i-1];
if (i >= 2)
a[i] = a[i-1] + b[i-2];
}
i = 0;
while (i < N) {
a[2*(N-i-1)] = a[N-i-1];
a[2*(N-i-1)+1] = b[N-i-1];
i++;
}
for(i=0; i<2*N; i++)
cout << a[i] << " ";
}
return 0;
- unanswered
3 0 2 3 2 3 3 5 7 12
3 0 2 3 2 5 5 7 10 12
3 0 2 3 3 3 3 5 7 12
3 0 2 3 3 2 3 5 10
12
You have used 0 of 1 submissions
Q9
(2 points possible)
Consider the following program. Assume 10 integer values are supplied as input.
#include<iostream>
using namespace std;
int main(){
int n = 10;
int A[10], B[10];
int k = 0;
for(int i=0; i<n; i++)
cin >> A[i];
bool found = false;
for(int i = 0; i<n-1; i++){ //Begin first for loop
found = false;
for(int j=i+1; j<n; j++){ // Begin second for loop
if((A[i]-A[j]) == 0){ // Begin first If
Which of the following can be said about the above program? Select the ones which are
appropriate:
- unanswered
All duplicate elements of array 'A' are stored in array 'B' with as many duplicates as is
present in array 'A'
The program successfully finds all duplicate elements in array 'A' and
None of these
Q10
(2 points possible)
The below given program first finds the length of the main string entered by the user. It then asks
for the substring to be searched in the main string. If the entered substring is found, it displays
the message "substring found at start index 'startindx' and end index 'endindx'. After which, it
asks for the substring to be replaced by the replacement substring, both are to be entered by the
user. Finally, it prints the main string.
#include<iostream>
#include<cstdio>
using namespace std;
//gets the string entered by the user of length 'len'
//It also checks for the maximum number of elements 'maxlength' the string can
contain
proper length of the string and hence leads to problems in searching substring
and the end index calculated for substring search is not correct
You have used 0 of 1 submissions
Q11
(2 points possible)
Consider the following program that prints the sequence of characters based on the value
of variable 'counter'
#include<iostream>
using namespace std;
int myFunction(char *name, int counter) {
if(counter == 1)
return 0;
else {
counter--;
if(counter == 4) {
for(int i=0;i<counter;i++)
cout<<name[i];
cout<<endl;
}
myFunction(name,counter);
if(counter == 4) {
for(int i=0;i<=counter;i++)
cout<<name[i];
cout<<endl;
}
return 0;
}
}
int main(){
int intNum=9;
char name[]={'C','S','1','0','1','.','2','x'};
myFunction(name, intNum);
return 0;
}
The value 9 is passed from the main function to the variable 'counter'. What will the function
'myFunction' print.
- unanswered
CS10
CS101
CS10
CS10
CS101
CS10
CS101
CS101
None of these
You have used 0 of 1 submissions
Q12
(2 points possible)
None of these
Q13
(2 points possible)
What is the result of execution of the following C++ program if the user enters
thequickbrownfox when prompted to enter myString ?
#include<iostream>
using namespace std;
int main ()
{
char myString[12];
cout << "Enter the string : ";
cin >> myString ;
cout << myString ;
return 0;
}
None of these
Q14
(2 points possible)
Consider the following piece of code which removes alternate characters from a file 'file_path1'
and writes the result to a new file 'file_path2'. The first character is copied, the second is skipped,
and so on. Assume that 'file_path1' and 'file_path2' are defined earlier and have paths to valid
files on the disk.
#include<iostream>
#include<cstdio>
using namespace std;
int main(){
const char* file_path1="input.txt";
const char* file_path2="output.txt";
FILE *fpt = NULL, *fpt_dest = NULL;
fpt = fopen(file_path1, "r");
if(!fpt) return -1;
fpt_dest = fopen(file_path2, "w");
if(!fpt_dest) return -1;
//INSERT THE SNIPPET CODE HERE
fclose(fpt);
fclose(fpt_dest);
Which of the following snippet of code if replaced with "INSERT THE SNIPPET CODE
HERE", will execute the program correctly as mentioned in the question?
- unanswered
// Snippet Code 1:
while(true){
char tmp;
fscanf(fpt, "%c", &tmp);
if(feof(fpt))
break;
fprintf(fpt_dest, "%c", tmp);
fscanf(fpt, "%c", &tmp);
if(feof(fpt))
break;
}
// Snippet Code 2:
bool flag1 = true;
bool flag2 = true;
while(flag1){
char tmp;
fscanf(fpt,"%c", &tmp);
if(feof(fpt))
flag1 = false;
if(flag2)
fprintf(fpt_dest, "%c", tmp);
flag2 = !flag2;
}
// Snippet Code 3:
while(1){
char tmp;
fscanf(fpt,"%c", &tmp);
if(!feof(fpt))
fprintf(fpt_dest, "%c", tmp);
fscanf(fpt,"%c", &tmp);
}
// Snippet Code 4:
while(1){
char tmp1, tmp2;
fscanf(fpt, "%c", &tmp1);
fscanf(fpt, "%c", &tmp2);
fprintf(fpt_dest, "%c", tmp1);
fprintf(fpt_dest, "%c", tmp2);
}
None of these
Q15
(2 points possible)
Consider the following 'main' program:
#include <iostream>
#include<cstdio>
using namespace std;
int main(){
FILE *fp;
int d= 0;
fp = fopen("file.txt", "r");
if (fp == NULL)
cout<<"File not found";
else{
fseek(fp, 0, 2);
d = ftell(fp);
fclose(fp);
}
return 0;
}
The