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
Briefly explain the cooling mechanism implemented in FANLESS Laptops
Akimi4 [234]

The primary function of a fan in a computer system is to cool down the internal components and prevent overheating. Fanless computers use alternative cooling methods and lower-powered components that give off less heat. As a result, these machines are quieter during operation, use less energy and are often more compact than fan-based computers. These advantages are particularly important in business settings.
8 0
3 years ago
Betsy loves her job. On a daily basis she problem-solves and uses her creative side to fix situations centered around setting up
vladimir2022 [97]
 
The answer would be an A/V Specialist, because Betsy is working with technical equipment on a TV set.
6 0
3 years ago
Read 2 more answers
According to a case study in one of our weekly chapter reading, nearly..................... percent of all employees send work e
ozzi

Answer:

A.80, and uncontrolled

3 0
3 years ago
Read 2 more answers
Gregor installed a third stick of known-good RAM into his Core i7 system, bringing the total amount of RAM up to 3 GB. Within a
MA_775_DIABLO [31]

Answer:

The speed or quality was different.

Explanation:

The new ram that he installed most likely had a different rate, or was a different quality than the old ram.

5 0
3 years ago
If you were describing system software for your car, what would be the functions of the system software?
Marat540 [252]
B would be the correct answer
7 0
2 years ago
Other questions:
  • Which device lets you hear audio on your computer?
    12·2 answers
  • Which of the following contains information about which keywords are bringing visitors to your website?
    8·1 answer
  • Bill downloaded an antivirus software from the Internet. Under the Uniform Commercial Code (UCC), the software is a: Select one:
    15·1 answer
  • Marissa, a 21-year-old young woman, is working as an intern at a software company. She has recently graduated from college. She
    6·1 answer
  • Who is the father of computer​
    12·2 answers
  • A franchise restaurant is attempting to understand if customers think their service is good day-to-day by summarizing a series o
    10·1 answer
  • Which of these statements regarding​ time-cost tradeoffs in CPM networks is​ true?
    6·1 answer
  • What is the value of |-10|
    6·1 answer
  • What is software piracy?
    11·1 answer
  • A real estate office handles 50 apartment units. When the rent is $600 per month, all the units are occupied. However, for each
    14·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!