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

Create a MSVS project (or a project using your preferred IDE) and add lab11.cpp

ID: 651321 • Letter: C

Question

Create a MSVS project (or a project using your preferred IDE) and add lab11.cpp (GIVEN) to the project. You will be completing the code in lab11.cpp writing statements to implement the lab project requirements described below

For this lab you must:
1. Declare and use an array of 10 integers in your main function.
2. Collect 10 integer values from the user and store these in the array
3. Create and call a function that takes the array as an argument and returns the smallest value in the array.
4. Create and call a function that takes the array as an argument and returns the largest value in the array.
5. Create and call a function that takes the array as an argument and returns the sum of the array values.
6. Create and call a function that takes the array as an argument and returns the average of the array values.
7. Create and call a function that takes the array as an argument and reverses the order of the values in the array.
   a. For example: if you pass an array with these values in this order {2,5,3,1,4}
   i. Then the array will contain these values in this order {4,1,3,5,2} after the call to the function.
8. Create and call a function takes the array as an argument and that will print out the values in the array.
   a. For example: if the array contains these values in this order {2,5,3,1,4} it will print out: 2, 5, 3, 1, 4 9. Display the smallest value in the array for the user.
10. Display the largest value in the array for the user.
11. Display the sum of the values in the array for the user.
12. Display the average of the values in the array for the user
13. Display the values in the array before it is reversed and after it is reversed

GIVEN:

Explanation / Answer

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

class a
{
public:
   void sum(int *aj, int n)
   {
       int i,s=0;

       for(i=0;i<5;i++)
       {
           s=s+(*aj);
           *aj++;
       }
       cout<<"Sum is "<<s;
       getch();
   }


   void avg(int *aj, int n)
   {
       int i,s=0,av;

       for(i=0;i<5;i++)
       {
           s=s+(*aj);
           *aj++;
       }
       av=s/n;
       cout<<" Avg. is"<<av;
       getch();
   }

   void lar(int *aj, int n)
   {

       int i,s=0,l;

       l=*aj;
       for(i=0;i<5;i++)
       {
           if(*aj>l)
           {
               l=*aj;
           }
           *aj++;
       }
       cout<<" Large no is "<<l;
       getch();
   }

   void sma(int *aj, int n)
   {

       int i,s=0,l;

       l=*aj;
       for(i=0;i<5;i++)
       {
           if(*aj<l)
           {
               l=*aj;
           }
           *aj++;
       }
       cout<<" Smallest no is "<<l;
       getch();
   }
};

int main()
{
   int ar[5],i,c;

   a o;

   clrscr();


   cout<<" Enter 5 no";
   for(i=0;i<5;i++)
   {
       cin>>ar[i];
   }

   o.sum(&ar[0], 5);
   o.avg(&ar[0], 5);
   o.lar(&ar[0], 5);
   o.sma(&ar[0], 5);


}