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
ddd [48]
2 years ago
14

c++ 4.17 LAB: Count characters 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. The output should include the input character and use the plural form, n's, if the number of times the characters appears is not exactly 1. Ex: If the input is: n Monday the output is: 1 n
Computers and Technology
1 answer:
Nata [24]2 years ago
5 0

Answer:

#include <iostream>

using namespace std;

int main() {

   int n = 0;

   char c;

   string str;

   cin >> c >> str;

   for (int i = 0; i < str.length(); ++i)

       if (c == str[i]) n++;

   cout << n << " n" << (n > 1 ? "'s" : "");

   return 0;

}

Explanation:

Declares variables n, c, and str.

Next a loop lets count number of character c in string str.

Finally, answer is showing.

You might be interested in
How to shutdown a computer by step by step​
Reptile [31]

<u><em> </em></u>Answer:

1) Press Ctrl + Alt + Del

2) Click the power button in the bottom-right corner of the screen.

3) From the desktop, press Alt + F4 to get the Shut Down Windows screen.

and that's how to shut down your computer

<u><em></em></u>

<u><em>Please mark as brainliest if answer is right</em></u>

Have a great day, be safe and healthy  

Thank u  

XD  

7 0
2 years ago
Read 2 more answers
Double bar graphs compare multiple what
GalinKa [24]
You would multiply by 2
7 0
3 years ago
The new tag in HTML 5 means that it explanation or pronunciation of characters for Asian typography O sets a container for an ex
Eddi Din [679]

Answer:

yes very correctExplanation:

5 0
2 years ago
What's the problem with this code ?
Svet_ta [14]
Hi,

I changed your program using some of the concepts you were trying to use. Hopefully you can see how it works:

#include <string>
#include <iostream>
#include <sstream>
#include <vector>
#include <algorithm>

using namespace std;

int main()
{
   short T;
   cin >> T;
   cin.ignore();

   string str[100];

   for(int i=0; i<T; i++)
   {
      getline(cin, str[i]);
   }

   for (int i = 0; i < T; i++)
   {
      stringstream ss(str[i]);
      string tmp;
      vector<string> v;

      while (ss >> tmp)
      {
          // Let's capitalize it before storing in the vector
          if (!tmp.empty())
          {
              transform(begin(tmp), end(tmp), std::begin(tmp), ::tolower);
              tmp[0] = toupper(tmp[0]);
           }
           v.push_back(tmp);
        }

        if (v.size() == 1)
        {
           cout << v[0] << endl;
        }
        else if (v.size() == 2)
        {
           cout << v[0][0] << ". "  << v[1] << endl;
        }
        else
        {
            cout << v[0][0] << ". " << v[1][0] << ". " << v[2] << endl;
        }
    }

     return 0;
}

4 0
3 years ago
A Java main method uses the parameter (String[ ] variable) so that a user can run the program and supply "command-line" paramete
Firdavs [7]

Answer:

The answer is "Option a"

Explanation:

  • In java, the main function is the point of entry of every java program. Its syntax always starts "public static void main" with (String args[]), in which it can also be modified by the name of the string array name.
  • It also known as an entry point is the key process. In any program, it is the first method, that executes whenever you run a program. There is one main feature in a regular app that uses instances of certain classes to operate.
4 0
3 years ago
Other questions:
  • Which online resource is usually not free?
    10·2 answers
  • According to the ethical computer use policy, users should be __________ of the rules and, by agreeing to use the system on that
    11·1 answer
  • A network router connects multiple computers together and allows them to send messages to each other. If two or more computers s
    7·1 answer
  • I have wings, I am able to fly, I‘m not a bird yet I soar high in the sky. What am I?
    14·2 answers
  • Does any one here play destiny on xbox one
    12·1 answer
  • Which questions should you ask yourself when performing research online?
    9·1 answer
  • Select the correct answer.
    10·1 answer
  • In 100 words or less, discuss why ethics is especially important for computer professionals, as it pertains to addressing profes
    5·1 answer
  • The 0-1 knapsack problem is the following. A thief robbing a store finds n items. The ith item is worth vi dollars and weighs wi
    14·1 answer
  • Assume that x and y are boolean variables and have been properly initialized. !(x || y) || (x || y) The result of evaluating the
    10·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!