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

C++ on linux Create your main main.cpp, put your functions definitions in \"func

ID: 670407 • Letter: C

Question

C++ on linux

Create your main main.cpp,
put your functions definitions in "functions.h" and the function bodies in "functions.cpp"

in "main.cpp" you will test call all your functions to make sure they work properly
is is 100% your responsibility to make sure that the 4 functions you write work properly
All you code should be 100% your own work, there is no reason at all why your main.cpp should look any other, the job of the main is NOT to try to look exactly like the example
but to test to make sure you know how to use the functions and verify that they do what they are supposed to
your functions however MUST MATCH the definitions below VERBATIM the names should be exactly the same in terms of name, return type, parameter type and order
you can verify the naming with the 'make test' option described later.





there is a runable sample of a test main, pay attention to the logfile it produces especially the logging for the Sort functions


write the following functions

void SortAscending(int * target,const int count);
/* use the index operator [] to access and modify the elements DO NOT use the de-reference (*) operator
   sort the array pointed to by (target) sort (count) elements in the array in descending order
   use the BUBBLE sort logic below and the logging suggested there as well

   After calling the function the array should be sorted in ascending order
*/

void SortDescending(int * target,const int count);
/* use pointer arithmetic and the de-reference operator (*)   DO NOT use the index operator ([])
   sort the array pointed to by (target) sort (count) elements in the array in ascending order
   use the BUBBLE sort logic below and the logging suggested there as well

After calling the function the array should be sorted in descending order
*/

void PrintArray(const int * target, const int count);
/* print out (count) elements from the array pointed to by (target)
   the format should be like:
   Position:0 value:4
   Position:1 value:29
   Position:2 value:51
   ...
*/

void FillArrayWithRandom(int * target, const int count, const int min, const int max);
/* fill the array pointed to by (target) with (count) elements
   the random numbers generated should be between (min) and (max)
   you MUST use the CreateRandomNumber function in cmps222lib.h
*/






use a BUBBLE SORT with two nested for loops, do NOT use a do-while or while loop
for each iteration of the inner loop compare an element in the array with the element IMMEDIATELY following it
for example compare position 0 with 1, 1 with 2, 2 with 3, 3 with 4, 4 with 5 and so on

DO NOT VARY FROM THE BELOW LOGIC
pseudo code:
count is the number of elements in the array
myarray is the name of the array

for (outerloop 0 to less than count-1)
{
for (innerloop 0 to less than count -1)
{
LOG that you are comparing position ( innerloop ) with (innerloop+1)
compare array position innerloop with innerloop+1  
swap the values if necessary , LOG that you are swapping position (innerloop) with (innerloop+1)
}
}

Explanation / Answer

void SortAscending(int * target,const int count){
   int temp;
   for(int i = 0; i < count - 1 ; i++){
       for(int j = i + 1; j < count ; j++){
           if(target[i] > target[j]){
               temp = target[i];
               target[i] = target[j];
               target[j] = temp;
           }          
       }
   }
}
/* use the index operator [] to access and modify the elements DO NOT use the de-reference (*) operator
sort the array pointed to by (target) sort (count) elements in the array in descending order
use the BUBBLE sort logic below and the logging suggested there as well

After calling the function the array should be sorted in ascending order
*/

void SortDescending(int * target,const int count){
   int temp;
   for(int i = 0; i < count - 1 ; i++){
       for(int j = i + 1; j < count ; j++){
           if(target[i] < target[j]){
               temp = target[i];
               target[i] = target[j];
               target[j] = temp;
           }          
       }
   }
}
/* use pointer arithmetic and the de-reference operator (*) DO NOT use the index operator ([])
sort the array pointed to by (target) sort (count) elements in the array in ascending order
use the BUBBLE sort logic below and the logging suggested there as well

After calling the function the array should be sorted in descending order
*/

void PrintArray(const int * target, const int count){
  
   for(int i = 0; i < count - 1 ; i++){
       cout<<target[i]<<" "<<endl;      
   }
}
/* print out (count) elements from the array pointed to by (target)
the format should be like:
Position:0 value:4
Position:1 value:29
Position:2 value:51
...
*/

void FillArrayWithRandom(int * target, const int count, const int min, const int max){
   srand((unsigned)time(0));
int rint;
int lowest=min, highest=max;
int range=(highest-lowest)+1;
for(int i =0; i<count; i++){
target[i] = lowest+int(range*rand()/(RAND_MAX + 1.0));
  
}
/* fill the array pointed to by (target) with (count) elements
the random numbers generated should be between (min) and (max)
you MUST use the CreateRandomNumber function in cmps222lib.h
*/

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