question 4 - #include

Info icon This preview shows pages 1–2. Sign up to view the full content.

View Full Document Right Arrow Icon
Fundamentals Programming Classes Laboratory 4 1. Consider a class emp , which is defined as shown: class emp { int id; float salary; public: emp(){ id =0; salary = -1; } void input(int c, float s) { Id= c; salary= s; } }; Add a constructor with two parameters to the class emp ; Add a copy constrictor to the class emp . Add a destructor to the class emp ; Add a global function with one parameter emp. Function should display all elements of object emp. Create a following object: emp obj1; emp obj2(23, 2500); emp obj3=obj2; Display all id and salary using defined global function. Define an array all emp of 50 object of type emp. Using a loop, write a code to change id and salary of the first 10 objects of the array to values 100 and 500 respectively. 2. Trace the following programs and check the generated output?
Image of page 1

Info icon This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
Image of page 2
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: #include <iostream.h> class Point { public: Point(int = 10,int = 10); void set_values(int, int); int get_Z( ) { return z;}; void Display( ) const; private: int X; int Y; static int z; }; int Point::z = 20; Point::Point(int a, int b) { set_values(a,b); ++z; } void Point::set_values(int a, int b) { X = a; Y = b; } void Point::Display( ) const { cout << X << " , " << Y << endl; } Barbara Fryc Fundamentals Programming Classes Laboratory 4 int main() { int i; Point r1,r2; Point A(10,20); Point D[3]; Point *p; A.Display(); p = new Point[5]; for (i = 1; i <3; i++) p[i].set_values (i,i*2); p ->Display(); p[2].Display(); cout << "------------- \n"; D[1]= A; D[2].set_values(A.get_Z(), A.get_Z() ); D[1].Display(); D[2].Display(); return 0; } Barbara Fryc...
View Full Document

{[ snackBarMessage ]}

What students are saying

  • Left Quote Icon

    As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

    Student Picture

    Kiran Temple University Fox School of Business ‘17, Course Hero Intern

  • Left Quote Icon

    I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

    Student Picture

    Dana University of Pennsylvania ‘17, Course Hero Intern

  • Left Quote Icon

    The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

    Student Picture

    Jill Tulane University ‘16, Course Hero Intern