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
Bogdan [553]
2 years ago
8

Assume you are given a boolean variable named isNegative and a 2-dimensional array of ints that has been created and assigned to

a2d. Write some statements that assign true to isNegative if more integer elements in entire 2-dimensional array are negative than not.
Computers and Technology
1 answer:
Anon25 [30]2 years ago
5 0

Answer:

#include <iostream>

using namespace std;

int main(){

   int rows, cols;

   bool isNegatives;

   cout<<"Rows: ";

   cin>>rows;

   cout<<"Columns: ";

   cin>>cols;

   int a2d[rows][cols];

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

   for(int j =0;j<cols;j++){

       cin>>a2d[i][j];}    }

   int negatives, others = 0;

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

   for(int j =0;j<cols;j++){

       if(a2d[i][j]<0){

           negatives++;}

       else{

           others++;}}    }

   if(negatives>others){

       isNegatives = true;}

   else{

       isNegatives = false;}

   cout<<isNegatives;  

   return 0;

}

Explanation:

For clarity and better understanding of the question, I answered the question from the scratch.

This line declares number of rows and columns

   int rows, cols;

This line declares the Boolean variable

   bool isNegatives;

This line prompts user for rows

   cout<<"Rows: ";

This line gets the number of rows

   cin>>rows;

This line prompts user for columns

   cout<<"Columns: ";

This line gets the number of columns

   cin>>cols;

This line declares the array

   int a2d[rows][cols];

This line gets user input for the array

<em>    for(int i =0;i<rows;i++){</em>

<em>    for(int j =0;j<cols;j++){</em>

<em>        cin>>a2d[i][j];}    }</em>

This line declares and initializes number of negative and others to 0

   int negatives, others = 0;

The following iteration counts the number of negatives and also count the number of non negative (i.e. others)

<em>    for(int i =0;i<rows;i++){</em>

<em>    for(int j =0;j<cols;j++){</em>

<em>        if(a2d[i][j]<0){</em>

<em>            negatives++;}</em>

<em>        else{</em>

<em>            others++;}}    }</em>

This checks of number of negatives is greater than others

   if(negatives>others){

If yes, it assigns true to isNegatives

       isNegatives = true;}

   else{

If otherwise, it assigns false to isNegatives

       isNegatives = false;}

This prints the value of isNegatives

   cout<<isNegatives;  

<em>See attachment</em>

Download cpp
You might be interested in
Write a valid HTML + Python page that will count numbered from 1 to 1,000,000?​
valentinak56 [21]

Answer:

I remember before the corona virus we used to do math at school

8 0
3 years ago
______ is data that is entered into a computer. ______ is the result produced by a computer.
Umnica [9.8K]
Input
Output
(Sorry for not being detailed)
5 0
2 years ago
Edhesive 11.1 lesson practice please
zloy xaker [14]

Answer:

1. Bits

2. Bitrate

3. The amount of time it takes for bits to travel from one place to another.

4. Used to send bits wirelessly.

5. Cables that carry light and dramatically increase the speed and accuracy of information over the internet.

6. 8

7. The number of bits per second a system can transmit.

Explanation:

hey lol

3 0
2 years ago
In the legend of sleeping Hallow what does Ichabod Crane fear the most
ahrayia [7]

Ichabod Crane is terrified of the headless horsemen

3 0
3 years ago
Read 2 more answers
For a class Foo, one difference between a variable declared Foo * and a variable declared Foo &amp; is that only the variable de
Studentka2010 [4]

Answer:

False.

Explanation:

When we declare a variable as reference type we have to initialize that variable otherwise the compiler will give error that the reference variable is not initialized.You also cannot initialize the variable Foo& with NULL value because it is a reference variable and we have to initialize it.

On the other there is no need to initialize the variable Foo * since it is a pointer it can also store NULL value.

So the answer is only Foo* can store NULL value not Foo &.

5 0
3 years ago
Other questions:
  • 1. What is the difference between a learner’s license and an operator’s license?
    10·1 answer
  • Blank includes websites that encourage interaction and connection among people ,business and organizations
    13·1 answer
  • Before measuring resistance of a component, be sure:
    8·1 answer
  • Type the correct answer in the box. Spell all words correctly.
    15·2 answers
  • A desktop computer (named workstation22) can’t connect to the network. A network card was purchased without documentation or dri
    15·1 answer
  • What is motivation and state the two forms​
    14·1 answer
  • Windows displays a(n)
    11·1 answer
  • Suppose that the first goal in a GP problem is to make 3 X1 + 4 X2 approximately equal to 36. Using the deviational variables d1
    15·1 answer
  • Is pseudocode obtained from Algorithm or is Algorithm obtained from pseudocode?
    8·1 answer
  • Which is the fastest memory in computer​
    9·2 answers
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!