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

http://pastebin.ca/3379585 Notes: C++ Program using pointers. Use bubble sort to

ID: 3671828 • Letter: H

Question

http://pastebin.ca/3379585

Notes:

C++ Program using pointers.

Use bubble sort to get times each value comes in list.

Cannot use [] except for "new" function only.

You are to write code to compute some statistical information. You are to read a set of numbers from the input file “numbers.txt”.    I don’t know how many numbers are in the file, so set up your array to hold the same number of values located in the file and allocate the array dynamically. Read in the values into the allocated array.

Print out the number of values read in and the average. Determine from the list of numbers in the array the ‘mode’. The mode is the value that occurs most often in the list of numbers. (A function) Find the ‘median’ of the set of values. The median is the middle value in the list. If the list has an odd number of values, then select the middle one. If the list has even number of values, then take the average of the two middle values in the list. Next, reverse the values in the array and then print out the first 32 values of the list, 8 numbers per line. Don’t print the entire list please. Print out the number of times each value in the list appears in the list. Ex.   1-3 5-2 …   where 1 is in the list 3 times, 5 is in the list twice etc. Label each output part.

Restrictions: You must dynamically allocate your array. You must use pointers to manipulate the array.
No [ ]’s are to be found in your code. You can use the [ ]’s for ‘new’ function only.

Explanation / Answer

Hi below i written a C++ program for Bubble sort using pointers for your reference,

#include <iostream>
using namespace std;
void bubble(int*,int);//////////////////prototype

void main()
{
       int Array[5],size=5,*pointer;

       for(int num=0;num<size;num++)
       {
       cout<<"Enter element no : "<<num+1<<endl;
       cin>>Array[num];
       }
       pointer=Array;
       bubble(pointer,size);
       }

       void bubble(int *pointer,int size)
       {
              int count1,count2,swap;

              for(count1=0;count1<size-1;count1++)
              {
                     for(count2=0;count2<size-count1-1;count2++)
                     {
                    
                           if(*(pointer+count2)>*(pointer+count2+1))
                           {
                           swap=*(pointer+count2);
                           *(pointer+count2)=*(pointer+count2+1);
                           *(pointer+count2+1)=swap;
                          
                           }
                    
                     }
              }

              for(count1=0;count1<size;count1++)
              {
              cout<<*(pointer+count1)<<" , ";
              }
       };