0% found this document useful (0 votes)
330 views

123UGRD-ITE6200A Computer Programming 1

This document contains a series of questions and answers related to programming concepts like loops, arrays, and conditional statements in C++. It covers topics such as the proper syntax for different loop structures, accessing array elements, using break and continue statements, and selecting the appropriate control structure based on multiple conditions.
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
330 views

123UGRD-ITE6200A Computer Programming 1

This document contains a series of questions and answers related to programming concepts like loops, arrays, and conditional statements in C++. It covers topics such as the proper syntax for different loop structures, accessing array elements, using break and continue statements, and selecting the appropriate control structure based on multiple conditions.
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 6

What's wrong?

  (x = 4 && y = 5) ? (a = 5) ; (b = 6);

b. the first semicolon should be a colon

If there is more than one statement in the block of a for loop, which of the following
must be placed at the beginning and the ending of the loop block?

a. braces{}

What's wrong?  while( (i < 10) && (i > 24))


b. the test condition is always false

What's wrong?  for (int k = 2, k <=12, k++)

a. the commas should be semicolons


Which looping process is best used when the number of iterations is known?

a. for

The statement  i++;  is equivalent to – 

c. i = i + 1;

In a group of nested loops, which loop is executed the most number of times?

d. the innermost loop

A continue statement causes execution to skip to - 

d. the next iteration of the loop


Which looping process checks the test condition at the end of the loop?

b. do-while
Each pass through a loop is called a/an - 

b. iteration
2
n array can contain how many kinds of elements ?

a. All of them have same type

 Array is defined as -

d.
An array is a series of elements of the same type in  contiguous memory locations

Which of the header file is used for array type manipulation?

a. std namespace

Arrays elements can be accessed?

a. Randomly

Which of the following correctly declares an array?

b. array array[10];

if you have to make decision based on multiple choices, which of the following is best
suited?

c. if-else-if

In situations where we need to execute body of the loop before testing the condition,
we should use_____.

c. do-while loop

What is the way to suddenly come out of or quit any loop in C++?

c. break; statement

The switch statement is also called as?


a. selective structure

What is the index variable for the element at the first row and first column in array? 

c, a[0][0]

3
Output of the this program will be _____
#include
using namespace std;
int main ()
{
int array[] = {0, 2, 4, 6, 7, 5, 3};
int n, result = 0;
for (n = 0 ;n < 8 ;n++) {
result += array[n];
}
cout << result;
return 0;
}

d. 27
Output of this program will be ____?
#include
using namespace std;
int main()
{
char str[5] = “ABC”;
cout << str[3];
cout << str;
return 0;
}

b. ABC
What will be the output of the following C++ code?
#include <iostream>
#include <string>
using namespace std;
int main()
{
         cout<<is_array<int>::value;
         cout<<is_array<char[10]>::value;
         cout<<is_array<string>::value;
         return 0;
}

b. 010
What is the index number of the last element of an array with 9 elements?

d. 8

Fill in the blanks to print "this is a loop" to the screen 15 times.


int x = 1;
do {
  cout << "this is a loop" << endl;
  x++;
}
while (_____<= _____);

a. x,15
Fill in the blanks to enter five numbers from the user and print their sum. Store the sum in
the variable named total.
 
int x = 1;
int number;
int total = 0;
_______ (x <= 5) {
  cin >> number;
_______= total + number;
  x++;
}
cout << "Sum: " << _____ << endl;

a. while, total, total

Fill in the missing parts of the following code:


 int x = 22;
 ______(x > 33) {
 cout << "x is greater than 33" << endl;
}
 ______ {
 cout << "x is not greater than 33" << endl;
}

d. if, else
Fill in the blanks to test the value of the variable x; if x is 2, print "it's 2" to the screen;
otherwise (the default case), print "the default case" to the screen.
 
int x;
cin >> x;
switch (____) {
case 2:
 cout << "it's 2" << endl;
 break;
 ______:
 cout << "the default case" << endl;
}

b. x, default

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy