1. In C++, is cin an object or a class? Is string an object or a class? 2. When
ID: 3844212 • Letter: 1
Question
1. In C++, is cin an object or a class? Is string an object or a class?
2. When using a string object, you do not know how it stores its characters. How can you access them?
3. Describe two possible ways in which a string object might store its characters.
4. Suppose the providers of your C++ compiler decide to change the way that a string object stores its characters, and they update the string member functions accordingly. Which parts of your code do you need to change when you get the new compiler?
5. What does the following code segment print? CashRegister reg; reg.clear(); reg.add_item(0.95); reg.add_item(0.95); cout << reg.get_count() << " " << reg.get_total() << endl;
6. What is wrong with the following code segment? CashRegister reg; reg.clear(); reg.add_item(0.95); cout << reg.get_amount_due() << endl;
7. Declare a member function get_dollars of the CashRegister class that yields the dollar value of the total amount of the sale.
8. Name two accessor member functions of the string class.
9. Is the get member function of the ifstream class an accessor or a mutator?
Explanation / Answer
1. In C++, is cin an object or a class? Is string an object or a class?
->cin is a object
->String is a class
2. When using a string object, you do not know how it stores its characters. How can you access them?
->std::string::at
char& at(size_t pos);
const char& at(siz_t pos)const;
3. Describe two possible ways in which a string object might store its characters.
->
4. Suppose the providers of your C++ compiler decide to change the way that a string object stores its characters, and they update the string member functions accordingly. Which parts of your code do you need to change when you get the new compiler?
we hae to change the headerfiles that included in the program and have to chnage the methos of accessing the elements..
What does the following code segment print? CashRegister reg; reg.clear(); reg.add_item(0.95); reg.add_item(0.95); cout << reg.get_count() << " " << reg.get_total() << endl;
->count is 2
->total is 1.9
6. What is wrong with the following code segment? CashRegister reg; reg.clear(); reg.add_item(0.95); cout << reg.get_amount_due() << endl;
only in the above code we have added the item so,we can't get the amount due from the above code segment.
7.Declare a member function get_dollars of the CashRegister class that yields the dollar value of the total amount of the sale.
->
8. Name two accessor member functions of the string class.
->getter functions
9. Is the get member function of the ifstream class an accessor or a mutator?
->It's a accessor
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.