Question

In: Computer Science

ASM Programming instructions: For this week the student’s goal is to write an occurrence finding function...

ASM Programming instructions: For this week the student’s goal is to write an occurrence finding function that builds off of the past two weeks of assembly programming. The requirements for this function are as follows.

  1. The user is allowed to type in 10 positive integers plus an occurrence value (meaning 11 inputs).
    1. The 10 integers should be handled in a loop where each value input by the user (as in week 1) is stored into memory in an array like structure (as in week 2).
    2. The input occurrence is also an integer which represents a value present (or not) in the input array.
  2. Then, the program will loop through the array and find any matching with the input occurrence value.
  3. When finding a matching, its index inside the array will be output and the number of occurrences found will be incremented by 1.
  4. At the end of the loop, the program will print out the number of occurrences found.

The C++ code for this program is as such:

int main()

{            

                            int x[10], occur, count = 0;

                             

                               cout << "Type in array numbers:" << endl;

for (int i=0; i<10; i++) // reading in integers

                              {

cin >> x[i];       

}

cout << "Type in occurrence value:" << endl;

                                cin >> occur;

               

                                // Finding and printing out occurrence indexes in the array

                                 cout << "Occurrences indices are:" << endl;

for (int i=0; i<10; i++)

{

     If (x[i] == occur)

                                     {       

cout << i << endl;

                                                count ++;            

                                  }

}

cout << "Number of occurrences found:" << endl;

                                cout << count;

return 0;

}

Solutions

Expert Solution

#include <iostream>

using namespace std;

int main()
{
int x[10], occur, count = 0;
cout << "Type in array numbers:" << endl;
for (int i=0; i<10; i++) // reading in integers
{
cin >> x[i];   
}
cout << "Type in occurrence value:" << endl;
cin >> occur;
// Finding and printing out occurrence indexes in the array
cout << "Occurrences indices are:" << endl;
for (int i=0; i<10; i++)
{
if(x[i] == occur)
{
cout << i << endl;
count ++;   
}
}
cout << "Number of occurrences found:" << endl;
cout << count;
return 0;
}

//Code


//output


Related Solutions

The programming language is Python Instructions: Create a function that will delete a node in a...
The programming language is Python Instructions: Create a function that will delete a node in a Linked List based on position number. On below example, if you want to delete position #2, it will remove the Banana (arrangement of nodes below is Apple, Banana, Cherry, Grapes, Orange). myLinkedList = LinkedList() myLinkedList.append("Banana") myLinkedList.append("Cherry") myLinkedList.append("Grapes") myLinkedList.append("Orange") myLinkedList.prepend("Apple") myLinkedList.deleteByPositionNum(2) node = myLinkedList.head while node: print(node.value, " ") node = node.next_node You may start with the function head: def deleteByPositionNum(self, positionNum):
C PROGRAMMING Create the int delete(int key) function so that it deletes the LAST occurrence of...
C PROGRAMMING Create the int delete(int key) function so that it deletes the LAST occurrence of a given number in the linked list Make sure the parameter for this delete function is (int key). Also, use these variables and global Nodes BELOW as this is a DOUBLY LINKED LIST!!! #include #include typedef struct node {             int data;             struct node *next;             struct node *prev; } Node; Node *head; Node *tail; ----------------------- So, the function has to look like...
Module/Week 3 ASSIGNMENT (CONTROL STRUCTURES . IF ..ELSE) Write a C++ program that computes a student’s...
Module/Week 3 ASSIGNMENT (CONTROL STRUCTURES . IF ..ELSE) Write a C++ program that computes a student’s grade for an assignment as a percentage given the student’s score and total points. The final score must be rounded up to the nearest whole value using the ceil function in the <cmath> header file. You must also display the floating-point result up to 5 decimal places. The input to the program must come from a file containing a single line with the score...
1. INTRODUCTION The goal of this programming assignment is for students to write a Python program...
1. INTRODUCTION The goal of this programming assignment is for students to write a Python program that uses repetition (i.e. “loops”) and decision structures to solve a problem. 2. PROBLEM DEFINITION  Write a Python program that performs simple math operations. It will present the user with a menu and prompt the user for an option to be selected, such as: (1) addition (2) subtraction (3) multiplication (4) division (5) quit Please select an option (1 – 5) from the...
The goal of this project is to practice (Write a C Program) with a function that...
The goal of this project is to practice (Write a C Program) with a function that one of its parameter is a function.The prototype of this function is: void func ( float (*f)(float*, int), float* a, int length); This means the function: func has three parameters: float (*f)(float*, int): This parameter itself is a function: f that has two parameters and returns a floating-point number. In the body of the function: func we call the function: f with its arguments...
Programming in C (not C++) Write the function definition for a function called CompareNum that takes...
Programming in C (not C++) Write the function definition for a function called CompareNum that takes one doyble argument called "num". The function will declare, ask, and get another double from the user. Compare the double entered by the user to "num" and return a 0 if they are the same, a -1 num is less than the double entered by the user and 1 if it is greater.
Write in java please Instructions Your goal is to take N integer inputs from the user...
Write in java please Instructions Your goal is to take N integer inputs from the user -- N's value will be given by the user as well. You can assume the user provides a valid value for N, i.e., >0. Store the input integers in an array of size N in the order they are provided. These tasks should be done in the main() method. Create a new method called checkArray() that will take the previously created array as input...
C Language - Programming Write a function that takes an array of ints, and the size...
C Language - Programming Write a function that takes an array of ints, and the size of the array – another int. It also returns a double. Call this one ‘average.’ Return a double that is the average of the values in the array. Demonstrate that it works by finding the average of an array with these values {78, 90, 56, 99, 88, 68, 92} Write a function that takes one double parameter, and returns a char. The parameter represents...
7. Finding Roots Using the Bisection Method Write a function that implements the "bisection method" for...
7. Finding Roots Using the Bisection Method Write a function that implements the "bisection method" for finding the roots of function. The signature of your function should look like def find_root(f,a,b,n): where n is the maximum number of iterations of to search for the root. The code should follow this algorithm: We are given a continuous function f and numbers a and b and with a<b with f(a)<0<f(b). From the intermediate value theorem we know that there exists a c...
Design and write an efficient Python function (with tester code) for finding the 10 largest elements...
Design and write an efficient Python function (with tester code) for finding the 10 largest elements in a sequence of size n, where n >= 50. In your tester function, write code that generates at least 50 random numbers and stores them in an array, then calls your function on that array (and prints the resulting 10 largest elements). This function must be as efficient as possible. Marks will be deducted for a slow function, even if it actually answers...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT