Question

c++ question 1. C++ string Class What does the output look like after executing the following...

c++ question

1. C++ string Class

What does the output look like after executing the following statements?

std::string numstr = "12";
numstr += "3";
std::cout << numstr << '\n';

A. None of these.

B. The snippet has syntax errors.

C. 15

D.123

//

2. Let S be a class that allows integers to be stored in its objects like an array. For example, if obj is an object of S, one can write statements like

obj[0] = 100;

or

int x = obj[0];

What is required in the class specification?

A. A public member function int operator[](int);

B. None of these

C. A public member function int[] S(int);
D. A public member function  int &operator[](int);

//

3. Given a class Coll and some variables as follows:

class Coll {};

Coll obj;

char *cPtr = nullptr;

Coll *ptr = &obj;

Which casting is allowed by C++?

A. cPtr = reinterpret_cast<char *>(ptr);

B. cPtr = dynamic_cast<char *>(ptr);

C. None of these.

D.cPtr = static_cast<char *>(ptr);

0 0
Add a comment Improve this question Transcribed image text
Answer #1

1.

std::string numstr = "12"; // Initially the string is 12
numstr += "3"; // String concatenate with one more character that is 3
std::cout << numstr << '\n'; // print 123

Option d

2.

Let S be a class that allows integers to be stored in its objects like an array. For example, if obj is an object of S, one can write statements like

A public member function  int &operator[](int);

Option d

3.

class Coll {};

Coll obj;

char *cPtr = nullptr;

Coll *ptr = &obj;

class Coll and some variables as follows cPtr = dynamic_cast<char *>(ptr);

Option b

Add a comment
Know the answer?
Add Answer to:
c++ question 1. C++ string Class What does the output look like after executing the following...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • The following program contains the definition of a class called List, a class called Date and...

    The following program contains the definition of a class called List, a class called Date and a main program. Create a template out of the List class so that it can contain not just integers which is how it is now, but any data type, including user defined data types, such as objects of Date class. The main program is given so that you will know what to test your template with. It first creates a List of integers and...

  • Please, answer the with c++ Module 9: Odds and Ends Questions Question 1 How is the...

    Please, answer the with c++ Module 9: Odds and Ends Questions Question 1 How is the static_cast operator different from the dynamic_cast operator? Question 2 Which of the following are not examples of correct usage (conceptually or syntactically) of auto ptr? (Assume the needed header files have beenincluded.) auto ptr int> pia(new int[20]) auto ptr str> (new string); int ngue = 7; auto_ptr int pr(&rigue): auto ptr dbl (new double) Question 3 Give at least three examples of convenience advantages...

  • C++ 1. The copy constructor is used for one the following scenarios: I. Initialize one object...

    C++ 1. The copy constructor is used for one the following scenarios: I. Initialize one object from another of the same type. II. Copy an object to pass it as argument to a function. III. Copy an object to return it from a function. Read the following program and answer questions (20 points) #include <iostream> using namespace std; class Line public: int getLength( void); Line( int len // simple constructor Line( const Line &obj) 1/ copy constructor Line (); //...

  • For the LinkedList class, create a getter and setter for the private member 'name', constructing your...

    For the LinkedList class, create a getter and setter for the private member 'name', constructing your definitions based upon the following declarations respectively: std::string get_name() const; and void set_name(std::string); In the Main.cpp file, let's test your getter and setter for the LinkedLIst private member 'name'. In the main function, add the following lines of code: cout << ll.get_name() << endl; ll.make_test_list(); ll.set_name("My List"); cout << ll.get_name() << endl; Output should be: Test List My List Compile and run your code;...

  • C++ Questions. Question 1 What would the function prototype in the class declaration for the following...

    C++ Questions. Question 1 What would the function prototype in the class declaration for the following member function look like? void Fractions::showData() { if((num < 0 && denom < 0) || denom < 0) { num = -num; denom = -denom; } cout << num << "/" << denom << endl; } Question 2 What would the function header of the following member function prototype in class Fractions be? Fractions operator+(const Fractions &f2); Question 3 What would the function prototype...

  • 2. (50 marks) A string in C++ is simply an array of characters with the null...

    2. (50 marks) A string in C++ is simply an array of characters with the null character(\0) used to mark the end of the string. C++ provides a set of string handling function in <string.h> as well as I/O functions in <iostream>. With the addition of the STL (Standard Template Library), C++ now provides a string class. But for this assignment, you are to develop your own string class. This will give you a chance to develop and work with...

  • For Question 14 - 15, please refer to the following code snippet. 1 class Fitness 2...

    For Question 14 - 15, please refer to the following code snippet. 1 class Fitness 2 { 3 int Jumping; int Running; 12 }; 8 class Round ISAShape: public class Fitness 9 { 10 11 int Sleeping; int Eating; 13 }; 14. The following statements are TRUE based on the code snippet above, EXCEPT (A) class RoundISAShape is inheriting from class Fitness (B) class RoundISAShape is the base class for class Fitness (C) class Round ISAShape is considered as the...

  • HELP PLEASE ANSWER 3(c). Consider the following function object: #include <string> class CustomCompare public: bool operator...

    HELP PLEASE ANSWER 3(c). Consider the following function object: #include <string> class CustomCompare public: bool operator (const atd:istringk 1hs, const std::string& rhs) if (1hs. length) 0 && rhs.lengthO 0) return false; int 1 lhs. length )-1; intr rhs. length)-1; return (ro&&10) I Write one C++ statement that defines a variable myCustomPQ, where myCustomPQ is a priority queue storing strings and using CustomCompare.

  • 1.What will the following statement output? cout << &num1; A)None of these B)the value stored in...

    1.What will the following statement output? cout << &num1; A)None of these B)the value stored in the variable named num1 C)the number 1 D)the memory address of the variable named num1 E)the string &num1 2. What will the following code output? int number = 888; int *var = &number; cout << var << endl; A)the address of number B)an asterisk followed by 8888 C)8888 D)an asterisk followed by the address of number 3. Assuming ptr is a pointer variable, what...

  • #include <iostream> #include <string> #include <cstring> using namespace std; class Node{       private:       ...

    #include <iostream> #include <string> #include <cstring> using namespace std; class Node{       private:        int data;        Node* nextNodePtr;           public:        Node(){}               void setData(int d){            data = d;        }               int getData(){            return data;        }               void setNextNodePtr(Node* nodePtr){                nextNodePtr = nodePtr;        }                ...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT