76 984
Assignments Done
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 {
    int size; // number of students

    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;
  cout << "Students 1 has size " << students1.getSize() << endl;

  // Create object using copy constructor
  Students students2 = students1;
  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!


No comments. Be first!

Leave a comment

Ask Your question

Privacy policy Terms and Conditions