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
I made a fish emoji what do you think &gt;{'_'}&lt; should I change anything
Anvisha [2.4K]

Answer: It is beautiful

Explanation:

3 0
3 years ago
Read 2 more answers
Qual parâmetro é usado é usado na query sql para a presentar os dados em ordem decrescente?Leitura Avançada
nikitadnepr [17]

Answer:

gg

Explanation:

gg

4 0
3 years ago
The UNIX operating system started the concept of socket which also came with a set of programming application programming interf
VMariaS [17]

Answer:

(a). as the combination of IP address and port number to allow an application within a computer to set up a connection with another application in another computer without ambiguity.

Explanation:

The explanation is in the answer.

3 0
3 years ago
After you use the create sequence statement to create a sequence, you can use the _______________________ pseudo column to get t
user100 [1]

After you use the create sequence statement to create a sequence, you can use the NEXTVAL  pseudo column to get the next value in the sequence.

<h3 /><h3>How do you create a sequence?</h3>
  • You must have the Create any sequence system privilege to create a sequence in another user's schema.
  • Specify the schema that will hold the sequence.
  • If you leave out schema, Oracle Database will create the sequence in your own schema. Name the sequence that will be created.
  • Pseudo-columns allow selection, but you cannot edit, update, or remove their values.
  • A pseudo-column is analogous to a function that does not accept any inputs. This section goes over the two pseudo-columns, CURRVAL and NEXTVAL.
  • A pseudo column is a "column" that displays a value when a value is selected but is not one of the table's true columns.
  • Two examples are SysDate and RowID. It is frequently used in tandem with the DUAL table.
  • After you utilize the make sequence statement to make a sequence, you can utilize the NEXTVAL pseudo column to obtain the next value in the sequence.

To learn more about NEXTVAL, refer to:

brainly.com/question/13043887

#SPJ4

3 0
1 year ago
When purchasing a security program, you must make sure that _____. Select 2 options.
olganol [36]

Answer:

it is complex

employees are not involved

4 0
3 years ago
Other questions:
  • Which of the following are characteristics of a good webmail message select all that apply
    14·1 answer
  • This type of connection uses radio waves to connect devices on a network.
    15·2 answers
  • The establishment called ABC Enterprise requires a Java program to keep a database of the inventory of the products that it sell
    8·1 answer
  • Assume that another method has been defined that will compute and return the student's class rank (Freshman, Sophomore, etc). It
    8·1 answer
  • Your essay is due tomorrow and you don't have time to write it. You decide to buy an essay online. You've paid for it, so it can
    8·1 answer
  • In preparing his persuasive presentation, Reza should most likely focus on clearly presenting his
    6·2 answers
  • Which US electronics company was the pioneer in home video game consoles
    10·1 answer
  • Assume that the message M has to be transmitted. Given the generator function G for the CRC scheme, calculate CRC. What will be
    15·1 answer
  • Im drinking coffee. and working on school and watching a show. Whos with me?
    9·1 answer
  • ________ programs help solve the problem of running out of storage space by providing lists of application programs, stored vide
    13·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!