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

Problem Statement The use of pointers is very common when the engineer must deal

ID: 3768901 • Letter: P

Question

Problem Statement

The use of pointers is very common when the engineer must deal with variable length data sets and with

Requirements: Write a C++ program to that will use a pointer “list_ptr” to dynamically allocate memory for a list of integer values. The program will search for the largest and smallest values within the list and use the pointers “list_small” and “list_large” to store the locations of the smallest and largest values respectively. The program will prompt the user to enter the number of elements in the list and then ask the user to input the values one at a time using the keyboard.

The dynamic memory allocated by the code (using new) should be returned to the system at the end of the program (using delete).

Testing and Grading

Late submissions will be handled according to the policy in the course outline.

What to Submit

One file called binomial.cpp that contains the main function and all other necessary functions

Explanation / Answer

#include<iostream.h>
#include<conio.h>

void main()
{
   int *list_ptr,*list_small,*list_large;
   int a[100],i,n;  
   cout<<"Enter number of elements in the list";
   cin>>n;
  
   for(i=0;i<n;i++)
   {
       cout<<"Enter number ";
       cin>>a[i];
   }

   int min=a[0];
   for(i=0;i<n;i++)
   {
       if(a[i]<a[0])
       {
           list_small=&a[i];
           min=a[i];
       }
      
   }
   cout<<"Smallest element is at "<<list_small;

   int max=a[0];
   for(i=0;i<n;i++)
   {
       if(a[i]>a[0])
       {
           list_large=&a[i];
           max=a[i];
       }
      
   }
   cout<<" Largest element is at "<<list_large;
   getch();  
}

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