HE ISSUE IS IT'S NOT MATCHING WITH DESIRED OUTPUT. SO I HAVE I ATTACHED A MISMATCHED OUTPUT IMAGE . SO YOU HAVE TO EDIT MY CODE SO IT MUST MATCH OUTPUT.

Programming with Microsoft Visual Basic 2017
8th Edition
ISBN:9781337102124
Author:Diane Zak
Publisher:Diane Zak
Chapter8: Arrays
Section: Chapter Questions
Problem 14RQ
icon
Related questions
Question
QUESTION PROVIDE BELOW WITH MY SOLUTION .
 
THE ISSUE IS IT'S NOT MATCHING WITH DESIRED OUTPUT. SO I HAVE I ATTACHED A MISMATCHED OUTPUT IMAGE .
 
SO YOU HAVE TO EDIT MY CODE SO IT MUST MATCH OUTPUT.
 
 
----------------------QUESTION-----------------------------------
 
A school administration has a program to store a list of data using templates. They wish to add the functionality of search so that it is easy for the staff to search a roll number or marks of the student.

Write a C++ program to search an element in an array using a function template.
 
Note: Define an array size using Preprocessor directives
Example:  #define array_size 5
 
Strictly adhere to the Object-Oriented specifications given in the problem statement. All class names, member variable names, and function names should be the same as specified in the problem statement.
 
Include following member function using Template
Function Name Description
T SearchInArray(T x[], T element)                                                 This function is used to search an element in an array. If the element is found it returns true otherwise false.
 
In the main method, read the array elements and search for an element in the array.

Input and Output Format:
If an element is found in an array then print "Element # is found" otherwise "Element # is not found. (Eg. Element 4 is found)
Refer sample Input and output for formatting specifications.
 
Sample Input and Output:
[ All text in bold corresponds to input and the rest corresponds to output ]
Enter 5 integer numbers
9
2
4
10
5
Enter element to search:
4
Element 4 is found
Enter 5 float numbers
3.7
4.9
8.2
5.1
6.3
Enter element to search:
8.9
Element 8.9 is not found
 
-----------------------MY SOLUTION---------------------
MAIN.CPP
 
#include <iostream>
//defining array size using preproccesor directive
#define array_size 5
using namespace std;
//member function using Template
template <typename T>
T SearchInArray(T x[], T element){
int found=0;
for(int i=0;i<array_size;i++)
{
if(x[i]==element)
found=1; //if element is found
}
return found;
}
//main fuction
int main()
{
int ar[array_size],number;
float arr[array_size],num;
//asking user to enter integer array elements
cout<<"Enter 5 integer numbers \n";
for(int i=0;i<array_size;i++)
{
cin>>ar[i];
}
//asking user to enter element to search
cout<<"Enter element to search: \n";
cin>>number;
//calling function
int res = SearchInArray<int>(ar,number);
if(res==1)
cout<<"Element "<<number<<" is found\n";
else
cout<<"Element "<<number<<" is not found\n";
//asking user to enter float array elements
cout<<"Enter 5 float numbers \n";
for(int i=0;i<array_size;i++)
{
cin>>arr[i];
}
cout<<"Enter element to search: \n";
cin>>num;
//calling function
int ress = SearchInArray<float>(arr,num);
if(ress==1)
cout<<"Element "<<num<<" is found\n";
else
cout<<"Element "<<num<<" is not found\n";
return 0;
}
output not matching
Test Script - Main
S.No Test
Expected
Obtained
Differences
1
Test Script -
Enter 5 integer numbers
Enter 5 integer numbers
Enter 5
Main
Enter element to search: Element 4 is found
Enter element to search: Element 4 is not found
integer
Input: 9
numbers
2
Enter 5 float numbers
Enter 5 float numbers
Enter
4
Enter element to search: Element 2.3 is not found Enter element to search: Element 2.3 is found
element to
10
search:
5
Element 4 is
4
not found
2.2
3.2
Enter 5 float
4.5
numbers
6.8
Enter
9.1
element to
2.3
search:
Element 2.3
is not found
2
Test Script -
Enter 5 integer numbers
Enter 5 integer numbers
Enter 5
Main
Enter element to search: Element 4 is found
Enter element to search: Element 4 is not found
integer
Input: 9
numbers
2
Enter 5 float numbers
Enter 5 float numbers
Enter
4
Enter element to search: Element 9.1 is found
Enter element to search: Element 9.1 is not found element to
10
search:
5
Element 4 is
4
not found
2.2
3.2
Enter 5 float
4.5
numbers
6.8
Enter
9.1
element to
9.1
search:
Ele
is =
Transcribed Image Text:output not matching Test Script - Main S.No Test Expected Obtained Differences 1 Test Script - Enter 5 integer numbers Enter 5 integer numbers Enter 5 Main Enter element to search: Element 4 is found Enter element to search: Element 4 is not found integer Input: 9 numbers 2 Enter 5 float numbers Enter 5 float numbers Enter 4 Enter element to search: Element 2.3 is not found Enter element to search: Element 2.3 is found element to 10 search: 5 Element 4 is 4 not found 2.2 3.2 Enter 5 float 4.5 numbers 6.8 Enter 9.1 element to 2.3 search: Element 2.3 is not found 2 Test Script - Enter 5 integer numbers Enter 5 integer numbers Enter 5 Main Enter element to search: Element 4 is found Enter element to search: Element 4 is not found integer Input: 9 numbers 2 Enter 5 float numbers Enter 5 float numbers Enter 4 Enter element to search: Element 9.1 is found Enter element to search: Element 9.1 is not found element to 10 search: 5 Element 4 is 4 not found 2.2 3.2 Enter 5 float 4.5 numbers 6.8 Enter 9.1 element to 9.1 search: Ele is =
Expert Solution
steps

Step by step

Solved in 2 steps with 1 images

Blurred answer
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
Programming with Microsoft Visual Basic 2017
Programming with Microsoft Visual Basic 2017
Computer Science
ISBN:
9781337102124
Author:
Diane Zak
Publisher:
Cengage Learning