Answer to Question #158923 in C++ for Ashes

Question #158923

Suppose that a bird watching club has collected data on the number of sightings of 20 different

bird species in each of 100 different cities. The data has been stored in an two dimensional array

as:

int sightings[20][100];

The value stored in sightings [i][j] is the number of times that a bird belonging to

species number i was sighted in city number j.

(i)

Write a code segment that will compute and print the total number of bird sightings for

city number 0, then for city number 1, and so forth, up to city number 99.

(ii)

Let's say that a species is endangered if it has been sighted in only 4 cities or fewer.

(Species number i was sighted in city number j if sightings[i][j] is greater than zero.) Write

a code segment that will print a list of all the species that are endangered. 


1
Expert's answer
2021-01-27T09:35:45-0500
1) 
for (int j = 0; j < 100; j++)
	{
		for (int i = 1; i < 20; i++)
		{
			sightings[0][j] += sightings[i][j];
		}
		cout << "For city number " << j << " total number of bird sightings: " << sightings[0][j] << endl;
	}
2)
int k[20];
	for (int j = 0; j < 20; j++)
	{
		k[j]=0;
	}
	for (int j = 0; j < 20; j++)
	{
		for (int i = 0; i < 100; i++)
		{
			if (sightings[j][i] > 0)
			{
				k[j] += 1;
			}
		}
		if (k[j] < 4)
		{
			cout << "The species " << j << " is threatened with extinction.\n";
		}
	}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog