Question

In: Computer Science

*Answer must be in C++ and please use a Windows machine NOT IOS! Write a program...

*Answer must be in C++ and please use a Windows machine NOT IOS!

Write a program as follows:

Ask the user for an integer representing a number of integers to be sorted.

Create an array of integers of the size provided by user.

Initialize the array to zeros.

Ask the user for and populate the array with user input.

Output the array elements on one line separated by a space.

Write a function name “supersort” that takes an integer pointer for the starting memory address of an array and an integer variable representing the number of elements in that array. The function should sort the array elements from low to hi when called.

Output the array elements again in main after the function supersort is called.

Solutions

Expert Solution

source code of the above question

#include<iostream.h>

void supersort(int*,int); //function prototype
// Driver code
int main()
{
int n,i,Arr[20],*Ptr;
   cout<<"enter the number of integers to be sorted";
   cin>>n;
   for(i=0;i<n;i++)
Arr[i]=0; // initializing the array to 0;
   cout<<"enter the elements into array" ;
   for (i=0;i<n;i++)
   cin>>Arr[i];           //entering intigers to array
   Ptr=Arr;
   supersort(Ptr,n);        //function calling using pointer to array
  
   //    print the elementss of array
   cout<<"the array elements after sorting are"<<endl;
   for (i = 0; i < n; i++)
cout<<" "<<Arr[i];
  
return 0;
}
// sorting the numbers using pointers in a userdefined function
void supersort( int* p,int n)
{
int i, j, t;
  
// Sort the numbers using pointers
for (i = 0; i < n; i++)
{
for (j = i + 1; j < n; j++)
   {   
if (*(p+j) < *(p+i))
           {   
t = *(p+i);
*(p+i) = *(p+j);
*(p+j) = t;
   }
}
}

}

screen shot of the above program given below

result after the execution of the program given below

(press alt+f5 to see the output of the program in turbo c++ compiler after running the program)


Related Solutions

use linux or c program. please provide the answer in details. Write a program that will...
use linux or c program. please provide the answer in details. Write a program that will simulate non - preemptive process scheduling algorithm: First Come – First Serve Your program should input the information necessary for the calculation of average turnaround time including: Time required for a job execution; Arrival time; The output of the program should include: starting and terminating time for each job, turnaround time for each job, average turnaround time. Step 1: generate the input data (totally...
CODE MUST BE IN C++ (please use for loop) write a program that loops a number...
CODE MUST BE IN C++ (please use for loop) write a program that loops a number from 1 to 10 thousand and keeps updating a count variable (count variable starts at 0 ) according to these rules: n1 = 14 n2 = 54 n3 = 123 if the number is divisible by n1, increase count by 1 if the number is divisible by n2, increase count by 2 if the number is divisible by n3, increase count by 3 if...
Code in C# please. Write a program that will use the greedy algorithm. This program will...
Code in C# please. Write a program that will use the greedy algorithm. This program will ask a user to enter the cost of an item. This program will ask the user to enter the amount the user is paying. This program will return the change after subtracting the item cost by the amount paid. Using the greedy algorithm, the code should check for the type of bill. Example: Cost of item is $15.50 User pays a $20 bill $20...
C++ code Write a program to illustrate how to use the temporary class. Your program must...
C++ code Write a program to illustrate how to use the temporary class. Your program must contain statements that would ask the user to enter data of an object and use the setters to initialize the object. Use three header files named main.cpp, temporary.h, and temporaryImp.cpp An example of the program is shown below: Enter object name (rectangle, circle, sphere, or cylinder: circle Enter object's dimensions: rectangle (length and width) circle (radius and 0) sphere (radius and 0) rectangle (base...
Program must be in C++! Write a program which: Write a program which uses the following...
Program must be in C++! Write a program which: Write a program which uses the following arrays: empID: An array of 7 integers to hold employee identification numbers. The array should be initialized with the following values: 1, 2, 3, 4, 5, 6, 7. Hours: an array of seven integers to hold the number of hours worked by each employee. payRate: an array of seven doubles to hold each employee’s hourly pay rate. Wages: an array of seven doubles to...
Write an assembly language program that corresponds to the following C program ****Please give correct answer...
Write an assembly language program that corresponds to the following C program ****Please give correct answer using Pep/9 machine**** int num1; int num2; ;int main () { scanf("%d", &num1); num2 = -num1; printf("num1 = %d\n", num1); printf("num2 = %d\n", num2); return 0; }
Please write a program in c++ The method sellProduct of the Juice Machine programming example gives...
Please write a program in c++ The method sellProduct of the Juice Machine programming example gives the user only two chances to enter enough money to buy the product. Rewrite the definition of the method sellProduct so that it keeps prompting the user to enter more money as long as the user has not entered enough money to buy the product. Also, write a program to test your method. Your program should produce the following example output: *** Welcome to...
Please if you are able to answer the question below: Write C++ program using native C++...
Please if you are able to answer the question below: Write C++ program using native C++ (you can use STL)  that produces Huffman code for a string of text entered by the user.  Must accept all ASCII characters.  Pleas explain how you got frequencies of characters, how you sorted them, how you got codes.
please write it in printf and scanf please Please write it in c# program please and...
please write it in printf and scanf please Please write it in c# program please and if possible no arrays only loops Loop Introduction Assignment Using the conditions below, write one program that calculates a person’s BMI. Your main() function will call functions 1, 2, and 3. Your program will contain three functions: Function #1: Will ask the user for their weight in pounds and their height in inches. Your function will convert the weight and height into Body Mass...
Please Write C++ PROGRAM : That will write a program that initially prompts the user for...
Please Write C++ PROGRAM : That will write a program that initially prompts the user for a file name. If the file is not found, an error message is output, and the program terminates. Otherwise, the program prints each token in the file, and the number of times it appeared, in a well formatted manner. To accomplish all this, do the following: - Open the file - the user must be prompted and a file name input. DO NOT hardcode...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT