Question

Given the class below, which answer choice would be an implementation of the parameterized constructor (without...

Given the class below, which answer choice would be an implementation of the parameterized constructor (without an initialization list)?

class MyInteger {
    private:
       int num;
    public:
       MyInteger();
       MyInteger(int newint);
       void setInt(int newint);
       int getInt();
       int operator[](int index);
};

  

MyInteger::MyInteger(newNum) { num = newNum; }

   

MyInteger::MyInteger(int newNum) { num = newNum; }

   

Integer::MyInteger(int newNum = 0) : num{0} {;}

   

MyInteger::MyInteger(int newNum) : num{0} {;}

   

MyInteger::MyInteger() { num = 0; }

   

MyInteger::MyInteger() : num{0} {;}

   

MyInteger::MyInteger(int newNum = 0) { num = newNum; }

0 0
Add a comment Improve this question Transcribed image text
Answer #1
MyInteger::MyInteger(newNum) { num = newNum; }
incorrect because input parameter format/syntax is incorrect

MyInteger::MyInteger(int newNum) { num = newNum; }
this is correct

Integer::MyInteger(int newNum = 0) : num{0} {;}
incorrect because it's using initialization list

MyInteger::MyInteger(int newNum) : num{0} {;}
incorrect because it's using initialization list

MyInteger::MyInteger() { num = 0; }
incorrect because it's default constructor

MyInteger::MyInteger() : num{0} {;}
incorrect because it's default constructor

MyInteger::MyInteger(int newNum = 0) { num = newNum; }
incorrect because we can't use default parameters (= 0) in member function definitions. we must put it in declaration.

Answer:
----------
b)  MyInteger::MyInteger(int newNum) { num = newNum; }
Add a comment
Know the answer?
Add Answer to:
Given the class below, which answer choice would be an implementation of the parameterized constructor (without...
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
  • Given is the implementation of the class IntegeArray what we did for Assignment 5. This implementation...

    Given is the implementation of the class IntegeArray what we did for Assignment 5. This implementation has only one data member or attribute private int[] arr; If the length of the array is also added as an attribute or data member of the class as shown below, please rewrite the whole IntegerArray class implementation to reflect this new added data member of len. Complete the code given below (and submit based on the given code). No main needs to be...

  • Write a second constructor that could be added to the HeapPriorityQueue class. This constructor accepts an...

    Write a second constructor that could be added to the HeapPriorityQueue class. This constructor accepts an array of elements as a parameter and uses that array as the heap rather than creating a new array. Of course, the array passed in is probably not in proper heap ordering, so you must rearrange it until it is. There's a neat trick for achieving this: If you just "bubble down" all of the non-leaf nodes of the heap, starting from the last...

  • Write a second constructor that could be added to the HeapPriorityQueue class. This constructor accepts an...

    Write a second constructor that could be added to the HeapPriorityQueue class. This constructor accepts an array of elements as a parameter and uses that array as the heap rather than creating a new array. Of course, the array passed in is probably not in proper heap ordering, so you must rearrange it until it is. There's a neat trick for achieving this: If you just "bubble down" all of the non-leaf nodes of the heap, starting from the last...

  • Complete an Array-Based implementation of the ADT List including a main method and show that the...

    Complete an Array-Based implementation of the ADT List including a main method and show that the ADT List works. Draw a class diagram of the ADT List __________________________________________ public interface IntegerListInterface{ public boolean isEmpty(); //Determines whether a list is empty. //Precondition: None. //Postcondition: Returns true if the list is empty, //otherwise returns false. //Throws: None. public int size(); // Determines the length of a list. // Precondition: None. // Postcondition: Returns the number of items in this IntegerList. //Throws: None....

  • Complete the implementation of the method replace: public class SinglyLinkedList private Node head, public SinglyLinkedListo this(null) public SinglyLinkedList(Node head) [ this.head -head public Nod...

    Complete the implementation of the method replace: public class SinglyLinkedList private Node head, public SinglyLinkedListo this(null) public SinglyLinkedList(Node head) [ this.head -head public Node getHeado return head public void setHead(Node head) [ head: this. head Method that creates a Node containing 'item' @param item Value to be added this.headnew Node(item, this.head) * and adds it as the first element in the list *I public void add(int item) Method that finds the node at the given index d replaces its value...

  • Refer to this header file: // Fraction class // This class represents a fraction a /...

    Refer to this header file: // Fraction class // This class represents a fraction a / b class Fraction { public: // Constructors Fraction(); // sets numerator to 1 and denominator to 1 Fraction(int num, int denom); // Setters void setNumerator(int num); void setDenominator(int denom); // getters int getNumerator()const {return num;} int getDenominator()const {return denom;} double getDecimal(){return static_cast<double> num / denom;} private: int num, denom; }; 1.Write the code for the non-member overloaded << operator that will display all of...

  • C++ computer science Given the partial class HardDrive implementation below, implement all of the following: 1:...

    C++ computer science Given the partial class HardDrive implementation below, implement all of the following: 1: default constructor that initialized the attributes with proper default data of your choice. 2: destructor() method, that releases all the dynamically allocated memory. 3: copy constructor() method: That properly manages the dynamic array when the object is passed by value to a function as a parameter. 4: overload the assignment operator: To properly handle copying the dynamic array when one object is assigned to...

  • Problem 3 (List Implementation) (35 points): Write a method in the DoublyLList class that deletes the...

    Problem 3 (List Implementation) (35 points): Write a method in the DoublyLList class that deletes the first item containing a given value from a doubly linked list. The header of the method is as follows: public boolean removeValue(T aValue) where T is the general type of the objects in the list and the methods returns true if such an item is found and deleted. Include testing of the method in a main method of the DoublyLList class. ------------------------------------------------------------------------------------- /** A...

  • IN JAVA. Please reply with the solution without changing aspects of the pre-determined code. The example...

    IN JAVA. Please reply with the solution without changing aspects of the pre-determined code. The example is for your reference and is NOT supposed to be included in the pre-determined code. Comments are helpful, too. Thank you SO much! :) -- Basic constructor definition. Define a constructor as indicated. Sample output for below program: Year: 0, VIN: -1 Year: 2009, VIN: 444555666 -- // ===== Code from file CarRecord.java ===== public class CarRecord { private int yearMade; private int vehicleIdNum;...

  • java The following code is an implementation of a HeapPriorityQueue. You are to implement the methods...

    java The following code is an implementation of a HeapPriorityQueue. You are to implement the methods commented with: // TODO: TIP: Do not just go from memory of your assignment implementation, be sure to consider carefully the constructor and method implementation provided to you. NOTE: You do not have to provide an implementation for any methods intentionally omitted public class Heap PriorityQueue implements PriorityQueue private final static int DEFAULT SIZE 10000 private Comparable [ ] storage private int currentSize: public...

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
ADVERTISEMENT