Test QP C++ ADA 1 Codes

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 3

ADA using C++ Event

1. What is the output:

1. #include <iostream>
2. using namespace std;
3. class sample
4. {
5. public:
6. int x, y;
7. sample() {};
8. sample(int, int);
9. sample operator + (sample);
10. };
11. sample::sample (int a, int b)
12. {
13. x = a;
14. y = b;
15. }
16. sample sample::operator+ (sample param)
17. {
18. sample temp;
19. temp.x = x + param.x;
20. temp.y = y + param.y;
21. return (temp);
22. }
23. int main ()
24. {
25. sample a (4,1);
26. sample b (3,2);
27. sample c;
28. c = a + b;
29. cout << c.x << "," << c.y;
30. return 0;
31. }

4. What is the output of the code?

1. #include <iostream>
2. using namespace std;
3. class Integer
4. {
5. int i;
6. public:
7. Integer(int ii) : i(ii) {}
8. const Integer
9. operator+(const Integer& rv) const
10. {
11. cout << "operator+" << endl;
12. return Integer(i + rv.i);
13. }
14. Integer&
15. operator+=(const Integer& rv)
16. {
17. cout << "operator+=" << endl;
18. i += rv.i;
19. return *this;
ADA using C++ Event
20. }
21. };
22. int main()
23. {
24. int i = 1, j = 2, k = 3;
25. k += i + j;
26. Integer ii(1), jj(2), kk(3);
27. kk += ii + jj;
28. }

5. What is the output ?

#include <iostream>
using namespace std;
class A{
public:
int a;
};
int main(int argc, char const *argv[])
{
A a1 = {10};
A a2 = a1;
cout<<a1.a<<a2.a;
return 0;
}

11. Choose the correct output for the following Code:

1. #include <iostream>
2. using namespace std;
3. class polygon
4. {
5. protected:
6. int width, height;
7. public:
8. void set_values (int a, int b)
9. {
10. width = a; height = b;}
11. };
12. class output1
13. {
14. public:
15. void output (int i);
16. };
17. void output1::output (int i)
18. {
19. cout << i << endl;
20. }
21. class rectangle: public polygon, public output1
22. {
23. public:
24. int area ()
25. {
26. return (width * height);
ADA using C++ Event
27. }
28. };
29. class triangle: public polygon, public output1
30. {
31. public:
32. int area ()
33. {
34. return (width * height / 2);
35. }
36. };
37. int main ()
38. {
39. rectangle rect;
40. triangle trgl;
41. rect.set_values (4, 5);
42. trgl.set_values (4, 5);
43. rect.output (rect.area());
44. trgl.output (trgl.area());
45. return 0;
46. }

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy