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: Ex: If the input is: z Today is Monday, the output is: Ex: If the input is: n It's a sunny day, the output is Case matters. Ex: If the input is: n Nobody, the output is: n is different than N LAB ACTIVTY 4.12.1: LAB: Count characters 6/10 LAB ACTIVTY 4.12.1: LAB: Count characters 6/10 main.cpp Load default template... 1 #include«iostream» 2 using namespace std; 3 int mainO t 4 5 char C; 6 cin c 8 string s; 9 getline(cin, s); 10 11 int ct-0; 12 13 while (s. find(c) != string ::npos ) { 14 ct ct + 1; 15 s = s, find (c, s. find(c) + 1); 16 17 cout << ct << endl; 18 return 0: Total score: 6/10 Latest submission- 3:56 AM on 04/30/19 Only show failing tests Download this submission 1: Compare output 2/2 Input n Monday Your output 1 2: Compare output 2/2 Input z Today is Monday Your output 0 0/2 : Compare output Output differs. See highlights below. Input n It's a sunny day Your output Expected output2 4: Compare output 0/2 Output differs. See highlights below Input t this is a sentence with many t's Your output Expected output 2/2 5: Compare output Input x X Your output 0

Answers

Answer 1
Answer:

Answer:

Following are the code to the given question:

#include<iostream>//including the header file  

using namespace std;

int count_Characters(char ch, string s)//defining a method count_Characters that holds two variable as a parameter

{

int c=0,i;//defining integer variable

for(i=0;i<s.size();i++)//using for loop to check value

{

   if(s[i]==ch)//use if block to check string and char value

   {

       c=c+1;//incrementing c value

   }

}

return c;//return c value

}

int main() //defining main method

{

char ch;//defining char variable

cin>>ch;//input char value

string s;//defining string variable

cin>>s;//input string value

cout<<count_Characters(ch,s);//calling method count_Characters

return 0;

}

Output:

n Nobody

0

n Monday

1

Explanation:

In this code, a method "count_Characters" is declared that accepts one sting and one char variable as a parameter "s, ch", and inside the method a two integer variable and for loop is declared that uses the if block to match string and char value and increments the c variable value.

In the main method two-variable "s, ch" is declared that inputs the value from the user-end and pass the value into the method, and prints its values.


Related Questions

Implement the RC4 stream cipher in C++. User should be able to enter any key that is 5 bytes to 32 bytes long. Be sure to discard the first 3072 bytes of the pseudo random numbers. THE KEY OR THE INPUT TEXT MUST NOT BE HARD CODED IN THE PROGRAM.
In real-world environments, once the domains that are affected by the risks are identified, subsequent next steps would include:______.
Implement a java program to find the smallest distance between two neighbouring numbers in an array.
An attacker has obtained the user ID and password of a data center's backup operator and has gained access to a production system. Which of the following would be the attacker's NEXT action? A. Perform a passive reconnaissance of the network. B. Initiate a confidential data exfiltration process C. Look for known vulnerabilities to escalate privileges D. Create an alternate user ID to maintain persistent access
How can we make our programs behave differently each time they are run?

Write a program that accepts a four digit number, such as 1998, and displays it on number on a line, like: 1 9 9 8 The program should prompt for a four digit number. The program assumes that the user enters the correct information. Provide the java code, including a comment with your name, course code and date.

Answers

package brainly;

import java.util.*;

/**

*

* @author CotrinaAlejandra

*/

public class Brainly {

   /*Provide the java code, including a comment with your name, course code and date.

   Name:  

   Course:  

   Date: */

   public static void main(String[] args) {

       // TODO code application logic here

       int number;

       Scanner sc = new Scanner(System.in);

       System.out.print("Write a four digit number: ");

       number=sc.nextInt();

       String newLine= String.valueOf(number);

       System.out.println(newLine.charAt(0)+"  "+newLine.charAt(1)+"  "+newLine.charAt(2)+"  "+newLine.charAt(3));

       

       

   }

   

}

Write a program to calculate how much to tip a waiter person based on the quality of service. The script file should ask for the amount of the check and whether the service was good, fair or poor. If the service was good, the tip should be 20%. If the service was fair, the tip should be 15%. If the service was poor, the tip should be 5%. The program should display the tip and the total of the check including the tip.

Answers

Answer:

Since Python is a scripting language, here is code in python.

#prompt user to give check

amount=float(input("Please Enter the check:"))

#prompt user to give service

service=input("Please Enter the service (good, fair or poor):")

# calculate tip on the basis of service

if service =="good":

   tip=amount*0.2

elif service=="fair":

   tip=amount*0.15

elif service=="poor":

   tip=amount*0.05

#calculate total

total=amount+tip

#print tip

print("tip is equal to : {} ".format(tip))

#print total

print("total of the check is : {} ".format(total))

Explanation:

Prompt user to give check and service input.After taking the input from user, based on the service tip will be calculated. if service is "good" then tip will be 20% of the check, tip will be 15% if service is "fair" and tip will be 5% if service is "poor".

Output:

Please Enter the check:125                                                                                                

Please Enter the service (good, fair or poor):good                                                                        

tip is equal to : 25.0                                                                                                    

total of the check is : 150.0

Write a function copy that takes two arrays A and B, both of size N. The function then copies all N values from A into B and then displays it.

Answers

Answer:

Written in C++

#include<iostream>

using namespace std;

int main()

{

int N;

cout<<"Length of Array: ";

cin>>N;

int A[N], B[N];

for(int i =0;i<N;i++)  {

 cin>>A[i];

}

for(int i =0;i<N;i++)  {

 B[i] = A[i];

}

for(int i =0;i<N;i++)  {

 cout<<B[i]<<" ";

}  

return 0;

}

Explanation:

This line declares the length of the Array; N

int N;

This line prompts user for length of array

cout<<"Length of Array: ";

This line gets user input for length of array

cin>>N;

This line declares array A and B

int A[N], B[N];

The following iteration gets input for Array A

for(int i =0;i<N;i++)  {

 cin>>A[i];

}

The following iteration gets copies element of Array A to Array B

for(int i =0;i<N;i++)  {

 B[i] = A[i];

}

The following iteration prints elements of Array B

for(int i =0;i<N;i++)  {

 cout<<B[i]<<" ";

}  

Answer this question without running pin again. Assume that the 100,000 element integer array that you allocated starts at address 0x50000000 in memory, the size of an integer is 4 bytes and the D-cache is initially empty. As you read the integers in the array one-by-one, starting at index 0, how many D-cache misses will you see for reading the first 40 integers when the cache block size is:

Answers

Answer:

adaddsad

Explanation:

Whichof following can be thrown using the throw statement?ErrorThrowableExceptionRuntimeExceptionAll of Given

Answers

Answer: Exception

Explanation: A throw statement is a statement that whenever it gets executed ,it stops the flow of the execution immediately. The throw statement has a throw keyword for stopping of the execution which is denoted as the exception. A checked or unchecked exception can only be thrown. The compiler of a program has the function of giving warning if there are chances of exception.

Define a function that takes two arguments: a string called strText and a number called intNumber. This function will use a repetition structure (a While or For loop) to print strText intNumber of times. Call this function.

Answers

Answer:

public class Main

{

   public static void printString(String strText, int intNumber) {

       for(int i=0; i<intNumber; i++){

           System.out.println(strText);

       }

   }

   

public static void main(String[] args) {

       

       printString("Brainly", 3);

}

}

Explanation:

- Define a function called printString that takes two parameters - a String and an int. Since the function will print out the given String, it's type will be void.

- Use for loop to iterate according to the given number and print the given string

- In the main, call the printString function with some parameters.

Answer:

// Class declaration

public class Printer {  

   // Define the function and call it printMany

   // The return type is void since it doesn't necessarily return any value.

   // It just prints to the console.

   // It takes two arguments strText of type String and

   // intNumber of type int.

  public static void printMany(String strText, int intNumber){          

       // Initialize the loop counter i to 1;

       int i = 1;

      //Create a while loop that goes

      // from i = 1 to  i = intNumber.

      // Where intNumber is the number of times the string strText

      // will be printed.

      while(i <= intNumber) {

           

           // At each of the cycle of the loop;

           // print out the string strText

           // and increment the value of the loop counter by 1

           System.out.println(strText);

           i++;

       }                 // End of while loop

   }               // End of method, printMany, declaration

// Write the main method to call the printMany function

public static void main(String[] args) {

       // Call the printMany function by supplying sample arguments;

       // In this case, strText has been given a value of "Omobowale"

       // And intNumber has been given a value of 4

       // Therefore, "Omobowale" will be printed 4 times.

       printMany("Omobowale", 4);

   }            //  End of main method

}          // End of class declaration

Sample Output:

When the program above is run, the following will be the output;

----------------------------------------------------

Omobowale

Omobowale

Omobowale

Omobowale

-------------------------------------------------------

Explanation:

Comments:

* The above code has been written in Java

* The code contains comments explaining every part of the code. Kindly go through the comments.

The whole code without comments is re-written as follows;

public class Printer {      

   public static void printMany(String strText, int intNumber){    

       int i = 1;

       while(i <= intNumber){

           System.out.println(strText);

           i++;

       }

   }      

   public static void main(String[] args) {

       printMany("Omobowale", 4);

   }

}