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
A large population of ALOHA users manages to generate 50 requests/sec, including both originals and retransmissions. Time is slo
krok68 [10]

Answer:

The answer is below

Explanation:

Given that:

Frame transmission time (X) = 40 ms

Requests = 50 requests/sec, Therefore the arrival rate for frame (G) = 50 request * 40 ms = 2 request

a) Probability that there is success on the first attempt = e^{-G}G^k but k = 0, therefore Probability that there is success on the first attempt = e^{-G}=e^{-2}=0.135

b) probability of exactly k collisions and then a success = P(collisions in k attempts) × P(success in k+1 attempt)

P(collisions in k attempts) = [1-Probability that there is success on the first attempt]^k = [1-e^{-G}]^k=[1-0.135]^k=0.865^k

P(success in k+1 attempt) = e^{-G}=e^{-2}=0.135

Probability of exactly k collisions and then a success = 0.865^k0.135

c) Expected number of transmission attempts needed = probability of success in k transmission = e^{G}=e^{2}=7.389

6 0
3 years ago
A good first step to understanding any kind of text is to :
Vitek1552 [10]

Answer:

find the main idea

Explanation:

6 0
2 years ago
How works GPS on boats?
zaharov [31]
If you mean sonar it uses echolocation but GPS is signaled from satellite to the internal antenna
8 0
3 years ago
Displays information a bout drivers, network connections, and other program-related details.
slava [35]

Answer:

library

Explanation:

hope you like it

6 0
3 years ago
Professor Midas drives an automobile from Newark to Reno along Interstate 80. His car’s gas tank, when full, holds enough gas
zmey [24]

Answer:

The GREEDY Algorithm

Explanation:

Based on the situation given in question, the Greedy algorithm shall give the optimal solution to professor

Suppose that the cities are at locations0 =x0< x1< . . . < x

We shall use the induction method to prove that G is the optimal solution valid for numbers less than n

We assume another solution Z which we initially consider to be optimum as well, based on that when Z fills the tank, it fills it to full level

Let us state the values in case of n intervals. Given below, we say that g1 is the first stop and z1 is also the first stop.

This can be written as ;

G=g1, g2, . . . , gk

Z=z1, z2, . . . , zk’

Here k’ <= k and k < n

Let I be an idex where for the first time gi is not equal to zi

Considering t= maxi Zi

Z′=g1, z2, z3, . . . , zk′

Now since z2, z3, . . . , zk′ should be an optimal stopping pattern for the problem otherwise we have chosen Z, with smaller gas filling (not feasible)

Using induction hypothesis we conclude thatg2, . . . , gk is an optimal stopping pattern, which is based on greedy algorithm

7 0
3 years ago
Other questions:
  • Which practice represents the trait of effective communication?
    6·2 answers
  • True or False?
    8·1 answer
  • What is the internet ?
    11·2 answers
  • Theodor is researching computer programming. He thinks that this career has a great employment outlook, so he'd like to learn if
    9·2 answers
  • How does cryptocurrency exchange software works?
    14·1 answer
  • Which domain indicates that a website is sponsored by a university or college?
    12·1 answer
  • What help in executing commands quickly
    5·1 answer
  • Create a two functions: first called grocery_cost(food), where food can be one item or a list of items from the stock and price
    7·1 answer
  • I think you have been doing a great job but you haven’t been signing many people up for our new service feature I want you to se
    8·1 answer
  • Write an if statement that assigns 0.2 to commission if sales is greater than or equal to 10000.
    11·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!