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
Gekata [30.6K]
4 years ago
6

Implement a function which takes as input an array and a key and updates thearrayso that all occurrencesof the input key have be

en removed and the remaining elements have been shifted left to fill the emptied indices. Return the number of remaining elements. There are no requirements as to the values stored beyond the last valid element.
Computers and Technology
1 answer:
Eduardwww [97]4 years ago
6 0

The function in cpp language is given.

void shift(int n[], int num)

{

   // integer variable to keep count of remaining elements

    int count=10;

     

   for(int j=0; j<10; j++)

   {

      // key element is compared to each element in the array

       if(n[j] == num)

       {

           n[j] = n[j+1];

          // decremented after each occurrence of key element in the array

           count--;

       }

   }

   

   std::cout<<count<<" elements are remaining out of 10 elements "<<std::endl;

   

}

1. The method accepts two parameters, one array and one element.

2. The integer array, arr, and integer element, key, passed to this function are declared outside all the methods.

3. The integer variable, count, is initialized to the size of the integer array, i.e., count contains the number of elements present in the array, arr.

4. Inside the for loop, the element is compared with each element in the array. If they match, the integer variable, count, is decremented each time the element occurs in the array.

5. After the loop completes, the number of remaining elements are displayed.

This function is implemented inside a cpp program as shown below.

#include <stdio.h>

#include <iostream>

// integer array declared and initialized

int arr[10] = {1, 2, 3, 4, 5, 6, 7, 2, 8, 2};

   

// element to be removed from the array

int key = 2;

   

   

void shift(int n[], int num)

{

   // integer variable to keep count of remaining elements

    int count=10;

     

   for(int j=0; j<10; j++)

   {

       if(n[j] == num)

       {

           n[j] = n[j+1];

           count--;

       }

   }

   

   std::cout<<count<<" elements are remaining out of 10 elements "<<std::endl;

   

}

int main()

{

   // function called having array and key as parameters

   shift(arr, key);

   return 0;

}

The program begins when the array and the element are declared and initialized at the beginning of the program.

Inside the main() method, the method shift() is called by passing two parameters to this method.

The main() method has return type of integer. Hence, this program ends with a return statement.

You might be interested in
In a computer-controlled greenhouse, a temperature sensor and a window motor are connected to the computer.
GrogVix [38]
Hope this helps solve it

8 0
3 years ago
SP 800-14, Generally Accepted Principles and Practices for Securing Information Technology Systems, provides best practices and
Alika [10]

Answer:

blueprint.

Explanation:

Generally Accepted Principles and Practices for Securing Information Technology Systems, provides best practices and security principles that can direct the security team in the development of a security blueprint.

3 0
3 years ago
Read 2 more answers
Write a short-essay discussing your own stand on social media usage for students.​
hjlf

Answer:

More than half of the world’s population uses the internet. This is highlighted by social media users increasing by 21% since 2015, with 2.8 billion users reported globally in 2017.

Humans are social animals. We always like to remain in some group or another, and we prefer to follow what this group does. All of our traditions and cultures are the product of <em><u>this</u></em> group-oriented facet of human nature.Everyone is connected to one another in this vast network generated by the Internet.It illuminates the lives of thousands of people by spreading knowledge internationally, thereby making us global citizens. 

<h2><em><u>NOT</u></em><em><u> </u></em><em><u>COPIED</u></em><em><u> </u></em><em><u>ANSWER</u></em><em><u> </u></em></h2>
3 0
3 years ago
For this step, submit your work in the programming environment by
Tems11 [23]

Answer:

is there some oppsense you can choose from

7 0
3 years ago
A thick black line around the outside edge of a page is a _____.
Montano1993 [528]
B. Border. It borders the outer page.
7 0
3 years ago
Read 2 more answers
Other questions:
  • A 2-dimensional 3x3 array of ints, has been created and assigned to tictactoe. Write an expression whose value is true if the el
    10·1 answer
  • Help! live preview in brackets is not working
    8·1 answer
  • what type of clause must you always use with DEKETE or UPDATE to avoid inadvertently changing data elsewhere in the database​
    12·1 answer
  • Create a structure named planet This structure will contain distance from Earth as an integer Atmosphere, language, people and p
    8·1 answer
  • An instruction book or program that takes users through a prescribed series of steps to learn how to use a program is called (a)
    10·1 answer
  • Tạo thủ tục có tên _Pro04 để trả về số lượng tổng thời gian tham gia dự án Y của nhân viên có mã số X, với X là tham số đầu vào,
    5·1 answer
  • 8.10 quiz edhesive A swap is: a variable used to find the smallest value in an array an algorithm used to find a value in an arr
    12·1 answer
  • 8
    7·1 answer
  • Try to crack the code:
    14·1 answer
  • Modern life is not possible if computer stops working? Give your opinion<br>​
    7·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!