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]
3 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]3 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
Students who interact online with others from different cultures should remember that
aliya0001 [1]

Answer:

they are dealing with people, not computers.

8 0
4 years ago
Read 2 more answers
Which of the following is not a reason to choose a community college?
k0ka [10]
They do not make as big of a impression than a famous university when applying for jobs.
8 0
2 years ago
Who invent cars and who invent bikes and who invent pc
julia-pushkina [17]

Answer:

  • Cars were invented in 1886 by Karl Benz.
  • The term bicycle was coined in France in the 1860s, but The first verifiable claim for a practically used bicycle belongs to German Baron Karl von Drais in 1817
  • The first computer was by Charles Babbage, an English mechanical engineer and polymath he originated the concept of a programmable computer.

7 0
3 years ago
All linear programming problems have all of the following properties EXCEPT
lyudmila [28]

Answer:

alternative optimal solutions

Explanation:

8 0
4 years ago
Read 2 more answers
1. ¿Cuál es el papel de la voz en la radio?
MrRa [10]

Answer:

Locutor

Explanation:

Asi se llama el papel de la voz en la radio

Espero y te sirva :)

5 0
4 years ago
Other questions:
  • Which of the following attacks is MOST likely the cause when a user attempts to go to a website and notices the URL has changed?
    10·1 answer
  • To edit the text in a smartart graphic, what must be done first ?
    7·2 answers
  • Can someone help me with these questions on linear dimensions pls
    11·2 answers
  • Conduct online research on web authentication and define what it is. Describe different authentication methods
    5·1 answer
  • Which statement about comments is false? Select one: a. Lengthy comments can cause poor execution-time performance. b. Comments
    7·1 answer
  • How do you add a new comment to a document?
    14·1 answer
  • You are having difficulty changing permissions for a folder on an NTFS volume that was created by another user. How can you best
    6·1 answer
  • An articulated robot has a T-type wrist axis that can be rotated a total of 2 rotations (each rotation is a full 3600 ). It is d
    15·1 answer
  • I’m select circumstances is a permissible character on the Mac operating system
    11·1 answer
  • What do you mean by computer ethics?​
    9·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!