Advertisement
albela

Untitled

Apr 18th, 2021
105
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.83 KB | None | 0 0
  1. // Q3.Write a program to perform parameterized constructor.
  2. //Solution:-
  3.  
  4. #include <iostream>
  5. using namespace std;
  6. class Professor {
  7. public:
  8. int id;
  9. string name;
  10. float salary;
  11. Professor (int i, string n, float s)
  12. {
  13. id = i;
  14. name = n;
  15. salary = s;
  16. }
  17. void display ()
  18. {
  19. cout<<id<<" "<<name<<" "<<salary<<endl;
  20. }
  21. };
  22. int main(void) {
  23. Professor p1=Professor(10, "Aditya", 90000);
  24. Professor p2=Professor(12, "Anu", 60000);
  25. p1.display();
  26. p2.display();
  27. return 0;
  28. }
  29. /*
  30. In this example, a class Professor is declared which includes an access specifier as public type and then it is followed with data members as int id and string name the output which includes the implementation of the constructor will display the name of the professor, Id of the professor and salary he or she earns. Further manipulations can also be made to this
  31. */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement