Question

in C++, please show the work step by step. thanks 1.Write pseuodocode for a function that...

in C++, please show the work step by step. thanks

1.Write pseuodocode for a function that finds the minimum element in an array.
2. Translate your pseudocode from 1 into C++ code. Add a main function that calls the function appropriately.
3.First, wrap your head around what this function does:
bool isfact(int n){
bool is=false;
int fact=1;
for(int i=1; i<n+2; i++){
if(fact==n)
is=true;
fact=fact*i;
}
return is; }
Using this function, write another function void factarr(int a[], bool fact[], int size), in pseudocode, that determines the factorials in your array. When your function call is over, the array fact should be a parallel array to a where each spot holds true if the corresponding element of a is a fact, and false if it’s not.
4.Translate your pseudocode from 3 into C++ code. Add a main function that calls the function appropriately.
0 0
Add a comment Improve this question Transcribed image text
Answer #1

The explanation is done in the code itself. If you have any queries write a comment. If you have understood upvote. Thank you. I have written in the same as It has given

SOLUTION 1:

minimum(int a[]){
   min=a[0];
   //iterate through the array if there are any elements which are less than minimum update and return
   for(i=0;i<(size of array );i++){
       if(a[i]<min)
       min=a[i];
   }
   return min;
}

SOLUTION 2:

#include <bits/stdc++.h>
using namespace std;

int minimum( int a[],int size){
   int min=a[0];
   //iterate through the array if there are any elements which are less than minimum update and return
   for(int i=0;i<size;i++){
       if(a[i]<min)
       min=a[i];
   }
   //return minimum
   return min;
}
int main(){
   int a[]={10,20,30,5,9,70};
   cout<<"Minimum number is "<<minimum(a,(sizeof(a)/sizeof(*a)));
}

code Image:

OUTPUT:

SOLUTION 3:

//this function is calculating that the given number is factorial of some number or not like 120 is a factorial of 5 it give trrue if we 120 as input if we give 100 it will give it as false since it is not an factorial any number like it cannot obtained in the factorial way

bool isfact(int n){

bool is=false;

int fact=1;

for(int i=1; i<n+2; i++){

if(fact==n)

is=true;

fact=fact*i;

}

return is; }

factarray function :

//fact array for storing the array whether that it is a fact or
// not and store it in the fact array,
void factarr(int a[],bool fact[],int size]){
   for(int i=0;i<size;i++){
       fact[i]=isfact(a[i])
   }

}

SOLUTION 4:

#include <bits/stdc++.h>
using namespace std;

bool isfact(int n){
   bool is=false;
   int fact=1;
   for(int i=1; i<n+2; i++){
   if(fact==n)
       is=true;
   fact=fact*i;
   }
   return is;
}
//fact array for storing the array whether that it is a fact or
// not and store it in the fact array,
void factarr(int a[],bool fact[],int size){
   for(int i=0;i<size;i++){
       //call the fact function
       fact[i]=isfact(a[i]);
   }
   cout<<" If written 1 at the end means true if 0 false"<<"\n";
   for(int i=0;i<size;i++){
       cout<<a[i]<<" It is "<<fact[i]<<"\n";
   }
  
}

int main(){

//declare the array
   int a[]={120,100,720,1,2,80};

//i have written the fact bool array of size equal to the array since it needs to the passed to the //function
   bool fact[6];
   factarr(a,fact,6);
  
}

CODE IMAGE:

CODE OUTPUT:

Add a comment
Know the answer?
Add Answer to:
in C++, please show the work step by step. thanks 1.Write pseuodocode for a function that...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Step 4: Write a Sum Function Since we can write, compile and run simple c files,...

    Step 4: Write a Sum Function Since we can write, compile and run simple c files, lets add a bit to make a program that will sum an entire array of integers. To do this we are going to simply overwrite the main.c file to include the new function. The sum function below is not complete and must be finished before the program will execute properly. %%file main.c #include <stdio.h> int sum(int array[], int arrayLength) {     int i =...

  • Problem 1 1. Consider the following function (K is the size of array A and L...

    Problem 1 1. Consider the following function (K is the size of array A and L is the size of array B) bool func (int A[], int K, int B[], int L, int start) { if (L > K-start) return false; for (int i =0; i < L; i++) { if(A[start+i] != B[i]) return false } return true; } What are the input and output variables to this function. Trace it for the following call: int F[] = {1, 3,...

  • C ++Write a function, anyThree (int a[], int n), that returns true if the value 3...

    C ++Write a function, anyThree (int a[], int n), that returns true if the value 3 appears in the array exactly 3 times, and no 3's are next to each other. The parameter n will be greater than or equal to 0. Write a function, anyThree (int all, int n), that returns true if the value 3 appears in the array exactly 3 times, and no 3's are next to each other. The parameter n will be greater than or...

  • c++ please. Write a recursive method that takes the following parameters: * a sorted array of...

    c++ please. Write a recursive method that takes the following parameters: * a sorted array of ints * an int representing the size of the array * an int representing a value to be searched for Your function should return a bool. If the element is in the array, return true. Otherwise, return false. Your function should never produce memory access errors, regardless of the size of the array.

  • Step 1. Start Netbeans and create a project called ArrayLab Step 2. Write the main method...

    Step 1. Start Netbeans and create a project called ArrayLab Step 2. Write the main method  Declare and initialize an array called myNums int myNums = {3, 8, 12, 4, 2, 9, 6};  Declare an int called largestNum and set it to 0.  Write a for loop that prints the array for (int index = 0; index < myNums.length; index++) { System.out.println(myNums[index] + “ “); }  Write a for loop that prints the array backwards ...

  • In C language Write a program that includes a function search() that finds the index of...

    In C language Write a program that includes a function search() that finds the index of the first element of an input array that contains the value specified. n is the size of the array. If no element of the array contains the value, then the function should return -1. The program takes an int array, the number of elements in the array, and the value that it searches for. The main function takes input, calls the search()function, and displays...

  • Please help with my C++ homework! 1. The following function is supposed to perform binary search....

    Please help with my C++ homework! 1. The following function is supposed to perform binary search. It has no errors and will execute correctly. int binarySearch(int array[], int size, int value) {    int first = 0,             // First array element        last = size - 1,       // Last array element        middle,                // Mid point of search        position = -1;         // Position of search value    bool found = false;        // Flag    middle = (first + last)...

  • Please write the complete code in C. Write a C function that prints the minimum spanning...

    Please write the complete code in C. Write a C function that prints the minimum spanning tree of a graph. At the end, print the weight of the spanning tree. A suggested report format is shown in the following example. Source Vertex To Vertex Weight A B 2 A C 4 B D 3 D E 1 Total weight of spanning tree: 10 Your main program will read a graph from DataIn file to an adjacency table before calling the...

  • c++ show code thanks, only use library <iostream> Question 1 Write the following two functions The...

    c++ show code thanks, only use library <iostream> Question 1 Write the following two functions The first function accepts as input a two-dimensional array of integers. It returns two results: the sum of the elements of the array and the average The second function accepts as input a two-dimensional array of integers and integer value V. It returns true if the value V is found in the array, false otherwise. Write a main program that declares and initializes the following...

  • In C++ #include<iostream> using namespace std; //Implement the function below. bool is_fibonacci_array(int*,int); //Param 1: pointer to...

    In C++ #include<iostream> using namespace std; //Implement the function below. bool is_fibonacci_array(int*,int); //Param 1: pointer to the beginning of an array of integers //Param 2: size of that array //Returns: true, is every element in the input array is a Fibonacci number //(the order of the numbers in the array need not be ordered //as per the Fibonacci sequence) //false, otherwise //A Fibonacci sequence is generated as follows. //The first two numbers in the sequence are 0 and 1. //The...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT