Question

In: Computer Science

C++. Write a program that will read in id numbers and place them in an array.The...

C++. Write a program that will read in id numbers and place them in an array.The array is dynamically allocated large enough to hold the number of id numbers given by the user. The program will then input an id and call a function to search for that id in the array. It will print whether the id is in the array or not.

Sample Run:

Please input the number of id numbers to be read

4

Please enter an id number

96

Please enter an id number

97

Please enter an id number

98

Please enter an id number

99

Please input an id number to be searched

67

67 is not in the array

Solutions

Expert Solution

ANSWER :

CODE :

#include <iostream>
using namespace std;
void search(int arr[], int n,int x)
{
int a = 0;
for(int i=0; i<n; i++)
{
if(arr[i] == x)
{
a= 1;
break;
}
}
if(a==0)
{
cout<<x<<" is not in the array";
}
else
{
cout<<x<<" is in the array";
}
}
int main()
{
int n;
int x;
cout<<"Please input the number of id numbers to read"<<endl;
cin>>n;
int arr[n];
for(int i=0; i<n; i++)
{
cout<<"Please enter an id number"<<endl;
cin>>arr[i];
}
cout<<"Please input an id number to be searched"<<endl;
cin>>x;
search(arr,n,x);
return 0;
}
OUTPUT :


Related Solutions

C++ programming language. Write a program that will read in id numbers and place them in...
C++ programming language. Write a program that will read in id numbers and place them in an array.The array is dynamically allocated large enough to hold the number of id numbers given by the user. The program will then input an id and call a function to search for that id in the array. It will print whether the id is in the array or not. Sample Run: Please input the number of id numbers to be read 4 Please...
C++ Program: Write a program that prompts the user for two numbers and stores them in...
C++ Program: Write a program that prompts the user for two numbers and stores them in signed integers. The program should then add those two numbers together and store the result in a signed integer and display the result. Your program should then multiply them by each other and store the result in another integer and display the result. Then do the same but with dividing the first number by the second. Display an error message to the screen if...
write a c++ program that prompts a user to enter 10 numbers. this program should read...
write a c++ program that prompts a user to enter 10 numbers. this program should read the numbers into an array and find the smallest number in the list, the largest numbers in the list the sum of the two numbers and the average of the 10 numbers PS use file I/o and input error checking methods
Write a C++ program to read in a list of 10 integers from the keyboard. Place...
Write a C++ program to read in a list of 10 integers from the keyboard. Place the even numbers into an array called even, the odd numbers into an array called odd, and the negative numbers into an array called negative. Keep track of the number of values read into each array. Print all three arrays after all the numbers have been read. Print only the valid elements (elements that have been assigned a value). a. Use main( ) as...
Write a C++ program to read N numbers. Find sum, product, and average of N numbers
Write a C++ program to read N numbers. Find sum, product, and average of N numbers
Write a C++ program to read a collective of integer numbers. I f the number is...
Write a C++ program to read a collective of integer numbers. I f the number is greater than zero and less than 15 then terminate the loop and find factorial of the number
Write a C program that reads three integers and then prints them in the order read...
Write a C program that reads three integers and then prints them in the order read and reversed. Use four functions: main, one to read the data, one to print them in the order read, and one to print them reversed.
You must write a C program that prompts the user for numbers and multiplies them using...
You must write a C program that prompts the user for numbers and multiplies them using "a la russe" multiplication. No input is allowed at execution time (no command line input). The program MUST DISPLAY YOUR BANNER LOGO as part of a prompt to the user. A menu must allow the user to put in two numbers at the same time or each of two numbers one at a time. The valid range of values for each number is 0...
write a C program that asks the user to enter numbers and finds maximum among them
write a C program that asks the user to enter numbers and finds maximum among them
Write a program in C++ to read 10 numbers from keyboard and find their sum, average,...
Write a program in C++ to read 10 numbers from keyboard and find their sum, average, maximum and minimum
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT