485,867 views
3 votes
3 votes
Write a class with name shares shares( ) constructor to initialize the object shares(String , int , int ) constructor to initialize the object void buy( ) for buying the shares void sell( ) for selling the shares calc( ) to calculate the total value of shares show( ) to show the details. Note : buy( ) and sell( ) functions will increase or decrease the number of shares, and accordingly the Total value of shares will change. Create another class and write main( ) function and use the above functions....use : string nm(name of buyer)

int no(no. of shares)
int unitprc(price of 1 share)
int totalval (total value of all shares)

User Nileshsinh Rathod
by
2.8k points

1 Answer

22 votes
22 votes

Step-by-step explanation:

What is constructor?

Constructor is a member function of class, whose name is same as the class.

A constructor is a special type of member function of a class which initializes objects of a class. In C++, Constructor is automatically called when object(instance of class) is created.

Constructor is invoked at the time of object creation. It constructs the values i.e. provides data for the object that is why it is known as constructors.

Constructor does not have a return value, hence they do not have a return type.

User TechPassionate
by
3.2k points