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++: Early Objects (10th Edition)
- Create a program in C++ language Create a LeaderEntry Header file. In this file we will create LeaderEntry class: public LeaderEntry(); LeaderEntry(string playernameIn, int pointsIn, string datetimeIn); ~LeaderEntry(); private string playername; int gamepoints; string dategame; The first step is to create a Header file and LeaderEntry class as defined above. In main create a LeaderEntry object in your main. with sample data. Retrieve the entry and then display it at the beginning of the game. Now store LeaderEntry into a Vector and retrieve. Example vector<LeaderEntry> leaderboardtopten; LeaderEntry *s1 = new LeaderEntry; LeaderEntry *s1 = new LeaderEntry; LeaderEntry *s1 = new LeaderEntry; s1->gamepoints = 7000; LeaderEntry *s2 = new Site; s2->gamepoints = 9000; leaderboardtopten.push_back(*s1); // leaderboardtopten.push_back(*s2); ...…arrow_forwardCreate a subroutine that breaks down a noun-verb-object simple sentence into its component components. For example, the phrase "Mary walked the dog" is deconstructed as follows:Noun: MaryVerb: walkedObject: the dog The dog is the object.This function should be compatible with both StringBuilder and String objects.arrow_forwardclass displayClass{public:void print();...private:int listLength;int *list;double salary;string name;} Write the definition of the function to overload the assignment operator for the class displayClass.arrow_forward
- /* Interface File: Movie.h Declaration of Movie Class (Variables - "Data Members" or "Attributes" AND Functions - "Member Functions" or "Methods") */ #ifndef MOVIE_H // Include Guard or Header Guard -If already defined ignore rest of code #define MOVIE_H // Otherwise, define MOVIE_H #include<string> // Note: Not "using namespace std;" or even "using std::string" class Movie { private: std::string title = ""; // Explict scope used --> std::string int year = 0; public: Movie(std::string title = "", int year = 1888); // Declaring a Default Constructor ~Movie(); // A Destructor used for freeing up resources void set_title(std::string title_param); std::string get_title() const; // "const" safeguards class variable changes within function std::string get_title_upper() const; void set_year(int year_param); int get_year() const; }; //…arrow_forwardA class may occasionally be dependent upon itself. In other words, an object of one class engages in communication with an object of the same class. To do this, a method of the class can take an object of the same class as a parameter.An illustration of this scenario is the concat method of the String class. One String object calls the method, while another String object is supplied as an argument. Here's an illustration:str2 = str1.concat;The String object (str1) that executes the method adds its characters to the String (str2) that was supplied as a parameter. As a result, a fresh String object is produced and saved as str3. Write Java code to put the circumstances given into effect.arrow_forwardclass displayClass{public:void print();...private:int listLength;int *list;double salary;string name;} Write the definition of the copy constructor for the class displayClass.arrow_forward
- A string object is ______ which means its contents cannot be changed. Select one: a. Absolute b. Immutable c. Undisputable d. Irreversiblearrow_forwardWrite a program in C++ object oriented programming Create a class Class1 with a string data member ‘paragraph’. Provide a constructor and getParagraph() method in the class. The constructor just assigns NULL to the data member. getParagraph() method must read a paragraph from user. The paragraph should contain at least 30 words. If there are less than 20 words, the program must ask user to enter paragraph again. Create another class Class2, and make it a friend of the class Class1. Provide a function getSubString(Class1 &obj1, int startIndex, int lastIndex) with return type string in the class Class2 which accepts an object of class Class1 (by reference) and two integers. The getSubString() function should return the substring starting from location startIndex and ending at location lastIndex. Class2 must also contain a store() function that stores the substring in a file. Print screenshot of substring stored in file as well. (Topics covered: File Handling, Friend Classes.arrow_forwardA Person has a name (just a first name for simplicity) and friends. Store the names of the friends in a string, separated by spaces. Provide a constructor that constructs a person with a given name and no friends. Provide member functions. c++ void befriend(Person p) void unfriend(Person p) string get_friend_names()arrow_forward
- Define a Student class, with 3 data fields: ID: string Name: string FavoriteThing: string Create an application that stores and outputs a list of the students' favorite things. Suppose each student only has one favorite thing.arrow_forwardclass temporary { public: void set(string, double, double); void print(); double manipulate(); void get(string&, double&, double&); void setDescription(string); void setFirst(double); void setSecond(double); string getDescription() const; double getFirst()const; double getSecond()const; temporary(string = "", double = 0.0, double = 0.0); private: string description; double first; double second; }; What are the members and functions in this example? I need help identifying how the members and functions work to answer the questions below. I am having troubles understanding this concept. I am learning constructors and deconstructors along with inline and hiding information. I feel lost trying to answer these questions. Can I get direction on how to proceed? Write the definition of the member function set so that the instance variables are set according to the parameters. Write the definition of the member function manipulate that returns a decimal number as follows: If the…arrow_forwardin c++ i need to make it where the the code skips over the leading blanks in the string for example "0077" would mean the value of the BigNumber object will be 46 and the number of digits will be 2 #include <iostream>#include <string>using namespace std; class BigNumber { friend ostream& operator<<(ostream & out, const BigNumber & c); private: int digits[1000]; int numDigits; public: BigNumber(const string &s); }; ostream& operator<<(ostream & out, const BigNumber & c) { if (c.numDigits == 0) out << "0"; else for (int i = c.numDigits - 1; i >= 0; i--) out << c.digits[i]; //out << "<" << c.numDigits << ">"; return out; } BigNumber::BigNumber(const string &s){ int i = 0; int j = 0; string Holder; while (s[i] != '\0') { if(s[i] != '0') { numDigits++;…arrow_forward
- EBK JAVA PROGRAMMINGComputer ScienceISBN:9781337671385Author:FARRELLPublisher:CENGAGE LEARNING - CONSIGNMENTMicrosoft Visual C#Computer ScienceISBN:9781337102100Author:Joyce, Farrell.Publisher:Cengage Learning,