diff --git a/file.org b/file.org index 8d9f67f..4330733 100644 --- a/file.org +++ b/file.org @@ -32,3 +32,7 @@ * Lab 6 #+INCLUDE: ./lab6/file.org #+LATEX: \clearpage + +* Lab 7 +#+INCLUDE: ./lab7/file.org +#+LATEX: \clearpage diff --git a/file.pdf b/file.pdf index 8889035..f028272 100644 Binary files a/file.pdf and b/file.pdf differ diff --git a/lab2/file.org b/lab2/file.org index 9b3a713..38c72bb 100644 --- a/lab2/file.org +++ b/lab2/file.org @@ -206,7 +206,7 @@ void Student::input() { cin >> this->age; cout << "Gender (m/f): "; cin >> this->gender; - + cout << "Enter Marks for" << endl; for (i = 0; i < NSUBS; i++) { diff --git a/lab7/19.cpp b/lab7/19.cpp new file mode 100644 index 0000000..9d9bf15 --- /dev/null +++ b/lab7/19.cpp @@ -0,0 +1,22 @@ +#include +using namespace std; + +class Foo { + int x; + +public: + Foo(int _x) { x = _x; }; + Foo &operator++(); + int get() { return x; } +}; + +Foo &Foo::operator++() { + x++; + return *this; +} + +int main() { + Foo bar = Foo(-3); + ++bar; + cout << bar.get(); +} diff --git a/lab7/20.cpp b/lab7/20.cpp new file mode 100644 index 0000000..d656cf6 --- /dev/null +++ b/lab7/20.cpp @@ -0,0 +1,22 @@ +#include +using namespace std; + +class Foo { + int x; + +public: + Foo(int _x) { x = _x; }; + Foo operator+(Foo); + int get() { return x; } +}; + +Foo Foo::operator+(Foo bar) { + return Foo(x + bar.get()); +} + +int main() { + Foo bar = Foo(-3); + Foo baz = Foo(8); + + cout << (bar + baz).get(); +} diff --git a/lab7/21.cpp b/lab7/21.cpp new file mode 100644 index 0000000..6ba380f --- /dev/null +++ b/lab7/21.cpp @@ -0,0 +1,22 @@ +#include +using namespace std; + +class Foo { + int x; + +public: + Foo(int _x) { x = _x; }; + Foo operator*(Foo); + int get() { return x; } +}; + +Foo Foo::operator*(Foo bar) { + return Foo(x * bar.get()); +} + +int main() { + Foo bar = Foo(-3); + Foo baz = Foo(8); + + cout << (bar * baz).get(); +} diff --git a/lab7/file.org b/lab7/file.org new file mode 100644 index 0000000..01e6868 --- /dev/null +++ b/lab7/file.org @@ -0,0 +1,87 @@ +* Write a program to overload (++) operator. + +#+ATTR_LATEX: :options frame=single,breaklines=true +#+begin_src cpp :tangle 19.cpp :results output :exports both :wrap src text +#include +using namespace std; + +class Foo { + int x; + +public: + Foo(int _x) { x = _x; }; + Foo &operator++(); + int get() { return x; } +}; + +Foo &Foo::operator++() { + x++; + return *this; +} + +int main() { + Foo bar = Foo(-3); + ++bar; + cout << bar.get(); +} +#+end_src + +#+LATEX: \clearpage + +* Write a program to overload + operator. + +#+ATTR_LATEX: :options frame=single,breaklines=true +#+begin_src cpp :tangle 20.cpp :results output :exports both :wrap src text +#include +using namespace std; + +class Foo { + int x; + +public: + Foo(int _x) { x = _x; }; + Foo operator+(Foo); + int get() { return x; } +}; + +Foo Foo::operator+(Foo bar) { + return Foo(x + bar.get()); +} + +int main() { + Foo bar = Foo(-3); + Foo baz = Foo(8); + + cout << (bar + baz).get(); +} +#+end_src + +#+LATEX: \clearpage + +* Write a program to overload * operator. + +#+ATTR_LATEX: :options frame=single,breaklines=true +#+begin_src cpp :tangle 21.cpp :results output :exports both :wrap src text +#include +using namespace std; + +class Foo { + int x; + +public: + Foo(int _x) { x = _x; }; + Foo operator*(Foo); + int get() { return x; } +}; + +Foo Foo::operator*(Foo bar) { + return Foo(x * bar.get()); +} + +int main() { + Foo bar = Foo(-3); + Foo baz = Foo(8); + + cout << (bar * baz).get(); +} +#+end_src