Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Using Parnas table depict meaning of functions and procedures Example: Consider the following function: int example (int a[], int n) { int count=0; for (int

Using Parnas table depict meaning of functions and procedures

Example:

Consider the following function:

int example (int a[], int n) { int count=0; for (int i=0; i < n; i++) { if (a[i] %2 == 0) count++; } return count; }

The input variables are the array a and n, the size of a. The output variables is only returnValue the value returned by the function since the array is not modified and no global variables are modified. Clearly this function returns the number of even numbers in the array a. We can specify this in a Parnas table like:

Condition returnValue n = size of the array a n1 (a[i] is even) i=0 Question need to be help:

1. A procedure that rearranges things void rearrange (int &a, int &b, int &c) { int t = b; b = a; a = c; c = t; }

2. A procedure that prints something void print (int a, int b) { int sum = 0; int i; for (i=a; i <=b; i++) sum = sum + i; cout << sum << endl; }

3. A procedure that computes something void compute (int a[], int n, int key, int &i) { for (i=0; i < n && a[i] != key; i++); }

4. A function that computes something int sm1 (int a[], int n) { int t; for (t=0, int i=0; i < n; i++) { t = t+i; } return t; } 5. A function that accumulates from an array int sm3 (int a[], int n) { int t; for (t=0, int i=0; i < n; i++) { t = t+a[i]; } return t; }

6. A function that computes a value from an array int sm5 (int a[], int n) { int t; for (t=a[0], int i=0; i < n; i++) { if (a[i] > t) t = a[i]; } return t; }

7. A function that computes something from an array int f1 (int a[], int n, int k) { int i=0; while (i < n and a[i] != k) i++; return i; }

8. A function that computes a boolean from an array bool f2 (int a[], int n, int k) { int i=0; while (i < n and a[i] != k) i++; return i < n; }

9. A function that computes something from an array int f3 (int a[], int n, int k) { int i=0; while (i < n ) { i++; } return i < n; }

10. A function that does weird and unusual things int f1 (int a[], int n, int k) { int i=n-1; while (i>=0 and a[i] != k) i++; return i; }

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

More Books

Students also viewed these Databases questions