1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
Ghella [55]
2 years ago
14

Write a program whose input is a character and a string, and whose output indicates the number of times the character appears in

the string.
Ex: If the input is:

n Monday
the output is:

1
Ex: If the input is:

z Today is Monday
the output is:

0
Ex: If the input is:

n It's a sunny day
the output is:

2
Case matters.

Ex: If the input is:

n Nobody
the output is:

0
n is different than N.





This is what i have so far.
#include
#include
using namespace std;

int main() {

char userInput;
string userStr;
int numCount;

cin >> userInput;
cin >> userStr;

while (numCount == 0) {
cout << numCount << endl;
numCount = userStr.find(userInput);

}
return 0;
}
Computers and Technology
1 answer:
nevsk [136]2 years ago
5 0
Here is a Python program:

tmp = input().split(' ')
c = tmp[0]; s = tmp[1]
ans=0
for i in range(len(s)):
if s[i] == c: ans+=1

# the ans variable stores the number of occurrences
print(ans)
You might be interested in
Sino ang pinaka matalino sa math sa buong mundo​
Svetllana [295]

Answer:

lahat ng tao ay matalino kasama ka na dun kaya lang di natin ito inilalabas dahil natatamad tayo

6 0
3 years ago
Read 2 more answers
In JAVA please:
blagie [28]

Answer:

import java.util.Scanner;

public class ArraysKeyValue {

public static void main (String [] args) {

final int SIZE_LIST = 4;

int[] keysList = new int[SIZE_LIST];

int[] itemsList = new int[SIZE_LIST];

int i;

keysList[0] = 13;

keysList[1] = 47;

keysList[2] = 71;

keysList[3] = 59;

itemsList[0] = 12;

itemsList[1] = 36;

itemsList[2] = 72;

itemsList[3] = 54;  

/* Your solution goes here */

for ( i = 0; i < SIZE_LIST; i++){

 if (keysList[i]>50){

  System.out.println(itemsList[i] + " ");  }  }

System.out.println("");

}

}

Explanation:

I will explain the whole program flow.

  • There are two arrays here
  • keysList and itemsList
  • The first list (keysList) contains the following elements:

13 element at first position of the array (0th index)

47 element at second  position of the array (1st index)

71 element at third position of the array (2nd index)

59 element at fourth position of the array (3rd index)

  • The other list (itemsList) contains the following elements:

12 element at first position of the array (0th index)

36 element at second  position of the array (1st index)

72 element at third position of the array (2nd index)

54 element at fourth position of the array (3rd index)

  • The size of the array elements is fixed which is 4 and is stored in the variable SIZE_LIST.
  • Then the loop starts. The loop contains a variable i which is initialized to 0. First it checks if the value of i is less than the size of the list. It is true as SIZE_LIST=4 and i=0.
  • So the program control enters the body of the loop.
  • In first iteration, IF condition checks if the i-th element of the keysList is greater than 50. As i=0 So the element at 0th index of the keysList is 13 which is not greater than 50 so the body of IF statement will not execute as the condition evaluates to false. The value of i increments by 1 so now i becomes 1.
  • In next iteration loop again checks if the value of i is less than the size of the list which is true again so the body of the loop executes.
  • IF condition checks if the i-th element of the keysList is greater than 50. As i=1 So the element at 1st index of the keysList is 47 which is not greater than 50 so the body of IF statement will not execute as the condition evaluates to false. The value of i is incremented by 1 so now i becomes 2.
  • In next iteration loop again checks if the value of i is less than the size of the list which is true again as i= 2 which is less than SIZE_LIST so the body of the loop executes.
  • IF condition checks if the i-th element of the keysList is greater than 50. As i=2 So the element at 2nd index of the keysList is 71 which is greater than 50 so the body of IF statement is executed as the condition evaluates to true. So in the body of the IF statement there is a print statement which prints the i-th element of the itemsList. As i = 2 so the value at the index 2 of the itemsList is displayed in the output which is 72. Next value of i is incremented by 1 so now i becomes 3.
  • In next iteration loop again checks if the value of i is less than the size of the list which is true again as i= 3 which is less than SIZE_LIST so the body of the loop executes.
  • IF condition checks if the i-th element of the keysList is greater than 50. As i=3 So the element at 3rd index of the keysList is 59 which is greater than 50 so the body of IF statement is executed as the condition evaluates to true. So in the body of the IF statement there is a print statement which prints the i-th element of the itemsList. As i = 3 so the value at the index 3 of the itemsList is displayed in the output which is 54. Next value of i is incremented by 1 so now i becomes 4.
  • In next iteration loop again checks if the value of i is less than the size of the list which is now false as i=4 which is equal to the SIZE_LIST= 4. So the loop breaks.
  • So the output of the above program is:

72

54

5 0
3 years ago
If you want to change the name or file type of an existing word processing document, what command should you use?
mezya [45]
I think that the answer is "save as"
8 0
2 years ago
Read 2 more answers
can any one tell me the difference between the things showed in the circle i will mark brainiest to the first one
Shalnov [3]

Answer:

The different brainly websites are different because they are associated with different countries. Each country has their own network and internet rules, and Brainly has to comply with each countries rules. Each country gets their own Brainly site. So, Brainly.com is for the US, Brainly.pl is for Poland, etc.

Explanation:

3 0
3 years ago
In 1993, a group of professors and students at the University of Illinois National Center for Supercomputing Applications (NCSA)
Vladimir [108]

Answer:

The answer is "False"

Explanation:

The given statement is false, which can be described as follows:

The Netscape browser is also known as the series of the name web browsers, This browser was developed by AOL's former holding company Netscape Communicative Networks Organization.

  • It was a corporation, that has been best remembered for its Navigator web browser.  
  • It is one of the two web browsers most successful in the 1990s, that's why the given statement is false.

7 0
3 years ago
Other questions:
  • Jameis is researching at his local library when he finds a perfect source to use in his paper. When he goes to check the book ou
    12·2 answers
  • Discuss why mtv initially had a difficulty securing enough ads
    10·1 answer
  • Your bluetooth headset is waiting for another bluetooth device to locate its signal. what is this mode known as?'
    8·1 answer
  • Which key is used to indent the first line of a paragraph to the right?
    15·2 answers
  • A byte contains how many bits? Question 3 options:
    13·2 answers
  • George wants to pursue a career in web technology as a web developer. Which certifications can help him as a web developer?
    5·1 answer
  • Assume that a 5 element array of type string named boroughs has been declared and initialized. Write the code necessary to switc
    5·1 answer
  • Which of the following is input devices? (a)Scanner (b) Keyboard (c) Both a and b (d) Plotter​
    5·1 answer
  • In this lab, you complete a C++ program that uses an array to store data for the village of Marengo.
    8·1 answer
  • Direction: Write True on the line if the statement is correct. Write False if the statement is incorrect. 1. All objects are com
    13·2 answers
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!