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
ANTONII [103]
4 years ago
11

Given: an int variable k, an int array current Members that has been declared and initialized, an int variable memberID that has

been initialized, and a boolean variable isAMember. Write code that assigns true to isAMember if the value of memberID can be found in current Members, and that assigns false to isAMember otherwise. Use only k, currentMembers, memberID, and isAMember.
Computers and Technology
1 answer:
Alekssandra [29.7K]4 years ago
4 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;

   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.

You might be interested in
_____ is a method for analyzing and reducing a relational database to its most streamlined form. Structured query Normalization
mixas84 [53]
<span>Structured query Is The Answer.</span>
4 0
3 years ago
Which invention allowed computers to become smaller in size?
dexar [7]
computers got smaller because one of its main components the valve – was replaced by the much smaller transistor.
7 0
3 years ago
Whats with the bot spamming customer care numbers...kinda annoying when im trying to help people.
Norma-Jean [14]

Answer:

yes

Explanation:

5 0
3 years ago
When you catch an Exception object, you can call ____ to display a list of methods in the call stack so you can determine the lo
KonstantinChe [14]

Answer:

printStackTrace()

Explanation:

printStackTrace() :- This method is present in Java.lang.Throwable class and it prints this Throwable it also prints other details with throwable like backtrace and class name. printStackTrace() prints a stack trace for this Throwable object on the output stream of standard error. So we conclude that the answer is printStackTrace().

3 0
3 years ago
A shop will give discount of 10% if the cost of purchased quantity is more than 1000. Ask user for quantity suppose, one unit wi
Mamont248 [21]

Answer:

The program in C++ is as follows:

#include <iostream>

using namespace std;

int main(){

   int qty;

   float discount = 0;

   cout<<"Quantity: ";

   cin>>qty;

   int cost = qty * 100;

i f (cost > 1000) {        discount=cost * 0.10;        }

   cout<<"Cost: "<<cost - discount;

   return 0;

}

Explanation:

This declares the quantity as integer

   int qty;

This declares and initializes discount to 0

   float discount = 0;

This prompts the user for quantity

   cout<<"Quantity: ";

This gets input for quantity

   cin>>qty;

This calculates the cost

   int cost = qty * 100;

If cost is above 1000, a discount of 10% is calculated

i f (cost > 1000) {        discount=cost * 0.10;        }

This prints the cost

   cout<<"Cost: "<<cost - discount;

4 0
3 years ago
Other questions:
  • Which function of a web page relies on responsive web design
    14·1 answer
  • An operating system is an example of _______. The hard drive, keyboard and monitor are example of_______.​
    11·1 answer
  • Typically, what form do most database designers consider a database structure to be normalized?
    15·1 answer
  • 5. Write a function that takes two lists of integers and returns a list containing tuples with corresponding elements from both
    8·1 answer
  • Microsoft Word is ________________ software.
    8·1 answer
  • HELP PLSSSSS!!! I WILL MARK BRAINLIEST FOR THE FIRST AND CORRECT ANSWER!!!
    14·2 answers
  • How to change your name to a fake one
    8·1 answer
  • Test if the word mold is stored in the variable word. Computer science.
    9·1 answer
  • How do you select from the insertion point to the beginning of the current line?
    5·1 answer
  • Write a C++ program to print name, age, class, school​
    12·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!