1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
egoroff_w [7]
3 years ago
12

Given :an int variable k,an int array currentMembers that has been declared and initialized ,an int variable nMembers that conta

ins the number of elements in the array ,an int variable memberID that has been initialized , andan int variable isAMember, write code that assigns 1 to isAMember if the value of memberID can be found in currentMembers, and that assigns 0 to isAMember otherwise. Use only k, currentMembers, nMembers, and isAMember.
Computers and Technology
1 answer:
ipn [44]3 years ago
5 0

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, 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 = 1;

           break;

       }

       else

           isAMember = 0;

   }

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.

int k, memberID = 12, nMembers=5, 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 1 otherwise it is assigned 0.

When the variable isAMember is initialized to 1, the break statement is used to exit from the loop.

for(k=0; k<nMembers; k++)

   {

       if(memberID == currentMembers[k])

       {

           isAMember = 1;

           break;

       }

       else

           isAMember = 0;

 }

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 assigned value 0 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.

Also, the value of the variable isAMember is not displayed since it is not mentioned in the question.

This program can be tested for different values of the id of the members and different sizes of the array.

You might be interested in
Which of these sedimentary rocks is made of the largest particles?
Marta_Voda [28]
Your answer is <span>A.conglomerate.

Hope this helps :)</span>
6 0
4 years ago
Using a vue-cli initiated project, make a ticker that will keep track of the number of attendees in a space
BARSIC [14]
Number of attendees
7 0
3 years ago
Select the levels of data backup.
navik [9.2K]
What levels r right and we can pick from??
6 0
4 years ago
Collaborative devices are web and mobile applications that allow users to share files, meet virtually in real-time, and assign t
const2013 [10]

Answer:

true

Explanation:

because collaborative devices are made to make work much productive and easier within a group. it's true since the following statements can result to productivity

6 0
3 years ago
Read 2 more answers
What are the best gta online buisinesses?​
ELEN [110]

Answer:

Night club

Explanation:

Because night club isn't a day club

3 0
3 years ago
Read 2 more answers
Other questions:
  • Which actions can be performed on tables in Word? Check all that apply.
    13·2 answers
  • Select the correct answer. Ryan received an email from a person claiming that he is an employee of the bank in which Ryan has a
    11·2 answers
  • What is the difference between a switch and a hub?
    8·1 answer
  • When a company is attempting to go public, they will hire an investment bank to...
    11·2 answers
  • What is the command for basic router configuration?
    6·1 answer
  • Use______ to format cells when they meet a certain criteria.
    13·1 answer
  • Which option correctly describes a DDMS application?
    6·1 answer
  • The science of how an object reacts to its motion through air is called _______________. (12 letters)
    13·2 answers
  • Computer are most wonderful creation of 21st century how ?​
    15·1 answer
  • Draw and implement of an organization which have 125 employees. use the following features 1.email services 2.lan communication
    8·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!