Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Question 1)=What is the output of the following program? class Nums { int x, y;

ID: 3688924 • Letter: Q

Question

Question 1)=What is the output of the following program?

class Nums { int x, y;

public:

void set(int a){ x =a; y =x*2; }

void display() { cout <<x <<' ' <<y <<endl; }

};

int main()

{ Nums *nptr; int n=3;

nptr = new Nums[n]; for (int i=0; i<n; i++) { nptr[i].set(i);

nptr[i].display();

}

Question 2)=Given the following Pixel class definition, write a definition of the Display( ) friend function that will display the values of x and y. Give an example of the function call.

class Pixel { int x, y;

public:

Pixel(int a, int b){ x = a; y = b; } friend void Display(Pixel obj);

};

}

Explanation / Answer

1.i will take values->0,1,2

for i=0

=>x=0,y=0

for i=1

=>x=1,y=2

for i=2

x=2,y=4

output:

x=0 y=0

x=1 y=2

x=2 y=4

2. this is the defination:

friend void Display(Pixel obj);

{cout<<obj.x<<obj,y;

}

class Pixel { int x, y;

public:

Pixel(int a, int b){ x = a; y = b;

friend void Display(Pixel obj)

{cout<<obj.x<<obj,y;

}

int main()

{pixel p1;

p1.display(p1); calling here

}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote