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
What are two preferences a user can indicate for the Junk Email folder?
marysya [2.9K]
Did you mean this?
<span>Controls are divided between two locations: (a) </span>Tools -> Options<span> -> Security -> Junk, and (b) Tools -> Account Settings -> *each account* -> Junk Settings.</span>
5 0
3 years ago
Read 2 more answers
The technical relationship between inputs and outputs, which is needed to understand the difference between the short run and th
MrRa [10]
<span>The technical relationship between inputs and outputs, which is needed to understand the difference between the short run and the long run, is called a production function.

Hope I helped ;)
</span>
3 0
3 years ago
TQ Sustainability &amp; Technology
harkovskaia [24]

A way to make the metro system more sustainable is to use machine learning so as to optimize the frequency of train routes  using passenger load.

<h3>What is a sustainable transport system?</h3>

This sustainable transport system is known to be a kind of system that aids the basic access and growth needs of the society to be met rightly and safely.

This also should be meant in a way that is consistent with human and ecosystem health, and boast equity in all successive generations.

Other methods are the use of Cooling System to lower temperature and non waste of Energy and also lower the Noise Levels.

learn more about Sustainability from

brainly.com/question/25032305

4 0
2 years ago
The =COUNT function calculates what value?
Natalka [10]

c is the anwer of question

4 0
2 years ago
Read 2 more answers
The ________ utility automatically creates duplicates of your libraries, desktops, contacts, and favorites to another storage lo
olchik [2.2K]

I guess the best option is B.

The file history utility automatically creates duplicates of your libraries, desktops, contacts, and favorites to another storage location.


7 0
3 years ago
Other questions:
  • Complete the following:_____
    9·1 answer
  • The part of the computer that provides access to the internet is the?
    14·1 answer
  • 1. Write an expression whose value is the result of converting the str value associated with s to an int value. So if s were ass
    12·1 answer
  • Which option allows users to access the handout master to modify it?
    13·2 answers
  • with the advent of technology one can experience special features such as 3D theater experiences true or false
    8·1 answer
  • Use python
    9·1 answer
  • A form of segmentation that is based on user usage rate, user status, purchase occasion, and benefits sought is _________.
    13·1 answer
  • Why is it now difficult for computer technology to maintain the pace of
    12·1 answer
  • Write a function called mul_time that takes a Time_Elapsed object and a number and returns a new Time_Elapsed object that contai
    13·1 answer
  • Suppose that you have the following definitions:
    8·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!