Question
c++. please show screenshots of output
This project will continue to familiarize the student with using arrays. Store all the function proto-types in project11_func
0 0
Add a comment Improve this question Transcribed image text
Answer #1

Enter value in between 1 and 100: 10 Enter a value: 3 13 16 27 25 23 25 16 12 9 1 1 9 12 13 16 16 23 25 25 27 - + - - - - - -

project11.cpp

#include "project11_func.cpp"

int main(int argc, char const *argv[])
{
int p[100];
int N, M;
cout<<"Enter value in between 1 and 100: ";
cin>>N;
cout<<"Enter a value: ";
cin>>M;
fill_array(p,N);
print_array(p,N,M);
insertion_sort(p,N);
for(int i=0;i<N;i++)
cout<<p[i]<<" ";
cout<<endl;
print_search_result(p,N);
return 0;
}

WNE #include projectll_fund.cpp int main(int argc, char const *argv[]) int p[100); int N, M; cout<<Enter value in between

project11_func.cpp

#include "project11_func.h"
#include <iostream>
using namespace std;

void fill_array(int array[], int N){
for(int i=0;i<N;i++){
array[i] = rand() % (3*N);
}
}

void print_array(int array[], int N, int M){
int b=0;
for(int i=0;i<N;i++){
if(b==M){
cout<<endl;
b=0;
}
cout<<array[i]<<" ";
b++;
}
cout<<endl;
}

void insertion_sort(int array[], int N){
int i, key, j;
for (i = 1; i < N; i++)
{
key = array[i];
j = i - 1;
while (j >= 0 && array[j] > key)
{
array[j + 1] = array[j];
j = j - 1;
}
array[j + 1] = key;
}
}

int linear_search(int array[], int N, int element){
for(int i=0; i<N;i++){
if(array[i] == element)
return i;
}
return -1;
}

void print_search_result(int array[], int N){
for(int i=0; i<=3*N;i++){
if(linear_search(array,N,i)==-1)
cout<<"-";
else
cout<<"+";
}
cout<<endl;
}

#include projectll func.h #include <iostream> using namespace std; void fill array(int array[], int N) { for(int i=0;i<N;i+

if(array[i] == element) return i; return -1; void print_search_result(int array[], int N) { for(int i=0; i =3 N;i++){ if(line

project11_func.h

void fill_array(int array[], int N);
void print_array(int array[], int N, int M);
void insertion_sort(int array[], int N);
int linear_search(int array[], int N, int element);
void print_search_result(int array[], int N);

2 void fill array(int array[], int N); void print array(int array[], int n, int M); void insertion sort(int array[], int N);

Add a comment
Know the answer?
Add Answer to:
c++. please show screenshots of output This project will continue to familiarize the student with using...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • The purpose of this assignment is to familiarize you with sort algorithms. Problem Description is as follows: 8. Search Benchmarks Write a program that has at least 20 250 integers stored in an ar...

    The purpose of this assignment is to familiarize you with sort algorithms. Problem Description is as follows: 8. Search Benchmarks Write a program that has at least 20 250 integers stored in an array in ascending order. It should call a function that uses the linear search algorithm to locate one of the values. The function should keep a count of the number of comparisons it makes until it finds the value. The program then should call a function that...

  • I am having problems getting the insertion sort function to output in descending order. Also, the...

    I am having problems getting the insertion sort function to output in descending order. Also, the initialize array function is not being called when I test it in the main function. I am wondering why it prints out the original array instead of initializing. Thank you. #include <stdio.h> void print_array(int *array, int length){ int i; for(i=0; i<length;i++) printf("%d"",",array[i]); printf("\n"); } void initialize_array(int *array, int length){ int i; for(i=0, i<length; i++;){ if (i%2 ==0) array[i]= 5; else array[i]= 0; } }...

  • The purpose of this assignment is to familiarize you with sort algorithms. Problem Description is as follows: 8. Search Benchmarks Write a program that has at least 20 250 integers stored in an ar...

    The purpose of this assignment is to familiarize you with sort algorithms. Problem Description is as follows: 8. Search Benchmarks Write a program that has at least 20 250 integers stored in an array in ascending order. It should call a function that uses the linear search algorithm to locate one of the values. The function should keep a count of the number of comparisons it makes until it finds the value. The program then should call a function that...

  • JAVA Objectives: 1. Apply linear search algorithm 2. Apply select sort algorithm 3. Apply array iteration...

    JAVA Objectives: 1. Apply linear search algorithm 2. Apply select sort algorithm 3. Apply array iteration skill Problem description: Write the following eight methods and write a main function to test these methods // return the index of the first occurrence of key in arr // if key is not found in arra, return -1 public static int linearSearch(int arr[], int key) // sort the arr from least to largest by using select sort algorithm public stati void selectSort(int arr[])...

  • Write a program that will do the following. The main function should ask the user how...

    Write a program that will do the following. The main function should ask the user how many numbers it will read in. It will then create an array of that size. Next, it will call a function that will read in the numbers and fill the array (fillArray). Pass the array that was made in themain function as a parameter to this function. Use a loop that will read numbers from the keyboard and store them in the array. This...

  • Write a java program to sort arrays using 3 different methods: Bubble Sort, Selection Sort and...

    Write a java program to sort arrays using 3 different methods: Bubble Sort, Selection Sort and Insertion Sort. The numbers to be sorted will be obtained using a library function which generates pseudo-random numbers. TO Do 1. Fill an array with 140 real numbers between 0.00 and 945.00. Generate the numbers using the subroutine that generates random numbers. Make a spare copy of the array; you will need it later. 2. Call a subroutine to print the contents of the...

  • Language C++ (Please include a short description & Screenshot of output) Implement a Priority...

    Language C++ (Please include a short description & Screenshot of output) Implement a Priority queue using a SORTED list. Use Quick sort after adding a new node. Example of quick sort below. Adopt to your program the code below. #include <iostream> void quickSort(int a[ ], int first, int last); int pivot(int a[], int first, int last); void swap(int& a, int& b); void swapNoTemp(int& a, int& b); void print(int array[], const int& N); using namespace std; int main() { int test[]...

  • 7eatng that function Write a C++ program that does the following: Fill an array of 123...

    7eatng that function Write a C++ program that does the following: Fill an array of 123 elements using srand) and rand) with random numbers between 150 and 667. Fill an array of 123 elements with random numbers between 150 and 667. Using a loop. Fill an array of 123 elements with random numbers between 150 and 667. Using a for loop Use a void function to fill an array of 123 elements with random numbers between 150 and 667, Possible...

  • 4 Exercise: Arrays and Functions Many of the tasks from the previous exercises can be generalized...

    4 Exercise: Arrays and Functions Many of the tasks from the previous exercises can be generalized to functions, allowing easy reuse. Recall that arrays in C are essentially represented by pointers, so when an array is passed into a function, the function is given access to the original array data (not a copy). This means that arrays are effectively passed by reference in C, and therefore that functions must be careful not to modify the contents of arrays they receive...

  • COMP1410 - Lab Exercises #3 (Due at the end of the lab period or beginning of...

    COMP1410 - Lab Exercises #3 (Due at the end of the lab period or beginning of the next) Start Date: Oct. 1st, 2019 Objectives: Practice dealing with 2D arrays. Create a two dimensional array (e.g. int A2D[M] [N] ;) of size MXN to store integer values. Use #define M 4 and N 3 to start. (Using symbolic constants instead of hard coding the array sizes improves scalability). Create an interactive menu within main() for this program (call it Lab3.c) with...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT