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
If there are 8 opcodes and 10 registers, a. What is the minimum number of bits required to represent the OPCODE? b. What is the
Nimfa-mama [501]

Answer:  

For 32 bits Instruction Format:

OPCODE   DR               SR1                   SR2      Unused bits

a) Minimum number of bits required to represent the OPCODE = 3 bits

There are 8 opcodes. Patterns required for these opcodes must be unique. For this purpose, take log base 2 of 8 and then ceil the result.

Ceil (log2 (8)) = 3

b) Minimum number of bits For Destination Register(DR) = 4 bits

There are 10 registers. For unique register values take log base 2 of 10 and then ceil the value.  4 bits are required for each register. Hence, DR, SR1 and SR2 all require 12 bits in all.  

Ceil (log2 (10)) = 4

c) Maximum number of UNUSED bits in Instruction encoding = 17 bits

Total number of bits used = bits used for registers + bits used for OPCODE  

     = 12 + 3 = 15  

Total  number of bits for instruction format = 32  

Maximum  No. of Unused bits = 32 – 15 = 17 bits  

OPCODE                DR              SR1             SR2              Unused bits

  3 bits              4 bits          4 bits           4 bits                17 bits

7 0
3 years ago
Advantages of using Unicode to represent data
Alona [7]
Global source and binary.
Support for mixed-script computing environments.
Improved cross-platform data interoperability through a common codeset.
Space-efficient encoding scheme for data storage.
Reduced time-to-market for localized products.
Expanded market access.
5 0
2 years ago
Enter the database function in cell i6 that determines the average salary of all full-time employees with at least one dependant
love history [14]

Based on the given spreadsheet, the database function that needs to be entered into cell I6 to find the average salary of all full-time employees is =AVERAGEIFS(D5:D34,B5:B34,"FT",C5:C34,">=1")

<h3>What does the AverageIfs formula find?</h3>

You can use the AverageIfs formula to find the average of a specific group of numbers from a spreadsheet based on the shared categories that these numbers fall under.

After typing in the =AverageIfs function, you then input the range from which the category will be specified. In this case that is D5:D34. The next entry would be the range the category is picked from which is  B5:B34. The function will be FT for Full time workers.

Then use C5:C34 to find out the number of dependents that are equal to or greater than 1.

The digit returned is the average salary of all full-time employees.

Find out more on the AverageIf function at brainly.com/question/13661607

#SPJ1

4 0
2 years ago
Which advertising medium has the widest reach on a global front?
lesya [120]

Answer: B

The internet would allow businesses to easily expand globally with the help of social media and the ever expanding resources being poured onto the internet, reaching customers anywhere in the world.

8 0
3 years ago
Unit 6: Lesson 2 - Coding Activity 1 AP Computer science
sladkih [1.3K]

The complete program is to define a boolean method that returns true if all elements of an array are negative, or return false, if otherwise

The method in java, where comments are used to explain each line is as follows:

//This defines the method

public static boolean chkNegative (double[] myArr) {

   //This initializes a boolean variable

   boolean isNeg = true;

   //This iterates through the array

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

     //If the array element is 0 or positive

     if (myArr[i] >= 0) {

         //Then the boolean variable is set to false

       isNeg = false;

       //And the loop is exited

       break;

     }

   }

   //This returns true or false

   return isNeg;

 }

Read more about boolean methods at:

brainly.com/question/18318709

8 0
2 years ago
Other questions:
  • Nancy would like to configure an automatic response for all emails received while she is out of the office tomorrow, during busi
    13·2 answers
  • Rewrite this method so that it avoids the use of a return statement:
    15·1 answer
  • A collision volume is called ____
    7·1 answer
  • An email message form includes all of the following main areas except
    11·2 answers
  • What type of electronic monitoring involves an offender being contacted periodically by telephone or beeper to verify his or her
    5·1 answer
  • To read visual and audio text means
    11·1 answer
  • What important practice can help prevent hardware trouble?
    6·1 answer
  • Data types influence the following in the workflow: (Select all that apply)a. the color choices and layout decisions around comp
    15·2 answers
  • This isn't an academic question, but can anyone help me change the face on my apple watch to a picture from my camera roll? I've
    15·1 answer
  • Define a function FindLargestNum() with no parameters that reads integers from input until a negative integer is read. The funct
    9·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!