76 984
Assignments Done
98,5%
Successfully Done
In June 2019

Answer to Question #89780 in C++ for matimu

Question #89780
write a program that has a class named "students". the class should have at least two constructors:one being the default constructors and the other one being a copy constructor. and two more functions of your choice.create two objects of type student:one created using the default constructor and the other by the copy constructor.call at least two functions from the class using both object.
Expert's answer
#include <iostream>
using namespace std;



class Students {
  private:
    int size; // number of students



  public:
    Students() {
      this->size = 0;
    }



    Students(const Students &other) {
      this->size = other.getSize();
    }



    void setSize(int size) {
      this->size = size;
    }



    int getSize() const {
      return this->size;
    }
};



int main() {
  // Create object using default constructor
  Students students1;
  students1.setSize(10);
  cout << "Students 1 has size " << students1.getSize() << endl;



  // Create object using copy constructor
  Students students2 = students1;
  students2.setSize(20);
  cout << "Students 2 has size " << students2.getSize() << endl;
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be first!

Leave a comment

Ask Your question

Submit
Privacy policy Terms and Conditions