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

INSTRUCTIONS C++ In this assignment, we will be writing a series of functions th

ID: 3674610 • Letter: I

Question

INSTRUCTIONS C++

In this assignment, we will be writing a series of functions that use array and pointer notation for passing arguments. In your main() function, declare an array of 20 integers and a string containing a hard-coded sentence (in a char[]). Try to make your sentence at least 20 characters. Use #define statements to state the size of both arrays upfront. Write the following functions and demonstrate their use in main().

Function #1

Signature: int ReturnLargest(int[])

Description: This function takes in an array of numbers and returns the value of the largest number in the array. When accessing the array, you must use array notation in your logic ([])

Function #2

Signature: int ReturnSmallest(int*)

Description: This function takes in an array of numbers and returns the value of the smallest number in the array. When accessing the array, you must use pointer notation in your logic (*)

Function #3

Signature: int ToUpperCase(char*)

Description: This function takes in a string and converts all lower-case letters to upper-case letters. The function then returns an integer reflecting the number of characters that were changed in the string. When accessing the array, you may use any notation that you desire.

Explanation / Answer


#include<iostream>
#include<stdlib.h>
#include<time.h>
#include<locale>
using namespace std;

#define aSize 20

int ReturnLargest(int aRay[]);
int ReturnSmallest(int* a);
int ToUpperCase(char* n);

int main()
{
   srand(time(NULL));
   int aRay[aSize];
   char name[] = "Banana McMasters, the Private Investigator.";

   for (int c = 0; c < aSize; c++)
   {
       aRay[c] = rand() % 999 + 1;
   }

   char *n;
   int *a;
   n = name;
   a = aRay;

   cout << "Largest: " << ReturnLargest(aRay) << endl;
   cout << "Smallest: " << ReturnSmallest(a) << endl;
   cout << "Lower Cases Letters: " << ToUpperCase(n) << endl;

    return 0;
}

int ReturnLargest(int aRay[])
{
   int largest = 0;

   for (int c = 0; c < aSize; c++)
   {
       if (aRay[c] > largest)
       {
           largest = aRay[c];
       }
   }

   return largest;
}

int ReturnSmallest(int* a)
{
   int smallest = 1000;

   for (int c = 0; c < aSize; c++)
   {
       if (a[c] < smallest)
       {
           smallest = a[c];
       }
   }

   return smallest;
}

int ToUpperCase(char* n)
{
   int count = 0;
   int c = 0;

   while (n[c])
   {
       char x = n[c];
       if (islower(x))
       {
           count++;
           x = toupper(x);
       }
       n[c] = x;
       c++;
   }

   return count;
}


sample output

Largest: 999                                                                                                                                                
Smallest: 20                                                                                                                                                
Lower Cases Letters: 32                                                                                                                                     

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