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

Simple Functions Functions that display a volde he Come Message simple message;

ID: 3822328 • Letter: S

Question

Simple Functions Functions that display a volde he Come Message simple message; Functions that do something a specified number of times (i.e. display a message x-times, etc.); Functions that calculate and return the sum, difference, quotient, product, square, cube, remainder, average, or other simple calculated value; [Overloading] Functions that return the min, max or other selection derived value based on two or more passed values; Functions that return a calculated value based a simple formula (i.e FeetTolnches, FahTocel, grossPay etc.); on Functions that display an appropriate message (i e. "Small Package, "Large Package", etc.);

Explanation / Answer

Function that dispaly a simple message

void display()
{
cout << "Hello world!";
}

Function that do something a specified number of times

void display(int n)
{
for(int i = 0; i < n; i++)
cout << "Hello world!"<<endl;
}

Functions that calculate and return the sum, difference.....

int sum(int a, int b)
{
return a+b;
}


int diff(int a, int b)
{
return a-b;
}

int quotient(int a, int b)
{
return a/b;
}

int product(int a, int b)
{
return a*b;
}

int square(int a)
{
return a*a;
}


int cube(int a)
{
return a*a*a;
}

int remainder(int a, int b)
{
return a%b;
}

int average(int a, int b)
{
return (a+b)/2;
}

Functions that return min, max, or other selection deried....

int min(int arr[], int n)
{
int minValue = arr[0];
for(int i = 1; i < n; i++)
{
if(arr[i] < minValue)
minValue = arr[i];
}
return minValue;
}


int min(int arr[], int n)
{
int maxValue = arr[0];
for(int i = 1; i < n; i++)
{
if(arr[i] > maxValue)
maxValue = arr[i];
}
return maxValue;
}

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