Can two classes contain member functions with the same name

Assignment Help Other Subject
Reference no: EM132588443

Assignment -

1. Is it possible for a member function of a class to activate another member function of the same class?

No.

Yes, but only public member functions.

Yes, but only private member functions.

Yes, both public and private member functions can be activated within another member function.

 None of the above.

2. Can two classes contain member functions with the same name?

No.

Yes, but only if the two classes have the same name.

Yes, but only if the main program does not declare both kinds

Yes, this is always allowed, but only if they have different parameters.

None of the above.

3. Consider this class definition:

class quiz

{

public:

quiz();

int f();

int g() const;

private:

double score;

};

Which function(s) can carry out an assignment score = 1.0;?

Both f and g can carry out the assignment.

f can carry out the assignment, but not g.

g can carry out the assignment, but not f.

Neither f nor g can carry out the assignment.

 

4. The general syntax to overload the assignment operator = for a class is ____.

friend className& operator=(const className&);

className& operator=(className&);

string className& operator=(className&);

const className& operator=(const className&);

None of the above

5. What is the primary purpose of a default constructor with default parameter?

To allow multiple classes to be used in a single program.

To copy an actual argument to a function's parameter.

To initialize each object as it is declared.

To maintain a count of how many objects of a class have been created.

None of the above.

6. Suppose that the foo class does not have an overloaded assignment operator. What happens when an assignment a = b; is given for two foo objects?

The automatic assignment operator is used

The copy constructor is used

Compiler error

Run-time error

None of the above

7. Which of the following blocks is designed to catch any type of exception?

a) catch( ) { } b) catch (...) { } c) catch(exception) { } d) catch(*) { } e) none of the above

8. When should you use a const reference parameter? [3]

Whenever the data type might be many bytes.

Whenever the data type might be many bytes, the function changes the parameter within its body, and you do NOT want these changes to alter the actual argument.

Whenever the data type might be many bytes, the function changes the parameter within its body, and you DO want these changes to alter the actual argument.

Whenever the data type might be many bytes, and the function does not change the parameter within its body.

None of the above.

9. Consider the following declaration:

template <class T> class equality

{

private:

T x;

T y;

};

Write a statement that shows the declaration in the class equality to overload the operator != as a member function? [3]

bool operator!= (equality s);

equality operator!= (equality s) const;

bool equality::operator!= (equality s1, equality s2) const;

bool equality::operator!= (const equality& s) const;

none of the above.

10. Here is a function prototype and some possible function calls:

int day_of_week(int year, int month = 1, int day = 1);

// Possible function calls:

cout << day_of_week( );

cout << day_of_week(1995);

cout << day_of_week(1995, 10);

cout << day_of_week(1995, 10, 4);

How many of the function calls are legal? [3]

None of them are legal

1 of them is legal

2 of them are legal

3 of them are legal

All of them are legal

Answer the next 4 questions (11 - 14) based on the following program:

// Assume normal headers exist

class MyException

{

public:

string m_except;

MyException (const char * str) {

m_except = str;

}

};

class SpecialException : public MyException

{

public:

int m_num;

SpecialException(int num, const char * str):MyException(str) {

m_num = num;

}

};

void throwIt(int t)

{

try

{

switch (t)

{

case 0: throw 1; break;

case 1: throw "hello"; break;

case 2: throw MyException("hello"); break;

case 3: throw SpecialException(1, "hello"); break;

case 4: throw new MyException("hello"); break;

}

}

catch (int i) {

cout << "throwIt int";

}

catch (SpecialException e) {

cout << "throwit Special";

}

}

int main()

{

try {

//xxx

}

catch (int i) { cout << "main int"; }

catch (SpecialException e) { cout << "main SP";}

catch (MyException e) { cout << "main Exception"; }

catch (const char * str) { cout << "main const *"; }

catch ( ... ) { cout << "main unknown"; }

}

11. What is the output of the program if //xxx was replaced with throwIt(0)? [3]

a) main int b) throwIt int c) main Exception d) main unknown e) none of the above

12. What is the output of the program if //xxx was replaced with throwIt(1)? [3]

a) main const b) throwIt Speical c) main const * d) main SP e) none of the above

13. What is the output of the program if //xxx was replaced with throwIt(2)? [3]

a) main int b) throwIt int c) main Exception d) main unknown e) none of the above

14. What is the output of the program if //xxx was replaced with throwIt(3)? [3]

a) throwIt Special b) throwIt int c) main Exception d) main unknown e) none of the above

True or False questions (15 - 23): [30]

A pure virtual function is a virtual function that causes its class to be abstract. __

An abstract class is useful when no classes should be derived from it. __

A friend function can access a class's private data without being a member of the class. __

The keyword friend appears in the private or the public section of a class. __

 A static function can be called using the class name and function name. __

A pointer to a base class can point to objects of a derived class. _____

An assignment operator might be overloaded to ensure that all member data is copied exactly. __

A copy constructor is invoked when an argument is passed by value. ___

The statements virtual void sort(int); and void virtual sort(int); are the same.

24. How many parameters are required to overload the post-increment operator for a class as a friend function?

a) 0 b) 1 c) 2 d) 3 e) none of the above

25. Consider the definition of the following recursion function:

int mystery(int first, int last)

{

if (first > last)

return 0;

else if (first == last)

return first;

else

return first + mystery(first + 1, last - 1);

}

What is the output of the following statement?

cout << mystery(6, 10) << endl;

a) 13

b) 21

c) 40

d) 42

e) none of the above

26. The class _________________ is designed to deal with illegal arguments used in a function call: [3]

a. invalid_function

b. invalid_call

c. invalid_parameter

d. invalid_arguments

e. none of the above.

27. Which of the following rules should you follow to solve the Tower of Hanoi problem?

a. Only two disks can be moved at a time.

b. You can remove disks only from the first needle.

c. The removed disk must be placed on one of the needles.

d. A larger disk can be placed on a smaller disk.

e. none of the above.

28. Every node (except of the last node) in a singly linked list contains ____.

a. the next node.

b. no address information.

c. the address of the next node.

d. the address of the previous node.

e. none of the above.

29. What is the purpose of the following code?

current = head;

while (current != NULL)

{

//Process current

current = current->link;

}

a. Insertion of a node.

b. Selection of a node.

c. Traversal of a linked list.

d. Creation of a new list.

e. none of the above.

30. Which of the following is a basic operation on singly linked lists?

a. Retrieve the data of an arbitrary node.

b. Swap the head and the last node.

c. Determine whether the list is full.

d. Make a copy of the linked list.

e. none of the above.

[31] List four common examples of exceptions:

[32] Consider the definition of the following function template:

template <class T>

class strange

{

T a;

T b;

};

a. Write a statement that shows the declaration in the class strange to overload the operator == as a member function.

b. Write a statement that declares sObj to be an object of type strange such that the private member variables a and b are of type int.

c. Write the definition of the function operator== for the class strange, which is overloaded as a member function. Assume that two objects of type strange are equal if their corresponding member variables are equal.

[33] Write a function template palindrome that takes vector parameter and returns true or false according to whether the vector does or does not read the same forwards as backwards. (e.g., a vector containing 1, 2, 3, 2, 1 is a palindrome, but a vector containing 1, 2, 3, 4 is not).

[34] Consider the following definition of the recursive function print.

void print(int num)

{

if (num > 0)

{

cout << num << " ";

print(num - 1);

}

}

What is the output of the following statement?

print(4);

[35] Consider the following definition of the recursive function:

int puzzle(int start, int end)

{

if (start > end)

return start - end;

else if (start == end)

return start + end;

else

return end * puzzle(start + 1, end - 1);

}

What is the output of the following statement?

cout << puzzle(5, 10) << endl;

[36] Write the definition of the function template that swaps the contents of two variables of any type.

[37] Overload the operator += for the class myString to perform the following string concatenation. Suppose that s1 is "Hello" and s2 is "there". Then, the statement:

s1 += s2;

should assign "Hello there" to s1, in which s1 and s2 are myString objects.

[38] Write a class called PhoneNumber. The class should have the following string data members, areaCode, exchange, and lineNum.

The class will have to overload the >> operator.

Input the entire phone number into an array. Test that the proper number of characters has been entered. There should be a total of 14 characters read for the phone number of the form (800) 555-1212.

The area code and the exchange do not begin with 0 or 1.

The middle digit of an area code is limited to 0 or 1.

The area code should be surrounded by parenthesis and there is a dash between the exchange and the line.

There should be only one space between the area code and the exchange

If none of the above operations results in an exception, copy the parts of the phone number into the PhoneNumber object's data members. If there is an exception, throw an exception, catch the exception, display each error and ask the user to enter another phone number.

Write a main program to test your class and use the following sample input file:

(877)123-4567

(808) 123-4567

(101) 555-0111

(809) 123-9990

809 123 9999

(606) 555-1212 nothing wrong with this number

(000) 000-0000

Make sure you upload .h, .cpp and a screen print of the output. No output, no grade.

Note: TYPE your answers, print any code you write and its output, staple them to this exam and return them.

Reference no: EM132588443

Questions Cloud

How blossom should report cash provide by operating activity : How Blossom should report cash provided by operating activities of? Increase in accounts receivable 62000. Depreciation expense 139000
Alliance supermarket and point-of-sale systems : Alliance Supermarkets has been using a point-of-sale (POS) system for some time to track its inventory.
Suggest how you intend to handle the challenge : Clearly identify three (3) challenges that you expect to encounter while writing a business research paper. For each of the challenges you identify.
What total amount should carla vista co report : $104000; deferred income taxes, $126000 and retained earnings, $455000. What total amount should Carla Vista Co. report as stockholders' equity?
Can two classes contain member functions with the same name : Can two classes contain member functions with the same name. Is it possible for a member function of a class to activate another member function of same class
What wildhorse free cash flow is : What Wildhorse free cash flow is? Net cash provided by operating activities 339000,Average long-term liabilities 91000,Average current liabilities 158000
MBA641 Strategic Project Management Assignment : MBA641 Strategic Project Management Assignment Help and Solution, Kaplan Business School - Assessment Writing Service
Scan current authoritative business sources : Scan current authoritative business sources to locate and discuss some global factor that pertains to the health insurance market domain.
Sexual assault or wartime experiences : In "Trauma Warnings," some students have survived very traumatic events, such as sexual assault or wartime experiences.

Reviews

Write a Review

Other Subject Questions & Answers

  What language did your or their relatives speak

Were you or any of your or their family being researched have family that was adopted? How has this impacted your/their ability to know your history.

  The difference between men and women in negotiation

Review of a scholarly article on the difference between men and women in negotiation. Reviews should include a synopsis.

  Develop a status report for the project at the end of period

Given the project network and baseline information below, complete the form to develop a status report for the project at the end of period

  Federalist and democratic-republican attitudes

Compare and contrast the Federalist and Democratic-Republican attitudes toward the national government. Include a clear discussion of the differences their leaders held.

  What is the stage of the trauma response cycle

Considering each stage of the trauma response cycle, during which would be most difficult to implement intervention and treatment goals with clients, and why?

  Discuss contemporary versions of amende honorable in world

Recent news articles, and other forms of media as your evidence. Where do you see contemporary versions of the amende honorable in the world today?

  Difference between normal and abnormal behavior

Identify two psychological disorders that you want to learn more about. After reading about that psychological disorder, discuss two key items you learned about each of the two disorders.

  What health risks associated with obesity

What health risks associated with obesity does Mr. C. have? Is bariatric surgery an appropriate intervention? Why or why not?

  Rapidly destroying ecosystems

Water is vital for humanity there is no doubt about that, but big companies that profit from water use methods that are rapidly destroying ecosystems,

  Describe what steps are required to initiate policy change

Participate in health care policy development to influence nursing practice and health care. Research public health issues on the "Climate Change" or "Topics.

  Is gun control a violation of the bill of rights

Is gun control a violation of the Bill of Rights. How can public safety and personal rights coexist

  The body regulates zinc absorption

The body regulates zinc absorption by:

Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd