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
Which category best represents: a student sends harassing emails to another student. The receiving student retaliates with a "fl
Dima020 [189]
It is considered C. cyber bullying
3 0
3 years ago
Read 2 more answers
Define storage device with two examples? ​
Vlad [161]

Answer:

Hehe!

Explanation:

Storage Device is a technology consisting of computer components and recording media that are used to retain digital data. It is a core function and fundamental component of computers. The central processing unit of a computer is what manipulates data by performing computations.

Examples: Hard disk and Floopy Disk.

7 0
2 years ago
Read 2 more answers
Which of the following is an example of synchronous communication?
kirza4 [7]

The answer is D) on Oddessey Ware

4 0
3 years ago
What is the primary purpose of the destination address?
ehidna [41]

Answer:

The answer to this question is given below is the explanation section.

Explanation:

"A" option is correct

    It helps the router know where to send the packet.

4 0
3 years ago
Find functions f1 and f2 such that both f1 and f2 are O(g(n)), but f1(n) is not O(f2)
MakcuM [25]

Answer:

I dont think I can answer this

6 0
3 years ago
Other questions:
  • As part of his proofreading process, and to catch any spelling or grammar mistakes, John uses this feature in Word Online to hav
    7·1 answer
  • Which animation effects allow text or images to show movement on a slide? Check all that apply. Entrance, Emphasis, Exit, Motion
    5·2 answers
  • A is a paid placement that appears in a search engines results page at or near the top of the results
    5·1 answer
  • Aiming high means???
    6·1 answer
  • Determine if x(t) is periodic and determine the fundamental period.
    15·1 answer
  • Which of the following is NOT one of the three basic structures used to solved logical problems?
    7·1 answer
  • Write python code that does the following: Ask the user to enter as many as number they want; Then find the sum and the average
    10·1 answer
  • If you want the input gear to spin in the same direction as the output gear you must use a _______ gear.
    13·1 answer
  • what is the importance of familiarizing and understanding the cells rows and format tools in the microsoft cell​
    9·1 answer
  • Explain briefly how learning how to follow can make a person a good leader
    5·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!