Your program must define and call the following function that returns the number of times the input character appears in the input string. int CountCharacters(char userChar, string userString)

Answers

Answer 1
Answer:

Answer:

The program to this question can be given as:

Program:

#include <iostream>  //header file

using namespace std;  //using name space.

int CountCharacters(char userChar,string userString) //define function.

{    

int count = 0;  //define variable

for (int i=0;i<userString.length();i++) //loop

if (userString[i]==userChar)  //if block

count++;  //increment the value.

return count;  //return value.

}

int main()  //main method.

{

   string userString= "Clanguage";  //define variable and assign value.

   char userChar = 'a';   //define variable and assign value.

   cout << CountCharacters(userChar,userString);  //calling function and print value.  

   return 0;  

}

Output:

2

Explanation:

  • In the above C++ programming language program we define a function that is "CountCharacters". Inside function parameters, we pass two parameters that are "userChar and userString". The userChar is a char variable that holds single character value and userString is a string variable that holds a string value.
  • In the function, we define an integer variable that is "count". This variable counts the match value and returns its value.
  • To counts values, we define a loop in a loop we use if statement that counts the value that how many time it occurs in a string value and return its value.
  • In the main method, we define these variables ("userChar and userString") and assign values that are "a and Clanguage " and call the function and print function return value.

Related Questions

If a student fails to recognize how to properly quote the words of an author, that student may be found guilty of _____. A. intentional plagiarism B.unintentional plagiarism C. intentional citation D. unintentional reference
What political, cultural and economical impact did the telescope have during the renaissance era?​
Because a chart is _______, it can be dragged to another area of the worksheet. A. a picture B. clip art C. a table D. a graphic
The most basic function of firewalls is to
Which of the following is most likely to be used in a garment factory to solve problems like defective inputs, broken machine parts, or a worker''s lack of skills to product a specific type of garment?

ethics and internal control are important applications in accounting . Provide FIVE code of ethics and five internal control measures that any business can adopt. explain fully

Answers

ethics:
- to ensure that privacy will not be lost.
-ensuring personal information is not lost
-information in the accountings will not be submitted or shared with anyone
-information will be saved and viewed by the business.
- The business will not falsely make the accountings.

While there are hundreds of different operating systems, there are only three basic categories, which are... Option 1: Proprietary, open-source, and embedded Option 2: Windows, macOS, and Linux Option 3: Mobile, desktop, and server Option 4: Unix, Linux, and Android

Answers

Answer:

1: Proprietary, open-source, and embedded

Explanation:

To begin with, 'Windows, macOS and Linux' aren't categories. They're names (and also specific examples of operating systems). Technically Option 3 is also correct, but it's not as 'technical' as Option 1. Option 4 is just completely wrong, Linux is based off of Unix, and Android is based off of Linux. Again, those aren't categories.

Now onto the full explanation:

Windows is an operating system made by Microsoft, macOS is made by Apple, and Linux was originally created by Linus Torvalds.

A good tie-in between the explanation of Option 1 and 2 is that, Windows and MacOS are proprietary (owned by a person or company, the code is not publicly shared), and Linux is open-source (the general public can contribute code, albeit within reason).

Embedded operating systems aren't common-place in commercial desktop computers, but in offices generally there are plenty of them. Coffee machines run on embedded operating systems (although a fair few actually run off Linux surprisingly), printers run on embedded operating systems, and essentially the Internet of Things as a collective run on embedded operating systems.

A table has several fields related to computer data. You want the serial number (Sr. No.) field to increase by one every time you add a new record. Which data type would you use for the Sr. No. field?autonumber
memo
null
BLOb

Answers

The answer is Autonumber.

AutoNumber data type is commonly used for primary key fields and it automatically generates a unique number for each record. This data type stores an integer that Access increments automatically as you continue adding new records. Primary keys are great but Auto numbers are also important for insuring that records are uniquely identified.  


autonumber
-----------------------------------------

Examples of three different types of computer storage

Answers

Hard disk, SD, USB. I think. Unless the question wants file storage methods.

With a presentation open, you can hover your mouse pointer over a design theme on the Design tab, and PowerPoint will display the current slide with the design theme formatting applied. This is an example of the ____ feature.

Answers

Answer: Live preview

Explanation:

The live preview feature enables to display the current slide with the design theme formatting applied with the mouse pointer. This feature is also available in digital cameras where the screen can be used as viewfinder.

What is printed by the following program? var numApples = 10; var numOranges = 5; if(numApples < 20 || numOranges == numApples){ println("Hello, we are open!"); } else { println("Sorry, we are closed!"); } println("Sincerely, the grocery store");

Answers

Answer:

The output of the following code is "Hello, we are open! Sincerely, the grocery store ".

Explanation:

In the given code firstly we declare the variable that is numApples and numOranges. In this variable we assign value and the datatype of the variable is var. The var datatype can hold any type of data. Then we use the conditional statement. In the conditional statement, we use the OR logical operator. In the if block we check the condition that is if numApples variable value is less then 20 OR numOranges variable value is equal to numApples then it will print "Hello, we are open!". In the else block it will print "Sorry, we are closed!". In the last, we print "Sincerely, the grocery store".So in this question, if block is executed and the additional message is printed.