What does this function do?
int mystery(double employees[], double id, int size)
{
for (int i = 0; i < size; i++)
{
if (id == employees[i])
{
return i;
}
}
return -1;
}
| A. | This is a function that performs a search. If the id is found in the employees array, its index location is returned, otherwise -1 is returned. |
| B. This is a function that sorts the employees array |
| C. This is a function that returns all index numbers in the employees array, one at a time. Once the entire array has been processed, -1 is returned. |
| D. This is a function that swaps the value in the id variable with the value in the employees array at index i. If the swap cannot be performed, -1 is returned. |
The numbers to the left represent the line numbers, but are not part of the code. Why is the temp variable necessary in this function?
1 void swapShells(int &n1, int &n2)
2 {
3 int temp = n1;
4 n1 = n2;
5 n2 = temp;
6 }
| A. Because the value of n2 is overwritten on line 4. Without first saving it in the temp variable, the original value of n2 would be lost. |
| B. Because n1 and n2 are passed by reference, temp is necessary to return the result. |
| C. Because there are three values being swapped. n1, n2 and temp. |
| D. Because the value of n1 is overwritten on line 4. Without first saving it in the temp variable, the original value of n1 would be lost. |
What does this function do? int mystery(double employees[], double id, int size) { for (int i...
code in C language ADT: typedef struct{ int ID; float salary; int age; }Employee; Specification: In this lab, five functions need to be implemented using the given ADT. 1. Employee* readRecord(FILE*) This function receives a FILE pointer created before. It reads a line from the provided csv file, and creates an Employee struct pointer with the information from that line then returns the pointer back to the calling function. Each line in the provided csv file contains the id, salary,...
#include <iostream> #include <vector> #include <iomanip> using namespace std; int main() { const int NUM_ITEMS = 8; vector <double> inverse(NUM_ITEMS); int j; double temp; for (int i = 0; i < NUM_ITEMS; i++) { inverse.at(i) = 1 / (i + 1.0); } cout << fixed << setprecision(2); cout << "Original vector..." << endl; for (int i = 0; i < NUM_ITEMS; i++) { cout << inverse.at(i) << " "; } cout << endl; cout << "Reversed vector..." << endl; for...
A function that takes three parameters: an int array, an int n that is the size of the array and an int pointer max that is to assign the maximum value in the array. The function will find and return the index of the first occurrence of the maximum value in the array and assign the maximum value to the pointer. For example, in the array {1, 2, 6, 5, 6, 4, 3, 6, 4}, the maximum value is 6...
In C++ Write a function that accepts two int arrays of the same size. The first array will contain numbers and the second array will be filled out inside the function. The function should find all numbers in the array that are greater or equal to the average and fill out the second array with these numbers. You need to design the function. I tried this code but the errors returned were: expression must have a constant value #include<iostream> using...
What is the run-time of this recursive code: int maximum(int array[], int index, int len); //define maximum function. int minimum(int array[], int index, int len);//define minimum function. int main() { //Main method int array[MAX_SIZE], N, max, min; //Defining all the variable. int i; printf("Enter size of the array: ");//Taking input from user as a array size scanf("%d", &N); printf("Enter %d elements in array: ", N);//Taking input from user for(i=0; i<N; i++) { scanf("%d", &array[i]);//storing all the element in array. }...
In class Recursion problems bool anyNegative(int al , int size) This function returns true if there are any negative numbers in the array, grity false otherwise. int firstNegative(int al I, int size) This function returns the position of the first negative number in the array & EAO If there are no negative numbers it returns int countNegative(int al I, int size) This function returns the number of negative numbers in the array a. 12 bst Stringsint indexO bout Strings nt...
Hi I need a fix in my program. The program needs to finish after
serving the customers from the queue list.
Requeriments:
Headers:
DynamicArray.h
#ifndef DynamicArray_h
#define DynamicArray_h
#include
using namespace std;
template
class DynamicArray
{
V* values;
int cap;
V dummy;
public:
DynamicArray(int = 2);
DynamicArray(const DynamicArray&);
~DynamicArray() { delete[] values; }
int capacity() const { return cap; }
void capacity(int);
V operator[](int) const;
V& operator[](int);
DynamicArray& operator=(const DynamicArray&);
};
template
DynamicArray::DynamicArray(int cap)
{
this->cap = cap;
values =...
Question 1 Answer the questions below about this function prototype: double coinTotal (double coinValue, int nCoins); What is the type of the return value? How many parameters does the function take? What is the name of the function? Question 2 These are defined in the function heading and tell a user what data needs to be sent to a function. Question 3 What is the term used for a variable sent as data in a function call, such as n1...
// PLACE YOUR NAME HERE #include <iostream> using namespace std; float findAverage (int [], int); // finds average of all //grades int findHighest (int [], int); // finds highest of all //grades int findFirstFail( int[]); int main() { int grades[100]; // the array holding 100 grades. int numberOfGrades; // the number of grades read. int pos; // index to the array. float avgOfGrades; // contains the average of the grades. int highestGrade; // contains the highest grade. int inderOfFail; //...
(C++ program )Write a function that accepts an int array and the array’s size as arguments. The function should create a new array that is one element larger than the argument array. The first element of the new array should be set to 0. Element 0 of the argument array should be copied to the element 1 of the new array. Element 1 of the argument array should be copied to element 2 of the new array, and so forth....