//This code created by Dr. Ramsey //I'm grading Homework 6 as extra credit and applying it to Homework 7 //This solution to Homework 6 should assist you in completing Homework 7 #include using namespace std; void inputandcount(int array[], int count[], int &numused); void output(int array[], int count[], int numused); int search(int array[], int numused, int target); int main() { const int MAX = 50; int array[MAX], count[MAX]; int size,numused; inputandcount(array,count,numused); cout << "Output the array and count " << endl; output(array,count,numused); } void output(int array[], int count[], int numused) { for(int i = 0; i < numused; i++) { cout << array[i] << " " << count[i] << endl; } } int search(int array[], int numused, int target) { for(int i = 0; i < numused; i++) //look through every element of the array { if(array[i] == target) //if you find the one you're looking for, return i; // then return its index } return -1; //otherwise return -1 } void inputandcount(int array[], int count[], int &numused) { int size; cout << "How many elements will you input? " << endl; cin >> size; numused = 0; // how many elements are currently in the array for(int i = 0; i < size; i++) //number the user will input { int num; cin >> num; // get the next number the user inputs int index = search(array,numused,num); //is num in the array? // if index == -1 then if(index == -1) // the number wasn't found in the array { //we need to add an element to the array numused++; //increase the size array[numused-1] = num; //add num at the last index count[numused-1] = 1; // wasn't seen before so it was now seen once } else //index is 'where' that element was found { count[index] ++; //it was seen before, now it is seen again //since it is seen again, we want to increase //the times it was seen by 1 } } }