Write a program that creates a Bus class. Create a constructor that initializes the number of passengers and number of seats. Declare four objects. Use the default copy constructor to initialize two of the objects.
Here's what I have, what did I do wrong?
#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstdlib>
#include<cstring>
#include<algorithm>
#include<vector>
#include<stack>
#include<deque>
bus( int a, int b)
{
num_seat = a;
num_passenger = b;
}
void print()
{
cout<<"number of seats"<<num_seat<<endl;
cout<<"number of passengers "<<num_passenger<<endl<<endl;
}
};
int main()
{
bus obj1,obj2,obj3,obj4;
bus obj,obj_user(200, 150);
cout<<"object 1 is being initialised using default copy constructer\n\n";
obj1 = obj;
obj1.print();
cout<<"object 2 is being initialised using user copy constructer\n\n";
obj2 = obj_user;
obj2.print();
return 0;
}
#include<iostream>
usingnamespace std;
class bus
{
public:
bus( int a = 7, int b = 25) // 7 and 25 are default values
{
num_seat = a;
num_passenger = b;
}
void print()
{
cout<<"number of seats "<<num_seat<<endl;
cout<<"number of passengers "<<num_passenger<<endl<<endl;
}
private:
int num_seat;
int num_passenger;
};
int main()
{
bus obj;// constructed using default values
bus obj1 = obj;
cout << "object obj1 is being constructed using default copier\n";
obj1.print();
cout << "object obj-user constructed using class constructor with user parameters and then copied\n";
bus obj_user(200, 150);
bus obj2 = obj_user;
obj2.print();
return 0;
}