Question

In: Computer Science

Using C++ Write One one single program with two or more functioncallsWrite a C++...

Using C++ Write One one single program with two or more function calls

  1. 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.

  2. 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.

Solutions

Expert Solution

#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]            //if yes make that element index as min index
           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.


Related Solutions

Write a C++ class that implement two stacks using a single C++ array. That is, it...
Write a C++ class that implement two stacks using a single C++ array. That is, it should have functions pop_first(), pop_second(), push_first(…), push_second(…), size_first(), size_second(), …. When out of space, double the size of the array (similarly to what vector is doing). Notes: Complete all the functions in exercise_2.cpp, then submit this cpp file. pop_first() and pop_second() should throw std::out_of_range exception when stack is empty. CODE: #include <cstdio> #include <stdexcept> template <class T> class TwoStacks { public:   // Constructor, initialize...
Using Virtualbox in Debian, write a simple program (a single .cpp file) in Linux shell C++...
Using Virtualbox in Debian, write a simple program (a single .cpp file) in Linux shell C++ Rules: -Use fork(), exec(), wait(), and exit() _______________________________________________________________________________________________________________________________________________ -A line of input represents a token group. -Each token group will result in the shell forking a new process and then executing the process. e.g. cat –n myfile.txt // a token group -Every token group must begin with a word that is called the command(see example above). The words immediately following a command are calledarguments(e.g....
Using Virtualbox in Debian, write a simple program (a single .cpp file) in Linux shell C++...
Using Virtualbox in Debian, write a simple program (a single .cpp file) in Linux shell C++ Rules: -Use fork(), exec(), wait(), and exit() _______________________________________________________________________________________________________________________________________________ -A line of input represents a token group. -Each token group will result in the shell forking a new process and then executing the process. e.g. cat –n myfile.txt // a token group -Every token group must begin with a word that is called the command(see example above). The words immediately following a command are calledarguments(e.g....
Using c++, write a program that reads a sequence of characters from the keyboard (one at...
Using c++, write a program that reads a sequence of characters from the keyboard (one at a time) and creates a string including the distinct characters entered and displays the string on the screen. The input terminates once the user enters a white-space character or the user has entered 50 distinct characters. Do not use C-Strings. 2. Use the following function to append character “ch” to the string “s”: s.push_back(ch); 3. Read the input characters one by one, i.e. do...
Using c# , Write a program using a switch statement that takes one character value from...
Using c# , Write a program using a switch statement that takes one character value from the user and checks whether the entered value is an arithmetic operator (+, -, * , /) If not the program display a message that it not of the operators ( (+, -, * , /) .
Write a program using c++. Write a program that uses a loop to keep asking the...
Write a program using c++. Write a program that uses a loop to keep asking the user for a sentence, and for each sentence tells the user if it is a palindrome or not. The program should keep looping until the user types in END. After that, the program should display a count of how many sentences were typed in and how many palindromes were found. It should then quit. Your program must have (and use) at least four VALUE...
I am using C++ Write a program that allows two players to play a game of...
I am using C++ Write a program that allows two players to play a game of tic-tac-toe. Use a two-dimensional char array with three rows and three columns as the game board. Each element of the array should be initialized with an asterisk (*). The program should run a loop that does the following: Displays the contents of the board array. Allows player 1 to select a location on the board for an X. The program should ask the user...
write a Program in C++ Using a structure (struct) for a timeType, create a program to...
write a Program in C++ Using a structure (struct) for a timeType, create a program to read in 2 times into structures, and call the method addTime, in the format: t3 = addTime(t1, t2); Make sure to use add the code to reset and carry, when adding 2 times. Also, display the resultant time using a function: display(t3);
Write a C program that does the following In this part, you will write more complicated...
Write a C program that does the following In this part, you will write more complicated functions. They will require parameters and return values. The purpose is to give you experience with these components, and to show you how functions can be used to break your code down into smaller parts. You will also get some more experience with iterating through arrays.Open repl project Lab: User-Defined Functions 2. Write a program that does the following: 1.(20 pts.) Allows the user...
Can you solve this C program by using Function? Q1. Write a C program to ring...
Can you solve this C program by using Function? Q1. Write a C program to ring the computer bell at any number of times you specify. Use the system clock as a delay, you need to include the time header file.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT