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
expeople1 [14]
3 years ago
5

How many times will line 7 be executed when the following code is run?

Computers and Technology
1 answer:
cluponka [151]3 years ago
8 0

Answer:

4 times

Explanation:

Required.

How many times will line 7 be executed?

Line 2 initialises i to 0

Line 3 subtracts 1 from the length of "rebellion" , the result of the subtraction is then saved in J

So:

j = 9 - 1

j = 8

From line 2 and line 3, we have that:

i = 0 and j = 8

Line 4 is an iteration that is repeated as long as i is less than j

Line 7 will be executed, for the first time as: i < j because 0 < 8

i is incremented to 1 and j is reduced to 7

Line 7 is then executed again, the second time because 1 < 7

i is incremented to 2 and j is reduced to 6

Line 7 is then executed again the third time because 2 < 6

i is incremented to 3 and j is reduced to 5

Line 7 is then executed again the fourth time because 3 < 5

i is incremented to 4 and j is reduced to 4

At this stage, line 7 will no longer be executed because I is no longer less than as 4 = 4.

Hence, number of execution is 4 times

You might be interested in
Write a program that records high-score data for a fictitious game. the program will ask the user to enter five names, and five
Harman [31]

Scores.cpp

#include <iostream>

#include <string>

using namespace std;

void initializeArrays(string names[], int scores[], int size);

void sortData(string names[], int scores[], int size);

void displayData(const string names[], const int scores[], int size);

int main()

{

   string names[5];

   int scores[5];

   //reading names and scores

   initializeArrays(names, scores, 5);

   //sorting the lists based on score.

   sortData(names, scores, 5);

   //displaying the contents of both arrays

   displayData(names, scores, 5);

 

  return 0;

}

void initializeArrays(string names[], int scores[], int size){

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

       cout<<"Enter the name for score #"<<(i+1)<<": ";

       cin >> names[i];

       cout<<"Enter the score for score #"<<(i+1)<<": ";

       cin >> scores[i];

       }

}

void sortData(string names[], int scores[], int size){

   

       int temp = 0;

       string tempStr = "";

       

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

               for(int j=1; j < (size-i); j++){

                      //checking max score and sorting based on it.

                       if(scores[j-1]< scores[j]){

                               //swap the elements!

                           //swapping scores

                               temp = scores[j-1];

                               scores[j-1] = scores[j];

                               scores[j]=temp;

                               

                               //swapping names

                               tempStr = names[j-1];

                               names[j-1] = names[j];

                               names[j]=tempStr;

                       }

                       

               }

       }

}

void displayData(const string names[], const int scores[], int size){

   cout<<"Top Scorers:"<<endl;

       //printing the elements up to the size of both arrays.

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

           cout<<names[i]<<": "<<scores[i]<<endl;

       }

}

3 0
4 years ago
Define the term entity and give an example of an entity .
Norma-Jean [14]

Explanation:

This term is used in programming languages/concepts, database management, systems design, etc. It's defined as a singular, identifiable and separate object, a thing of interest to an organization, system or individual about which data is to be held. Each of these entities have attributes (properties or characteristics) and can be considered as separate wholes.

Some examples of entities are:

  • In a system: discrete or separate components
  • In general, users, components and organizations.

I hope you find this information useful and interesting! Good luck!

3 0
3 years ago
Inserting diagrams into documents can help readers better understand document text. True or False?
Masja [62]
It's true because you can get a better understanding when looking at the evidence.
4 0
3 years ago
Fill up the blank:- The picture that graphically represents the items you use in Windows is called a/an .......
vagabundo [1.1K]
The picture that graphically represents the items you use in Windows or any other OS is called an Icon. An icon is a picture that represents the program that is being used. An icon is useful for the user's to directly know what type of program they need to use or such.
8 0
3 years ago
The process of learning by making mistakes and by trial and error is called _____.
vodomira [7]
I believe it’s problem solving.
6 0
3 years ago
Other questions:
  • 4. The programmer who focuses on implementing the game mechanics, rules, and other elements essential for gameplay is the
    13·1 answer
  • What is a Web application?
    12·1 answer
  • When you hear or see the warning signal of any emergency vehicle, you should ________________.?
    14·1 answer
  • a) Write out an abstract class to represent a ball. Include data fields to store the weight of the ball as a double value and th
    6·2 answers
  • The concept of the internet was developed by the u.s. department of defense as a network that ________ in event of an attack.
    8·1 answer
  • I don't want my large video files using up all my hard drive space . Can I archive my videos in on DVDs or Blu Rays?
    8·1 answer
  • How do u mark bralienst
    5·1 answer
  • What code would you use to create the login button?
    11·1 answer
  • Select the correct answer.
    5·1 answer
  • What are the importance of rules in the computer lab ?​
    12·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!