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
DedPeter [7]
3 years ago
7

The intention of this problem is to analyze a user input word, and display the letter that it starts with (book → B).

Computers and Technology
1 answer:
yulyashka [42]3 years ago
3 0

Answer:

Here is the C++ program:

#include<iostream>  // to use input output functions

using namespace std;     //to identify objects like cin cout

void StartChar(string str)  {  // function that takes a word string as parameter and returns the first letter of that word in capital

   int i;  

   char c;

   do  //start of do while loop

   {

   for (int i = 0; i < str.length(); i++) {  //iterates through each character of the word str

       if(str.length()>25){  //checks if the length of input word is greater than 25

           cout<<"limit exceeded"; }  //displays this message if a word is more than 25 characters long

      c = str.at(i);   // returns the character at position i

       if (! ( ( c >= 'a' && c <= 'z' ) || ( c >= 'A' && c <= 'Z' ) ) ) {  //checks if the input word is contains characters other than the alphabet

            cout<<str<<" is not a word!"<<endl; break;}  //displays this message if user enters characters other than the alphabet

        if (i == 0) {  //check the first character of the input word

           str[i]=toupper(str[i]);  //converts the first character of the input word to uppercase

           cout<<str<<" starts with letter "<<str[i]<<endl;  }  // prints the letter that the word starts with in capital letter

   }   cout<<"Enter a word: ";  //prompts user to enter a word

      cin>>str;   //reads input word from user

}while(str!="#");   }    //keeps prompting user to enter a word until the user enters #

int main()   //start of the main() function body

{ string str;  //declares a variable to hold a word

cout<<"Enter a word: "; //prompts user to enter a word

cin>>str; //reads input word from user

   StartChar(str); }  //calls function passing the word to it

     

Explanation:

The program prompts the user to enter a word and then calls StartChar(str) method by passing the word to the function.

The function StartChar() takes that word string as argument.

do while loop starts. The for loop inside do while loop iterates through each character of the word string.

First if condition checks if the length of the input word is greater than 25 using length() method which returns the length of the str. For example user inputs "aaaaaaaaaaaaaaaaaaaaaaaaaaa". Then the message limit exceeded is printed on the screen if this if condition evaluates to true.

second if condition checks if the user enters anything except the alphabet character to form a  word. For example user $500. If this condition evaluates to true then the message $500 is not a word! is printed on the screen.

Third if condition checks if the first character of input word, convert that character to capital using toupper() method and prints the first letter of the str word in capital. For example if input word is "Computer" then this prints the message: Computer starts with the letter C in the output screen.

The program keeps prompting the user to enter the word until the user enters a hash # to end the program.

The output of the program is attached.

You might be interested in
When assigning a value to a string, which of the following rules needs to be followed?
Alecsey [184]

Answer:

Let's say you need to remember some information, the way moviegoers tried to remember the name of the movie. Instead of storing it in your human memory, you can store information in your computer's memory using Python. This is called assigning a string value to a variable.

To assign a string value to a variable in Python, follow this example. Select each part of the code to see how it works with the movie title example.

movieTitle = "Live. Die. Repeat."

This line of Python code is an example of an assignment statement. In an assignment statement, you tell Python, "This variable is assigned this string value."

Explanation:

4 0
3 years ago
State whether true or false.
Rufina [12.5K]
True. hope this helped!!
7 0
4 years ago
What are the major features of React?
marysya [2.9K]

<em>JSX - JavaScript Syntax Extension. JSX is a syntax extension to JavaScript. </em>

<em>Virtual DOM. React keeps a lightweight representation of the “real” DOM in the memory, and that is known as the “virtual” DOM (VDOM)</em>

<em>Performance. ...</em>

<em>Extensions. ...</em>

<em>One-way Data Binding. ...</em>

<em>Debugging. ..</em><em>.</em>

<em>Components. ...</em>

<em>State.</em>

3 0
3 years ago
Good morning beautiful people,
Nataliya [291]

Answer:

The girl that fed the dying boy?/

Explanation:

4 0
3 years ago
When humans remove vegetation from an area, the water cycle is MOST directly affected in which way?
GaryK [48]
<span>The correct answer is letter C. evaporation in the area will decrease. When humans remove vegetation from an area, the water cycle is MOST directly affected on the evaporation side. The evaporation in that area will decrease because there'll be no more plants that will hasten the evaporation process. This will create an abnormality in the water cycle.</span>
3 0
3 years ago
Read 2 more answers
Other questions:
  • Which argument forces a writer to return to and change the input before resolving a “UnicodeError”?
    10·1 answer
  • What is the core of an operating system that manages memory and devices, maintains the computer’s clock, starts programs, and as
    7·1 answer
  • What kind of device should you install if you need the device to perform network address translation, facilitate access to the I
    6·1 answer
  • An example of hardware is a _____. a)word processor b)database c)motherboard d)internet
    15·2 answers
  • You are a police officer trying to crack a case. You want to check whether an important file is in the evidence room. Files have
    5·2 answers
  • What do you call when a hacker users multiple guest computers to crack a password?
    11·1 answer
  • Below is a recursive implementation of the factorial function. For what value of n will this function not produce the desired re
    8·1 answer
  • Spreadsheets: what is a column?
    15·1 answer
  • When using the text command, what needs to be around the word or words you<br> want to appear?
    10·1 answer
  • Ideally, Internet of Things (IoT) devices have the ability to:
    14·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!