Question

In: Computer Science

Create a Visual Studio console project named exercise093. In the exercise093.cpp file first define a function...

Create a Visual Studio console project named exercise093. In the exercise093.cpp file first define a function

void lowerToUpper(std::string & sentence)

that iterates over all characters in the sentence argument. Any lowercase letter should be converted to uppercase. This can be done by including <cctype> and testing each character in sentence with the islower() function. If islower(sentence[i]) returns true then sentence[i] should be replaced with toupper(sentence[i]). The main() function should assign "Hello how are you doing?" to sentence, call lowerToUpper(sentence), and use an if statement to check the new value of sentence. If the result is correct then main() should return 0 as usual. If the result is not correct then main() should display a descriptive error message (indicating the function called, argument and the incorrect result) on the console, and main() should return -1. This provides a unit test for the lowerToUpper() function.

Finally, see what happens when you rerun the program after changing the function interface to

void lowerToUpper(std::string sentence)

Solutions

Expert Solution

Please find below code in c++ and don't forget to give a Like

Note: Given scenario has a method with void but mentioned that this method should return a sentence to main function. If the void is present this can't return any value. So, changed the void to String type and returning the converted string to main function.

Code:

#include <iostream>
#include <cctype>
#include <string>
using namespace std;
string lowerToUpper(std::string sentence){
string new_se="";
for(int i=0;i<sentence.length();i++){
if(islower(sentence[i])){
new_se+=toupper(sentence[i]);
}
else{
new_se+=sentence[i];
}
}
return new_se;
}

int main()
{
string sentence,new_sentence;
cout<<"Hello how are you doing?\n";
cout<<"Enter sentence to convert: ";
getline(cin,sentence);
new_sentence=lowerToUpper(sentence);
if(new_sentence==sentence){
cout<<"the function called, argument and the incorrect result";
return -1;
}
else{
return 0;
}
  
}

Screenshot of code and output:


Related Solutions

ceate a Visual Studio console project named exercise093. In the exercise093.cpp file first define a function...
ceate a Visual Studio console project named exercise093. In the exercise093.cpp file first define a function void lowerToUpper(std::string & sentence) that iterates over all characters in the sentence argument. Any lowercase letter should be converted to uppercase. This can be done by including and testing each character in sentence with the islower() function. If islower(sentence[i]) returns true then sentence[i] should be replaced with toupper(sentence[i]). The main() function should assign "Hello how are you doing?" to sentence, call lowerToUpper(sentence), and use...
Create a new Visual Studio console project named assignment042, and translate the algorithm you developed in...
Create a new Visual Studio console project named assignment042, and translate the algorithm you developed in Assignment 04.1 to C++ code inside the main() function. Your program should prompt for a single 9-digit routing number without spaces between digits as follows: Enter a 9-digit routing number without any spaces: The program should output one of: Routing number is valid Routing number is invalid A C++ loop and integer array could be used to extract the routing number's 9 digits. However...
Create a C# .NET Core Console project in Visual Studio. (This is the same kind of...
Create a C# .NET Core Console project in Visual Studio. (This is the same kind of project we have been doing all semester.) Do all of the following in the Program class. You do not need to add any other classes to this project. 2. If it exists, remove the Console.WriteLine(“Hello World!”); line that Visual Studio created in the Program class. 3. At the very top of the Program.cs page you should see using System; On the empty line below...
Create a Visual Studio console project (c++) containing a main() program that declares a const int...
Create a Visual Studio console project (c++) containing a main() program that declares a const int NUM_VALUES denoting the array size. Then declare an int array with NUM_VALUES entries. Using a for loop, prompt for the values that are stored in the array as follows: "Enter NUM_VALUES integers separated by blanks:" , where NUM_VALUES is replaced with the array size. Then use another for loop to print the array entries in reverse order separated by blanks on a single line...
Create a Visual Studio console project using c++ void lowerToUpper(std::string & sentence) that iterates over all...
Create a Visual Studio console project using c++ void lowerToUpper(std::string & sentence) that iterates over all characters in the sentence argument. Any lowercase letter should be converted to uppercase. This can be done by including <cctype> and testing each character in sentence with the islower() function. If islower(sentence[i]) returns true then sentence[i] should be replaced with toupper(sentence[i]). The main() function should assign "Hello how are you doing?" to sentence, call lowerToUpper(sentence), and use an if statement to check the new...
Write a C program The Visual Studio project itself must make its output to the Console...
Write a C program The Visual Studio project itself must make its output to the Console (i.e. the Command Prompt using printf) and it must exhibit the following features as a minimum: 3%: Looping Menu with 3 main actions: View Cars, Sell Car, View Sales Note: A Car is defined by its price and model 3%: Must contain at least three arrays to record sales figures (maximum of 10 Car models) Two for recording the price and model of one...
Create a C++ project in visual studio. You can use the C++ project that I uploaded...
Create a C++ project in visual studio. You can use the C++ project that I uploaded to complete this project. 1. Write a function that will accept two integer matrices A and B by reference parameters, and two integers i and j as a value parameter. The function will return an integer m, which is the (i,j)-th coefficient of matrix denoted by A*B (multiplication of A and B). For example, if M = A*B, the function will return m, which...
1. Make a Console App (.NET Core) in Visual Studio and name it as A1YourFirstnameLastname. 2....
1. Make a Console App (.NET Core) in Visual Studio and name it as A1YourFirstnameLastname. 2. Implement a vehicle rental management system which is capable of doing the following: • View all, available and reserved vehicles. • Reserve vehicle or cancel a reservation. 3. The application must be menu-based app: 1 - View all vehicles 2 - View available vehicles 3 - View reserved vehicles 4 - Reserve a vehicle 5 - Cancel reservation 6 - Exit 4. NOTE: At...
Create a file named StudentArrayList.java,within the file create a class named StudentArrayList. This class is meant...
Create a file named StudentArrayList.java,within the file create a class named StudentArrayList. This class is meant to mimic the ArrayList data structure. It will hold an ordered list of items. This list should have a variable size, meaning an arbitrary number of items may be added to the list. Most importantly this class should implement the interface SimpleArrayList provided. Feel free to add as many other functions and methods as needed to your class to accomplish this task. In other...
answer in c++ First – take your Box02.cpp file and rename the file Box03.cpp Did you...
answer in c++ First – take your Box02.cpp file and rename the file Box03.cpp Did you ever wonder how an object gets instantiated (created)? What really happens when you coded Box b1; or Date d1; or Coord c1; I know you have lost sleep over this. So here is the answer………. When an object is created, a constructor is run that creates the data items, gets a copy of the methods, and may or may not initialize the data items....
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT