Int Int: Main (I, J, K J &i Printf (, I J I+ J) )

You might also like

Download as pdf or txt
Download as pdf or txt
You are on page 1of 1

Programming Fundamentals Final Term University of Engineering and Technology, Lahore Maximum Marks 40

Time Allowed 90 min Name: Reg. # 201 – EE – Answer Sheet # .


CLO 3 (Unguided Problem) - Question # 1 (10 Marks): Two words CLO 1 (Analysis) - Question # 4 (10 Marks): Write output of the
are called anagrams if they consist of exactly the same following program.
letters but in different order. While an isogram is a word in
#include <iostream>
which no letter of the alphabet occurs more than once. You
#include <string>
have to write a function which will take two strings as an using namespace std;
input and will check if they are anagrams and isograms. class Shape {
Some examples of anagrams and isograms are: “leap”, protected:
“pale” and “peal”. You can use built-in functions. int width, height, Area;
public:
Shape( int a = 0, int b = 0){
CLO 2 (Guided Problem) - Question # 2 (10 marks): Write a
width = a;
program to find 2s complement of a string containing only height = b;
numbers i.e. “12345”. Two's complement is one's }
complement + 1. The ones' complement of a binary number int area() {
is defined as the value obtained by inverting all the bits in Area = width * height;
the binary representation of the number (swapping 0s for 1s cout << "Parent class area :" << Area <<endl;
and vice versa). return 0;
}
Note: You can convert this string to integer. int area(int w) {
width = w;
CLO 1 (Analysis) - Question # 3 (10 Marks): Write output and Area = width * height;
show your working. Do it on question paper. cout << "Parent class area :" << Area <<endl;
return 0;
int main() }
{ };
int i=3, *j, k; class Triangle: public Shape {
j = &i; public:
printf("%d\n", i**j*i+*j); Triangle( int a = 0, int b = 0):Shape(a, b) { }
return 0; int area () {
} Area = (width * height / 2);
cout << "Triangle class area :" << Area <<endl;
return 0;
}
};
class Complex {
private:
int real, imag;
public:
Complex(int r = 0, int i =0) {real = r; imag = i;
}
// This is automatically called when '+' is used with
// between two Complex objects
Complex operator + (Complex const &obj) {
Complex res;
res.real = real + obj.real;
res.imag = imag + obj.imag;
return res;
}
void print() { cout << real << " + i" << imag << endl;
}
};
int main()
{
Triangle tri(10,5);
tri.area();
Shape rec(10,7);
rec.area();
rec.area(8);
Complex c1(10, 5), c2(2, 4);
Complex c3 = c1 + c2; // An example call to "operator+"
c3.print();
}

You might also like