Concept explainers
A)
String object:
- The variable “char” is used to hold only the characters but the variable string is to hold the whole set of character.
- Thus, string object is used to carry set of characters and it is declared with the keyword “string” followed by the object name.
A)
Explanation of Solution
“cin” statement to read a one word string:
When a string input is read using “cin” with a “>>” operator then the “cin” reads the data passed over it and it removes the whitespace characters such as spaces, tabs and line breaks in the string.
- Once it reaches the first non-blank character then it starts reading and it stops the reading process until it reaches the next whitespace character.
“cin” statement that reads a string in one word is as follows:
//get value of the description as a one word string
cin >> description;
- The above statement is used to read the input string until it receives the whitespace and then it ignores the remaining part of the string.
Therefore, “cin >> description;” is the “cin” statement which reads a string as one word string.
B)
String object:
- The variable “char” is used to hold only the characters but the variable string is to hold the whole set of character.
- Thus, string object is used to carry set of characters and it is declared with the keyword “string” followed by the object name.
B)
Explanation of Solution
“cin” statement to read multiple words:
In C++, using the “cin” statement, the multiple words can be read through the function getline().
- This getline() function read the line from the user including both leading and embedded spaces and then stores that line into the string object.
“cin” statement that reads multiple words in a string is as follows:
/* Read a string which contains multiple words separated by blanks */
getline(cin, description);
The above line is used to get input from the user by using “getline()”; the input contains multiple words which are separated by space.
Therefore, “getline(cin, description);” is the input statement that reads multiple words in a string using the getline() function.
Want to see more full solutions like this?
Chapter 3 Solutions
STARTING OUT WITH C++ MPL
- True or FalseReference variables can be used only to reference objects.arrow_forwardWelcome Assignment ### welcome_assignment_answers ### Input - All eight questions given in the assignment. ### Output - The right answer for the specific question. def welcome_assignment_answers(question): # The student doesn't have to follow the skeleton for this assignment. # Another way to implement it is using "case" statements similar to C. if question == "Are encoding and encryption the same? - Yes/No": answer = "The student should type the answer here" elif question == "Is it possible to decrypt a message without a key? - Yes/No": answer = "The student should type the answer here" return (answer) # Complete all the questions. if __name__ == "__main__": # use this space to debug and verify that the program works debug_question = "Are encoding and encryption the same? - Yes/No" print(welcome_assignment_answers(debug_question)) As you can see, the first two questions are already in the skeleton code. Please follow the first two questions…arrow_forwardA is a data type that you may construct that includes one or more fields. structure b. collection c. volume d. list a. structure b. collection c. volume d. list a. structure b.arrow_forward
- A class object can encapsulate more than one [answer].arrow_forwardLanguage: C++ Also, create two hurricane objects in the main function and print the average wind speed of them. All the data members can be public.arrow_forwardstructions: Write the following programs in C# using concepts learnt in this chapter and abmit the .cs file with the screenshot of your output for each question in the Lab Assignment 2 Submission page. 1. FRENCH TRANSLATOR Look at the following list of French words and their meanings: In French: gauche milieu droite middle In English: right left Create an application that translates the French words to English. The form should have three buttons, one for each French word. When the user clicks a button, the application should display the English translation in a Label control.arrow_forward
- Parameter that is result of a conversion of data from another form is calledarrow_forwarddef swap_text(text): Backstory: Luffy wants to organize a surprise party for his friend Zoro and he wants to send a message to his friends, but he wants to encrypt the message so that Zoro cannot easily read it. The message is encrypted by exchanging pairs of characters. Description: This function gets a text (string) and creates a new text by swapping each pair of characters, and returns a string with the modified text. For example, suppose the text has 6 characters, then it swaps the first with the second, the third with the fourth and the fifth with the sixth character. Parameters: text is a string (its length could be 0)Return value: A string that is generated by swapping pairs of characters. Note that if the Examples: swap_text ("hello") swap_text ("Party for Zoro!") swap_text ("") def which_day(numbers): → 'ehllo'→ 'aPtr yof roZor!' → '' length of the text is odd, the last character remains in the same position.arrow_forwardPython: Dietarrow_forward
- Alternate Character DisplayWrite a method that accepts a String object as an argument and then returns the alternate characters as substring starting from index 0. For instance, if the string argument passed is “GREAT”, the method should return “GET”. Demonstrate the method in a program that asks the user to input a string and then passes it to the method.arrow_forwardStatic Variable: a variable whose lifetime is the lifetime of the program (static int x;) Dynamic Variable: It is a pointer to a variable (int *x;) Is this comparison true?arrow_forward/ CLASS PROVIDED: IntSet (a container class for a set of// int values)//// CONSTANT// static const int MAX_SIZE = ____// IntSet::MAX_SIZE is the highest # of elements an IntSet// can accommodate.// CONSTRUCTOR// IntSet()// Pre: (none)// Post: The invoking IntSet is initialized to an empty// IntSet (i.e., one containing no relevant elements).// CONSTANT MEMBER FUNCTIONS (ACCESSORS)// int size() const// Pre: (none)// Post: Number of elements in the invoking IntSet is returned.// bool isEmpty() const// Pre: (none)// Post: True is returned if the invoking IntSet has no relevant// relevant elements, otherwise false is returned.// bool contains(int anInt) const// Pre: (none)// Post: true is returned if the invoking IntSet has anInt as an// element, otherwise false is returned.// bool isSubsetOf(const IntSet& otherIntSet) const// Pre: (none)// Post: True is returned if all…arrow_forward
- EBK JAVA PROGRAMMINGComputer ScienceISBN:9781337671385Author:FARRELLPublisher:CENGAGE LEARNING - CONSIGNMENTMicrosoft Visual C#Computer ScienceISBN:9781337102100Author:Joyce, Farrell.Publisher:Cengage Learning,