Practice Problems  (on some topics covered after midsem)


1. Given an   (m X n) boolean matrix of 1s and 0s representing two lines
drawn on screen, find out whether the lines intersect.

2.  Using function drawtriangle (int x1, int y1, int x2, int y2, int x3, int y3),
development a recursive program that generates the Sieipinski triangle (see picture on this page: link to picture) till some depth 'd'.

3. Write a function to demonstrate that passing a pointer into a function does not mean
    you are passing by reference.

4.  Write a program that counts no. of occurances of a given word inside a file named
    text.txt.

5. Write a function to count no. of sentences inside the file
identified in the file name. A sentence is counted when a word ends with character '.'

6. Implement a function that returns an array of unique strings occuring inside a file.

7.  What will be the output of the following program?

#include<iostream>
using namespace std;
class C;
class D;
class A {
public: void virtual f(C *c){cout<<"A::f1\n";}
        void virtual f(D *d){cout<<"A::f2\n";}
};
class B: public A{
public: void virtual f(C* c){cout<<"B::f1\n";}
        void virtual f(D *d){cout<<"B::f2\n";}

};
class C{}; class D:public C{};
int main () {
A *a; B *b; C *c; D *d;
b = new B();  a=b;
d = new D(); c=d;
b->f(c); b->f(d);
a->f(c); a->f(d);
}

8. .. and how about  this one below?

#include<iostream>
using namespace std;
class A {
public: void virtual f(){cout<<"A::f\n";}
        void g(){cout<<"A::g\n";}
};
class B: public A{
public: void f(){cout<<"B::f\n";}
        void virtual g(){cout<<"B::g\n";}

};
class C: public B{
public: void virtual f(){cout<<"C::f\n";}
        void g(){cout<<"C::g\n";}

};
int main () {
A*a; B*b; C*c;
c=new C(); c->f();c->g();
b=c; b->f(); b->g();
a=b; a->f(); a->g();
b=new B(); b->f(); b->g();
a=b; a->f(); a->g();
}


9. Execute the programs that we made during lectures and reason about them..
i.e. answer why you get the outputs that you get from them.

10.  Try out  making solutions to the problems that I mentioned during your demo.

11. Complete the linked list program given in the class to add delete operation.