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
A low concentration of market power has positive affects. A low concentration of market share has which of the following effects
lisov135 [29]
A or b i think hope it helps good luck and i hope it helps
6 0
3 years ago
A security utility program that scans the system for small programs that interfere with how a computer functions are _____ utili
Aneli [31]

Answer:

A security utility program that scans the system for small programs that interfere with how a computer functions are _____ utilities.

Explanation:

7 0
3 years ago
1. Ce este o baza de date? (1p)
lesya [120]

Answer:

would you mind telling me what this says im still learning my spanish

Explanation:

6 0
2 years ago
Read 2 more answers
To what extent do preexisting personal biases affect representation in new media
dolphi86 [110]

Answer:

Below

Explanation:

I believe that it's a bit of a case by case scenario. However, personal biases will inevitably show throughout any sort of writing or other presenting within media. That's why you should always be careful about what you read and believe is true

6 0
2 years ago
What is the output of this program?
dedylja [7]

Answer:

John Rambo is the output

6 0
3 years ago
Other questions:
  • Sarah is working on a project in which she needs to record all the extracurricular activities in her college. Her college teache
    5·1 answer
  • Reggie has hired you to design a home network. The home network will share a printer but will mainly be used to stream movies to
    7·1 answer
  • Green field county stadium is planning to conduct a circket match between two teams A and B. A large crowd is expected in the st
    13·1 answer
  • When you park on a hill, think about which way _____.
    6·2 answers
  • A company has critical systems that are hosted on an end-of-life OS. To maintain operations and mitigate potential vulnerabiliti
    14·1 answer
  • The current standard for RFID is based off of Group of answer choices MIT standards IEEE standards ISO standards there is no agr
    12·1 answer
  • 1)Create a conditional expression that evaluates to string "negative" if userVal is less than 0, and "positive" otherwise. Examp
    15·2 answers
  • Which of the following is as result of division of Labour​
    5·1 answer
  • Key Vocabulary:
    7·1 answer
  • A technology _________ occurs when the ability of a company to operate is impaired because of a hardware, software, or data outa
    7·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!