1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
tamaranim1 [39]
3 years ago
13

Write a generic C++ function that takes an array of genericelements and a scalar of the same type as the array elements. Thetype

of the array elements and the scalar is the generic parameter.The function must search the given array for the given scalar andreturn the subscript of the scalar in the array. If the scalar isnot in the array, the function must return -1. Test the function for int and float types.
Requirements:
1. Write a main function to make it acomplete program.
2. Initialize the array with random numbers.
Computers and Technology
1 answer:
siniylev [52]3 years ago
7 0

Answer:

Explanation:

Here is the code

#include<iostream>

using namespace std;

template <class myType>

int generic(myType *a, myType b)

{

int i;

for(i=0;a[i]!=-1;i++)

{

       if( b == a[i])

       return i;

}

return -1;

}

int main()

{

int a[]={1,2,3,4,5,6,7,8,-1};

float b[]={1.1,2.1,3.1,4.1 ,5.1,6.1,7.1,-1};

if(generic(a,5)>0)

       {

       cout<<" 5 is foundin int at index "<<generic(a,5)<<endl;

       }

       else

       {

       cout<<" 5 notfound "<<endl;

       }

if(generic(b,(float)5.1)>0)

       {

       cout<<" 5.1 isfound in float at index "<<generic(a,5)<<endl;

       }

       else

       {

       cout<<" 5.1 notfound "<<endl;

       }

system("pause");

}

/*

sample output

5 is found in int at index 4

5.1 is found in float at index 4

*/

You might be interested in
When does the following while-loop stop running?
8090 [49]

The loop never stops running because the value of var is always 1.

5 0
3 years ago
WILL GIVE BRAINLIEST
GenaCL600 [577]

Answer:

None of those answers is correct because E[1101] is index out of range.

8 0
3 years ago
¿En cuales situaciones concretas se puede aplicar las técnicas de conteo(particularmente las permutuaciones y las combinaciones)
Andrei [34K]

Answer:

In which specific situations can counting techniques (particularly permutuations and combinations) be applied within computer science? for anybody trying to help

7 0
3 years ago
As Juan sat in his biology lab, his instructor was droning on about the techniques of vivisection. Juan kept thinking about the
MaRussiya [10]

Answer:

attending

Explanation:

7 0
4 years ago
What is what is a network that is easy to maintain and cheap ​
kifflom [539]

Answer:

Click at the pic above and the ans will appear.

Hope it helps :)

4 0
3 years ago
Other questions:
  • Dan is a Civil Engineer for a company that builds nuclear power plants throughout the world. Which best describes the places he
    14·2 answers
  • True or false the primary advantage of the worksheet is the ability to solve numerical problems quickly and accurately
    11·1 answer
  • The posterior auditory stream terminates in the ________ and is involved in ________.
    12·1 answer
  • IF ACCURATE = BRAINLY (if u answer rubbish randomness= reported AND if you got questions dont ask in answer slot= reported)
    13·1 answer
  • Yahoo and Google are examples of __________ used to perform Internet research.
    14·2 answers
  • Consider the following partial class definitions: public class A1 { public int x; private int y; protected int z; ... } public c
    12·1 answer
  • The region which satisfies all of the constraints in graphical linear programming is called the:
    8·1 answer
  • Write a python program that requests a positive integer from the user, determines if it is a composite, a prime or neither prime
    8·1 answer
  • The road is closed a head
    9·1 answer
  • NEED HELP ASAP!!!!!!!!!!!
    7·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!