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):
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...
C programming review excerises. 1. Write a function that counts the number of lines in a...
C programming review excerises. 1. Write a function that counts the number of lines in a file, using the following declaration: int countLines(char *filename) 2. Write a program that counts the number of words in a text file. Use the command-line arguments to read the name of the file. The syntax: countwords filename.txt 3. Write a program that counts the number of words starting with the first letter ‘T’ in a text file. Using commend line argument for the text...
Write a function in any functional programming language that will reverse a general list. For example,...
Write a function in any functional programming language that will reverse a general list. For example, if an input is (A (B C (D E)) F), output is (F ((E D) C B) A).  Please note that any built-in/pre-defined function, e.g., reverse, cannot be used in your answer. Please DO NOT hard-code any input values, output values in your code. Please submit a screenshot of where your code got compiled, executed, showing the execution result
Programming in C language (not C++) Write a runction derinition for a function called SmallNumbers that...
Programming in C language (not C++) Write a runction derinition for a function called SmallNumbers that will use a while loop. The function will prompt the user to enter integers ine by one, until the user enters a negative value to stop. The function will display any integer that is less than 25. Declare and initialize any variables needed. The function takes no arguments and has a void return type.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT