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
VikaD [51]
2 years ago
9

Given a sorted array of integers created on the heap, its size and a new integer, design a function which will enlarge the array

and place the new item in the appropriate position in the array, so that it remains sorted. c++
Computers and Technology
1 answer:
Debora [2.8K]2 years ago
7 0

Using the computational language in C++ to write a code that will organize the values ​​in an array through a mathematical condition.

<h3>writing code in C++</h3>

<em>#include <bits/stdc++.h></em>

<em>using namespace std;</em>

<em>int getIndexInSortedArray(int arr[], int n, int idx)</em>

<em>{</em>

<em>/* Count of elements smaller than current</em>

<em>element plus the equal element occurring</em>

<em>before given index*/</em>

<em>int result = 0;</em>

<em>for (int i = 0; i < n; i++) {</em>

<em>if (arr[i] < arr[idx])</em>

<em>result++;</em>

<em>if (arr[i] == arr[idx] && i < idx)</em>

<em>result++;</em>

<em>}</em>

<em>return result;</em>

<em>}</em>

<em>int main()</em>

<em>{</em>

<em>int arr[] = { 3, 4, 3, 5, 2, 3, 4, 3, 1, 5 };</em>

<em>int n = sizeof(arr) / sizeof(arr[0]);</em>

<em>int idxOfEle = 5;</em>

<em>cout << getIndexInSortedArray(arr, n, idxOfEle);</em>

<em>return 0;</em>

<em>}</em>

See more about C++ at brainly.com/question/12975450

#SPJ1

You might be interested in
For a certain company, the cost function for producing x items is C(x)=50x+100 and the revenue function for selling x items is R
solmaris [256]

Assuming that this company sells all that it produces, the profit function would be given by P(x) = -0.5(x - 100)² + 5,000 - 50x - 100.

<h3>What is profit?</h3>

In Economics, profit can be defined as a measure of the amount of money (revenue) that is generated when the selling price is deducted from the cost price of a good or service, which is usually provided by producers.

This ultimately implies that, all producers generally work to maximize their profits and make them as large as possible, in order to enable them break even and successful.

Mathematically, the profit function P(x) of a business firm simply refers to the revenue function R(x) minus the cost function C(x):

P(x) = R(x) - C(x)

Where:

  • R(x) represents how much it takes in.
  • C(x) represents how much it spends.

Substituting the given parameters into the formula, we have;

P(x) = -0.5(x - 100)² + 5,000 - (50x + 100)

P(x) = -0.5(x - 100)² + 5,000 - 50x - 100

Read more on maximized profit here: brainly.com/question/13800671

#SPJ1

7 0
2 years ago
In which generation microprocessor was developed short answer of computer science​
3241004551 [841]

Explanation:

in fourth generation microprocessor was developed.

may it helped u

5 0
3 years ago
Suzy lives alone in New York, whereas her family lives in Florida. It is difficult for Suzy to visit her family very frequently,
Luda [366]
Answer:

<span>Skype.

---> Skype can most probably help Suzy given that the application allows for people to message, talk and video chat. This means that Suzy can see her family through video call, and see their face.

Best of wishes! xx :)</span>
4 0
3 years ago
Read 2 more answers
Here's something to stop you from getting repetitive when writing essays. Write a program that reads multiple lines of plain tex
Marianna [84]

Answer:

The output is attached below

Explanation:

d = {}

while True:

line = input("Enter line: ")

if len(line)==0:

break

token = line.split(' ')

for var in token:

try:

if len(var)==0:

continue

count = d[var]

d[var] = count + 1

except KeyError:

d[var] = 1

pass

for word in sorted(d):

print(word , d[word])

------------------

7 0
3 years ago
Why is it important to think about the programming language to use?
Sloan [31]
In think is C or B in my opinion
6 0
3 years ago
Other questions:
  • HELP NOW PLZZ/ Question: Complete the sentence with the correct response.
    11·1 answer
  • How do smart watches affect the business and its position in the global marketplace?
    12·2 answers
  • ______ means locating a file among a set of file​
    14·1 answer
  • What is the difference between Data and information?​
    7·1 answer
  • 3. Before you get ready to go diving, you want to explore the area. You see a small snowpack across a small bridge, a short walk
    11·1 answer
  • If a small monster collector:- Has 16 small monster containment devices and intends to use all of them.
    10·1 answer
  • Is this statement true or false?
    11·1 answer
  • What are the steps to view two different versions of the same document at once?
    11·1 answer
  • John has recently retired from an administrative, yet technical job which he held for 40 years. He decided to pursue a life-long
    11·1 answer
  • identify the difficulties with the k-nearest neighbor algorithm. a. both a and b b. calculate the distance of the test case from
    8·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!