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.
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.
Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
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
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
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
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; } |
Expert Solution
This question has been solved!
Explore an expertly crafted, step-by-step solution for a thorough understanding of key concepts.
Step by step
Solved in 2 steps with 1 images
Recommended textbooks for you
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education