Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Write and test a C++ main program that: a. declare an array arr of 6 integers b.

ID: 3790737 • Letter: W

Question

Write and test a C++ main program that: a. declare an array arr of 6 integers b. Prompt the user for 6 integer values and store them in arr. c. Prompt the user for a target integer target. d. Search for target in arr. If target is found to match an element in the arr, then the program prints out a message which contains the address of the found element, otherwise, if no element found then the message “the element target not found” will be printed out. The program must use the array name-offset notation to traverse the array. Write and test a C++ main program that: a. declare an array arr of 6 integers b. Prompt the user for 6 integer values and store them in arr. c. Prompt the user for a target integer target. d. Search for target in arr. If target is found to match an element in the arr, then the program prints out a message which contains the address of the found element, otherwise, if no element found then the message “the element target not found” will be printed out. The program must use the array name-offset notation to traverse the array. 1. Write and test a C++ main program that a. declare an array arr of 6 integers b. Prompt the user for 6 integer values and store them in arr. c. Prompt the user for a target integer target. d. Search for target in arr. If target is found to match an element in the arr, then the program prints out a message which contains the address of the found element, otherwise, if no element found then the message "the element target not found" will be printed out. The program must use the array name-offset notation to traverse the array.

Explanation / Answer

#include <iostream>

using namespace std;

int main(){
  
   //Integer array of size 6
   int arr[6];
   int target;
  
   //Input Array
   cout<<"Enter array elements ";
   for(int i=0;i<6;i++){
       cin>>arr[i];
   }
  
   //Input target
   cout<<"Enter target integer ";
   cin>>target;
  
   //Boolean to check if target found
   bool targetFound = false;
  
   int i=0;
   while(*(arr+i)!=''){
       if(*(arr+i)==target){
           targetFound = true;
           break;
       }
       i++;      
   }
  
   if(targetFound){
       //Printing address of the target
       cout<<arr+i;
   }
   else{
       //Target not found
       cout<<"The element target not found";
   }
   return 0;
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote