C++
Create a function called countOccurences that will count how many times a certain number occurs in the array. The function should take an array, a size and a variable, which is what you are searching for.
Heres what I got so far:
#include <iostream>
#include <string>
#include <vector>
using namespace std;
void fillArray(int a[], int size);
void printArray(int a[], int size);
int countEvens(int ar[], int size);
int main()
{
int ar[10];
fillArray(ar, 10);
printArray(ar, 10);
int count = countEvens(ar, 10);
cout << "There are " << count << "
Even numbers in the array " << endl;
return 0;
}
void fillArray(int a[], int size)
{
for (int i = 0; i < 10; i++)
a[i] = rand() % 10 + 1;
}
void printArray(int a[], int size)
{
for (int i = 0; i < 10; i++)
cout << a[i] <<
"\n";
}
int countEvens(int ar[], int size)
{
int count = 0;
for (int i = 0; i < size; i++)
{
if (ar[i] % 2 == 0)
count++;
}
return count;
}
#include <iostream>
#include <string>
#include <vector>
using namespace std;
void fillArray(int a[], int size);
void printArray(int a[], int size);
int countEvens(int ar[], int size);
int countOccurences(int ar[], int size,int
key);
int main()
{
int ar[10];
fillArray(ar, 10);
printArray(ar, 10);
int count = countEvens(ar, 10);
cout << "There are " << count << " Even numbers
in the array " << endl;
int count2=countOccurences(ar,10,4);
cout << "There are " << count2 << " occurences of
4 in the array " << endl;
return 0;
}
void fillArray(int a[], int size)
{
for (int i = 0; i < 10; i++)
a[i] = rand() % 10 + 1;
}
void printArray(int a[], int size)
{
for (int i = 0; i < 10; i++)
cout << a[i] << "\n";
}
int countEvens(int ar[], int size)
{
int count = 0;
for (int i = 0; i < size; i++)
{
if (ar[i] % 2 == 0)
count++;
}
return count;
}
int countOccurences(int ar[], int size,int key)
{
int count = 0;
for (int i = 0; i < size; i++)
{
if (ar[i]==key)
count++;
}
return count;
}

C++ Create a function called countOccurences that will count how many times a certain number occurs...
15.6: Fix the code to print the count from 1 to x (to loop x times) #include <iostream> // include the header file using namespace std; void count(int x){ for(int i=1; i<=x; i++){ cout<<x; } } int main(){ int x,i; cin >> x; count(x); return 0; } 15.7 Fix the nested for loops to print the count from 1 to x twice, e.g. "12....x12.....x" #include <iostream> // include the header file using namespace std; int main(){...
Remove srand(time(NULL)); from this C++ code so that it still finds random numbers correctly. Then, Write a program that adds the following to the fixed code. • Add a function that will use the BubbleSort method to put the numbers in ascending order. – Send the function the array. – Send the function the size of the array. – The sorted array will be sent back through the parameter list, so the data type of the function will be void....
c++ /*This is the starter file for your final proficiency test This program has a function that will generate a list of integers using the rand function. Your job is to fill the insertNum and oddCount functions.*/ #include <iostream> #include <ctime> using namespace std; //constants and function prototypes const int CAP = 100; int buildList(int[], int size); void printList(int[], int size); //your functions to implement /*This function finds even numbers in the list, and inserts a number before the even...
C++, Will Upvote: A) Try to get the following programs to run in your environment. B) If the programs will run, document each line of code with comments and describe any changes you had to make to the original code to get it to work. If the programs are unable to be modified to run with desirable results, explain why you think so. C) Description your solution and a synopsis of how your code is intended to work and the...
I need help of how to include the merge sort code into this counter code found below: #include<iostream> using namespace std; int bubble_counter=0,selection_counter=0; // variables global void bubble_sort(int [], int); void show_array(int [],int); void selectionsort(int [], int ); int main() { int a[7]={4,1,7,2,9,0,3}; show_array(a,7); //bubble_sort(a,7); selectionsort(a,7); show_array(a,7); cout<<"Bubble counter = "<<bubble_counter<<endl; cout<<"Selection Counter = "<<selection_counter<<endl; return 0; } void show_array(int array[],int size) { for( int i=0 ; i<size; i++) { cout<<array[i]<< " "; } cout<<endl; } void bubble_sort( int array[],...
I have to type and explain in class each code in every detail filled with // commentary. Explains how does work in every codes. 1) What does the below print #include <iostream> using namespace std ; int main() { int var1 = 20 ; int var2 = 30 ; int* ptr1 ; int* ptr2 ; int* temp ; ptr1 = &var1 ; ptr2 = &var2 ; cout << *ptr1 << endl ;...
How can I write this code (posted below) using vectors instead of arrays? This is the task I have and the code below is for Task 1.3: Generate twenty random permutations of the number 0, 1, 2, ..., 9 using of the algorithms you designed for Task 1.3. Store these permutations into a vector and print them to the screen with the additional information of unchanged positions and number of calls torand(). Calculate the total numbers of unchanged positions. Compare...
Programming Assignment 7 Implement a function named fibo that will get a 20 element initialized an array of zeros from the main function. It will set the array to the Fibonacci sequence. This sequence starts with 1 and 2 as the first 2 elements and each element thereafter is the sum of the previous two elements. (1, 2, 3, 5, 8, 13…). Add another function named findNum that will get the newly created array by fibo from the main function....
In C++ Write a function called fillArray that will fill an array of any constantly declared array size variable with random numbers in the range of 1 - 100. Write a function called printArray that will print an array of any size. Write a third function called countEvens which will count and return the number of even numbers in the array. In main create an array that holds 25 ints. Use your functions to fill, print, and count the number...