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
A decision tree Multiple Choice is a chart that shows the hierarchy of levels and positions in an organization. is a chart that
dezoksy [38]

Answer:

is a chart that allows the reader to follow a particular path and arrive at an outcome.

Explanation:

A decision tree is a chart i.e tree like diagram that allow a user to make choice on the option to partake in. Decision trees are also used for classification and for making process

The decision tree usually have a root as the node. Then each option/decision is represented as a branch out extending from the previous node.

For Instance, when a coins is toss three times; a decision tree gives us the possible path that is available to choose from.

3 0
3 years ago
What does this mean “Fatal error: Uncaught exception 'Thrift\Exception\TTransportException' with message 'THttpClient: Could not
hodyreva [135]
You could try turning your pc completely off then back on or redownloading your browser
3 0
4 years ago
Write Album's PrintSongsShorterThan() to print all the songs from the album shorter than the value of the parameter songDuration
Romashka-Z-Leto [24]

Answer:

Here is the function PrintSongsShorterThan() which prints all the songs from the album shorter than the value of the parameter songDuration.

void Album::PrintSongsShorterThan(int songDuration) const {

unsigned int i;

Song currSong;  

cout << "Songs shorter than " << songDuration << " seconds:" << endl;  

for(int i=0; i<albumSongs.size(); i++){  

currSong = albumSongs.at(i);  

if(currSong.GetDuration()<songDuration){  

currSong.PrintSong();     } } }

Explanation:

I will explain the working of the for loop in the above function.

The loop has a variable i that is initialized to 0. The loop continues to execute until the value of i exceeds the albumSongs vector size. The albumSongs is a Song type vector and vector works just like a dynamic array to store sequences.

At each iteration the for loop checks if the value of i is less than the size of albumSongs. If it is true then the statement inside the loop body execute. The at() is a vector function that is used to return a reference to the element at i-th position in the albumSongs.  So the album song at the i-th index of albumSongs is assigned to the currSong. This currSong works as an instance. Next the if condition checks if that album song's duration is less than the specified value of songDuration. Here the method GetDuration() is used to return the value of duration of the song. If this condition evaluates to true then the printSong method is called using currSong object. The printSong() method has a statement cout << name << " - " << duration << endl;  which prints/displays the name of the song with its duration.

If you see the main() function statement: musicAlbum.PrintSongsShorterThan(210);

The musicAlbum is the Album object to access the PrintSongsShorterThan(210) The value passed to this method is 210 which means this is the value of the songDuration.

As we know that the parameter of PrintSongsShorterThan method is songDuration. So the duration of each song in albumSongs vector is checked by this function and if the song duration is less than 210 then the name of the song along with its duration is displayed on the output screen.

For example if the album name is Anonymous and the songs name along with their duration are:

ABC 400

XYZ 123

CDE 300

GHI 200

KLM 100

Then the above program displays the following output when the user types "quit" after entering the above information.

Anonymous                                                                              

Songs shorter than 210 seconds:                                                                        

XYZ - 123                                                                                                              

GHI - 200                                                                                                              

KLM - 100

Notice that the song name ABC and CDE are not displayed because they exceed the songDuration i.e. 210.

The output is attached.

3 0
3 years ago
The color shown here, a pure green, is most likely to have which RGB value?
erastova [34]

Answer:

D.

Explanation:

Its pure green, and RGB means Red, Green, Blue.

7 0
2 years ago
Read 2 more answers
Q)What software application is the most effective tool to create charts of data? *
san4es73 [151]

Answer:

b) spreadsheet software

4 0
3 years ago
Other questions:
  • Joanna accidentally leaned on her keyboard and repeatedly typed the letter z. How can she fix this mistake?
    6·2 answers
  • Phase 1 RequirementsCode submitted for Phase 1 will only have the following capability. Any additional coding will result in the
    13·1 answer
  • How do I make my own extension for chrome?
    7·1 answer
  • Employees at the Red Bluff Golf Club &amp; Pro Shop have the opportunity to become certified trainers if they log enough hours.
    13·1 answer
  • Create a method remove Evens that removes all even elements from an ArrayList of
    7·1 answer
  • The _________ attack exploits the common use of a modular exponentiation algorithm in RSA encryption and decryption, but can be
    10·1 answer
  • What is the output of the code?
    15·1 answer
  • PLEASE HELP ITS CODING AND I INCLUDED A SCREENSHOT OF WHAT TO DO
    14·1 answer
  • Which of the following activities do not involve Information technology​
    6·1 answer
  • What I Can Do
    15·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!