Free CPA-21-02 Exam Braindumps (page: 13)

Page 13 of 65

What is the output of the program if character 2 is supplied as input?

#include <iostream>

using namespace std;

int main () {
int c;
cin >> c;

try
{
switch (c)
{
case 1:
throw 20;
case 2:
throw 5.2f;
}
}
catch (int e)
{ cout << "int exception. Exception Nr. " << e; }

catch (float e)
{ cout << "float exception. Exception Nr. " << e; }
catch (...)
{ cout << "An exception occurred."; }
return 0;
}

  1. It prints: float exception. Exception Nr.
  2. It prints: int exception. Exception Nr. 20
  3. It prints: An exception occurred
  4. It prints: float exception. Exception Nr. 5.2

Answer(s): D



What is the output of the program if character 4 is supplied as input?

#include <iostream>
using namespace std;
int main () {
int c;
cin >> c;
try
{
switch (c)
{
case 1:
throw 20;
case 2:
throw 5.2f;
case 3:
throw 'a';
default:
cout<<"No exception";

}
}
catch (int e)
{ cout << "int exception. Exception Nr. " << e; }
catch (float e)
{ cout << "float exception. Exception Nr. " << e; }
catch (...)
{ cout << "An exception occurred."; }
return 0;
}

  1. It prints: float exception. Exception Nr.
  2. It prints: int exception. Exception Nr.
  3. It prints: An exception occurred
  4. It prints: No exception

Answer(s): D



Which code, inserted at line 14, generates the output "3.14 10"?

#include <iostream>
using namespace std;
namespace myNamespace1
{
int x = 5;
int y = 10;
}
namespace myNamespace2
{
float x = 3.14;
float y = 1.5;
}
int main () {
//insert code here cout << x << " " << y;
return 0;
}

  1. using myNamespace2::y; using myNamespace1::x;
  2. using namespace myNamespace1;
  3. using namespace myNamespace1; using namespace myNamespace2;
  4. using myNamespace1::y; using myNamespace2::x;

Answer(s): D



What is the output of the program?

#include <iostream>
#include <string>

using namespace std;

int main()

{
string s1[]= {"Hello" , "World" };

for (int i=0; i<2; i++) {
cout << s1[i];
}
return( 0 );
}

  1. It prints: HelloWorld
  2. It prints: Hello
  3. It prints: WorldHello
  4. It prints: World

Answer(s): A



Page 13 of 65



Post your Comments and Discuss C++ Institute CPA-21-02 exam with other Community members:

Subash commented on October 21, 2024
I am planning to take this exam. Are these 257 questions enough to clear it? Also, does each section have a passing percentage, or is it based on the overall ?
INDIA
upvote