In: Computer Science
Using C++ Write One one single program with two or more function calls
Write a C++ function, smallest Index, that takes as parameters an int array and its size and returns the index of the smallest element in the array. Also the program should test the function.
Write another function that prompts the user to input a string and outputs the string in uppercase letters. You must use a character array to store the string.
#include
using namespace std;
//function to find minimum element idex in the array
int indexOf(int arr[],int size)
{
//let take first index as min index
int min = 0;
//Loop will iterate through the given array
for(int i=1;i
//Check for any element is less
than curent min index element
if(arr[i]
min = i;
}
//return minimum index
return min;
}
//function to take input string and convert it to uppercase
void StringUpper()
{
//Declare string as character array
char str[100];
//Prompt user for string
cout << "Enter String : ";
//Take input from user
cin >> str;
//Lopo will iterate through the string
for (int i = 0; str[i] != '\0'; i++) {
//check the character is in lowercase
if (islower(str[i]))
//if yes then change it to uppercase
str[i] = toupper(str[i]);
}
//Output the uppercae string
cout << "in Uppercase : " << str << endl;
}
//test function main
int main () {
//We take a sample array
int a[] = {2,5,3,2,4,4,1,5,3,32134,5645,52,32};
//Callin the indexOf() function and print the
output
cout << "Index of minimum element is : "
<< indexOf(a,13) << endl;
//calling the stringUpper function
StringUpper();
}
CODE SCREENSHOT:
OUTPUT:
In indexOf function,
first we take 0th index as min index and then we check for all the indexes in the array
if any element is less than the current min index element thn we change the min index value to that index.
at last we return the value in min variable.
in stringUpper function,
first we take input string from user which is stored in char array
and then we iterate though the char array and we check every character whether it is lower or not by using islower() function.
and if yes the we change that letter to uppercase by using the toupper function.
and we output the string of uppercase.