Answer:
The c++ program is given below. Nothing is displayed as per the question.
#include <iostream>
using namespace std;
int main() {
// declaration and initialization of integer variables
int k, memberID = 12, nMembers=5;
bool isAMember;
// declaration and initialization of integer array
int currentMembers[] = {12, 34, 56, 78, 90};
for(k=0; k<nMembers; k++)
{
if(memberID == currentMembers[k])
{
// when member is found in the array, the loop is exited using break
isAMember = true;
break;
}
else
isAMember = false;
}
return 0;
}
Explanation:
The program begins with declaration and initialization of integer variables and followed by initialization of the array holding the id of all the members.
The Boolean variable is declared but not initialized.
int k, memberID = 12, nMembers=5;
bool isAMember;
int currentMembers[] = {12, 34, 56, 78, 90};
After this, the array holding the id of the members is searched for the given member id. This is done using a for loop and a if else statement inside the loop.
If the member id is present in the array, the variable isAMember is initialized to true otherwise it is assigned false.
When the variable isAMember is initialized to true, the break statement is used to exit from the loop.
for(k=0; k<nMembers; k++)
{
if(memberID == currentMembers[k])
{
isAMember = true;
break;
}
else
isAMember = false;
}
The break is used since other values of id in the array will not match the given member id and the variable, isAMember will be initialized to false even if the given member id is present in the array. Hence, it is mandatory to exit the loop once the given member id is found in the array.
This program can be tested for different values of the id of the members and different sizes of the array.