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
8_murik_8 [283]
3 years ago
10

(1) Precursor to Array ...a Sorting Program: Write a modular program with a function named sort that takes three integer paramet

ers by reference. The function should rearrange the parameter values so that the first parameter gets set to the largest value, the second parameter gets set to the second largest value, and the third parameter gets set to the smallest value. For example, let's say in the main function we are given the variable assignments num1 = 20; num2 = 10; num3 = 30; then the function call sort(num1,num2,num3) should result in the following changes to the variables in the main function: num1 = 30, num2 = 20, and num3 = 10. Note that although the array construct covered in Chapter 7-8 supports a way to solve this type of problem for an arbitrary number of items instead of only for three items, DO NOT use an array for this programming challenge.
Computers and Technology
1 answer:
olga2289 [7]3 years ago
8 0

Here is code in C++.

#include <bits/stdc++.h>

// include header

using namespace std;

// function to rearrangement the numbers

void Sort(int& i, int& j, int& k)

// values are passed by reference

{

 // first parameter gets largest value

   if(i<j){

       // swap the value of i & j

       int tmp = i;

       i = j;

       j = tmp;

   }

   //second parameter gets second largest value

   if(i<k){

       // swap the value of i & k

       int tmp = i;

       i=k;

       k = tmp;

   }

   //third parameter gets smallest value

   if(j<k){

       // swap the value of k & j

       int tmp = j;

       j=k;

       k=tmp;

   }

}

// driver function

int main() {

cout << "Enter three integers: " << endl;

   // declaring 3 variables

   int num1,num2,num3;

   // reading the input

   cin >> num1 >> num2 >> num3;

   // calling the function

   Sort(num1,num2,num3);

   // printing the numbers after rearrangement

   std::cout<<"Numbers after rearrangement: \n"<< num1 << " " << num2 << " " << num3 << std::endl;

// main ends here

return 0;

}

Explanation:

First reading three integer in three different variables namely "num1","num2" and "num3".Pass these variable by reference in the function "sort()". There after comparing value of these three, largest value is assigned to num1, second largest value assigned to num2 and smallest value assigned to num3. Then it will print these value.

Output:

Enter three integers:

20 10 30

Numbers after rearrangement:

30 20 10

You might be interested in
Look at the code below. What does it do?
yulyashka [42]

Answer:

3- The code takes in an input, turns it into an integer and then multiplies it by 2 and prints it

Explanation:

Look- First, the code snippet asks for an input (int or float) as "Rawheight".

Aftewards, it converts the input into an integer numeral(if it was a float) and multiplies it by 2.

This processed value is, then, further transferred to the variable "double_height" and is thereafter rendered on the user's virtual screen.

5 0
2 years ago
What is the Median Pay of Advertising, Promotions, or Marketing Managers?
NemiM [27]

Answer:

it is 125.510$ per yr but try B see if its correct

6 0
3 years ago
Read 2 more answers
Look at the following assignment statements: food1 = "water" food2 = "melon" What is the correct way to concatenate the strings?
Ilia_Sergeevich [38]

Programming language in R studio or R, food1 = "Water" food2 = "Melon"

Concatenate = paste("food1","food2"), will give  "Water Melon". In excel Water in range("B2"), Melon in range("B3"), use =CONCATENATE(B2, " ", C2) it gives Water Melon.

Explanation:

  • R studio is analytical tool which comes from programming S language.
  • We need 3 variable Food1,Food2 and Concatenate in R studio.
  • Food1 = "Water" inverted commas mean it is character.
  • Food2 = "Melon" inverted commas mean it is a character.
  • "=" gives a variable notification.
  • Concatenate is a variable which we use function paste .
  • Concatenate = paste(food1,food2) result "water melon"
  • paste(..., sep = "" , collapse = Null)
  • It is function from R.
  • Excel Water in B2 and Melon in C2 use the formula concatenate.
  • =CONCATENATE(B2, " ",C2) in between commas means space.
5 0
3 years ago
/*
Kruka [31]

Answer:

C++.

Explanation:

Dynamic array consists of a pointer that, by default, points to the first element of the array. If the array name is foo, its first element's value can be accessed through foo[0] or *foo and foo[1] or *(foo + 1) and so on.

To find out if pointer ptr is pointing to any element of the intArray, we need to access each array element's address. We can do that by removing the asterisk from the element i.e. (foo + 1).

////////////////////////////////////////////////////////////////////////////////////

int withinArray(int * intArray, int size, int * ptr) {

    for (int i = 0; i < size; i++) {

       if (ptr == (intArray + i)) {

           return 1;

       }

   return 0;

}

4 0
4 years ago
If you play video games, please answer these questions it’s for a survey!!
Zinaida [17]

Hey buddy, I am there to help!

1. For entertainemnt purposes and stress releive and to take out my frustration

2. I play battle royale games, multi games and creative building games!

3. since 2 years

4. they will make all video games into real life experiences and better quality with more 4d interaction

5. yes

4 0
3 years ago
Read 2 more answers
Other questions:
  • What doe the &amp; operator do in python programming software
    9·1 answer
  • A structure that specifies which of a number of permitted data types (e.g. integers) that may be stored in its instances is:
    6·1 answer
  • James, a technician, needs to format a new drive on a workstation. He will need to configure read attributes to specific local f
    5·1 answer
  • Write a program that uses for loops to perform the following steps: Prompt the user to input two integers: firstNum and secondNu
    15·1 answer
  • I wrote a program to calculate how many unique students I have taught over the years. It will read in a file formatted with firs
    5·1 answer
  • By default the normal style inserts a vertical space equal to _____ lines between each line of text
    9·1 answer
  • The biggest limitation of a network operating system (NOS) is _____ in terms of memory, process, device, and file management.
    7·1 answer
  • What is the purpose of the website directory provided by the website host?
    5·1 answer
  • Write a static method called split that takes an ArrayList of integer values as a parameter and that replaces each value in the
    12·1 answer
  • When you ____ an exception, you send a message that an error has occurred to another part of the program.
    7·2 answers
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!