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
Jennifer has written a short story for children. What should be her last step before she submits the story for publication? A) p
erik [133]
It would be a or c when she is writing a childerns story
5 0
3 years ago
Read 2 more answers
Which of the following would be the most appropriate way to define a method that calculates and returns the final price, after t
Oksanka [162]

D. I hope it helped
5 0
2 years ago
Sweet thas 2 orange picks for every 5 green picks if there is 21 pick are in all how many picks are orange
Temka [501]

Your answer should be 9..

4 0
2 years ago
7. Test Average and Grade Write a program that asks the user to enter five test scores. The program should display a letter grad
Alenkasestr [34]

Answer:

The code solution is written in Java.

  1. import java.util.Scanner;
  2. public class TestScore {
  3.    public static void main(String[] args) {
  4.        Scanner input = new Scanner(System.in);
  5.        System.out.print("Please enter first score: ");
  6.        double firstScore = input.nextDouble();
  7.        System.out.println("Grade: " + determineGrade(firstScore));
  8.        System.out.print("Please enter second score: ");
  9.        double secondScore = input.nextDouble();
  10.        System.out.println("Grade: " + determineGrade(secondScore));
  11.        System.out.print("Please enter third score: ");
  12.        double thirdScore = input.nextDouble();
  13.        System.out.println("Grade: " + determineGrade(thirdScore));
  14.        System.out.print("Please enter fourth score: ");
  15.        double fourthScore = input.nextDouble();
  16.        System.out.println("Grade: " + determineGrade(fourthScore));
  17.        System.out.print("Please enter fifth score: ");
  18.        double fifthScore = input.nextDouble();
  19.        System.out.println("Grade: " + determineGrade(fifthScore));
  20.        System.out.println("Average score: " + calcAverage(firstScore, secondScore, thirdScore, fourthScore, fifthScore));
  21.    }
  22.    public static double calcAverage(double score1, double score2, double score3, double score4, double score5){
  23.        double average = (score1 + score2 + score3 + score4 + score5) / 5;
  24.        return average;
  25.    }
  26.    public static String determineGrade(double score){
  27.        if(score >= 90){
  28.            return "A";
  29.        }
  30.        else if(score >= 80 ){
  31.            return "B";
  32.        }
  33.        else if(score >=70){
  34.            return "C";
  35.        }
  36.        else if(score >=60){
  37.            return "D";
  38.        }
  39.        else{
  40.            return "F";
  41.        }
  42.    }
  43. }

Explanation:

Firstly, create the method, <em>calcAverage()</em>, that takes five test scores. Within the method, calculate the average and return it as output. (Line 33 - 36)

Next, create another method, <em>determineGrade()</em>, which takes only one score and return the grade based on the range of the  score. (Line 38 -54)

Once the two required methods are created, we are ready to prompt use for input five test scores using Java Scanner class. To use get user input, create a Scanner object (Line 7). Next, use getDouble() method to get an input score and assign it to variables firstScore, secondScore, thirdScore, fourthScore & fifthScore, respectively. Once a score input by user, call determineGrade() method by passing the input score as argument and immediately print out the return grade. (Line  9 - 27)

At last, call calcAverage() method by passing the first test score variables as argument and print out the returned average value. (Line 29).

5 0
3 years ago
Write a C++ program that reads students' names followed by their test scores. The program should output each students' name foll
Mashutka [201]

Answer:

#include<iostream>

#include<conio.h>

using namespace std;

struct studentdata{

char Fname[50];

char Lname[50];

int marks;

char grade;

};

main()

{

studentdata s[20];

for (int i=0; i<20;i++)

   {

cout<<"\nenter the First name of student";

cin>>s[i].Fname;

cout<<"\nenter the Last name of student";

cin>>s[i].Lname;

cout<<"\nenter the marks of student";

cin>>s[i].marks;

}  

 

for (int j=0;j<20;j++)

{

if (s[j].marks>90)

{

 s[j].grade ='A';

}

else if (s[j].marks>75 && s[j].marks<90)

{

   s[j].grade ='B';

}

else if (s[j].marks>60 && s[j].marks<75)

{

 s[j].grade ='C';

}

else

{

 s[j].grade ='F';

}

}

int highest=0;

int z=0;

for (int k=0;k<20; k++)  

{

if (highest<s[k].marks)

{

 highest = s[k].marks;

 z=k;

}

 

}

cout<<"\nStudents having highest marks"<<endl;

 

cout<<"Student Name"<< s[z].Fname<<s[z].Lname<<endl;

cout<<"Marks"<<s[z].marks<<endl;

cout<<"Grade"<<s[z].grade;

getch();  

}

Explanation:

This program is used to enter the information of 20 students that includes, their first name, last name and marks obtained out of 100.

The program will compute the grades of the students that may be A,B, C, and F. If marks are greater than 90, grade is A, If marks are greater than 75 and less than 90, grade is B. For Mark from 60 to 75 the grade is C and below 60 grade is F.

The program will further found the highest marks and than display the First name, last name, marks and grade of student who have highest marks.

6 0
3 years ago
Other questions:
  • Who is the last person appointed to the u.s supreme court
    11·1 answer
  • 16.
    7·1 answer
  • Consider a system that uses a 32-bit unique salt where users have a 4-digit number as a password (e.g. 6813). Eve wants to crack
    8·2 answers
  • Which statement describes Augmented Reality (AR) technology?
    12·1 answer
  • What type of app is Drake designing? Drake is designing a mobile app for an online travel blog. The app will enable browsers to
    5·1 answer
  • A draft has the following:<br> Plot<br> Details<br> Transition Words<br> Important events in order
    14·1 answer
  • (100 points) why does file explorer look like this and how do I fix it? I'm not good with computers, and I kinda need help
    13·1 answer
  • You have an audio that contains one pause for 0.2 seconds and another one for 0.6 seconds. When do you need to create a new segm
    5·1 answer
  • write a recursive bool valued function containsvowel that accepts a string and returns true if the string contains a vowel
    6·1 answer
  • Passing an argument by ___ means that only a copy of the arguments value is passed into the parameter variable and not the addrt
    6·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!