forked from natto1784/ooplab
4
file.org
4
file.org
@@ -32,3 +32,7 @@
|
|||||||
* Lab 6
|
* Lab 6
|
||||||
#+INCLUDE: ./lab6/file.org
|
#+INCLUDE: ./lab6/file.org
|
||||||
#+LATEX: \clearpage
|
#+LATEX: \clearpage
|
||||||
|
|
||||||
|
* Lab 7
|
||||||
|
#+INCLUDE: ./lab7/file.org
|
||||||
|
#+LATEX: \clearpage
|
||||||
|
@@ -206,7 +206,7 @@ void Student::input() {
|
|||||||
cin >> this->age;
|
cin >> this->age;
|
||||||
cout << "Gender (m/f): ";
|
cout << "Gender (m/f): ";
|
||||||
cin >> this->gender;
|
cin >> this->gender;
|
||||||
|
|
||||||
cout << "Enter Marks for" << endl;
|
cout << "Enter Marks for" << endl;
|
||||||
|
|
||||||
for (i = 0; i < NSUBS; i++) {
|
for (i = 0; i < NSUBS; i++) {
|
||||||
|
22
lab7/19.cpp
Normal file
22
lab7/19.cpp
Normal file
@@ -0,0 +1,22 @@
|
|||||||
|
#include <iostream>
|
||||||
|
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();
|
||||||
|
}
|
22
lab7/20.cpp
Normal file
22
lab7/20.cpp
Normal file
@@ -0,0 +1,22 @@
|
|||||||
|
#include <iostream>
|
||||||
|
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();
|
||||||
|
}
|
22
lab7/21.cpp
Normal file
22
lab7/21.cpp
Normal file
@@ -0,0 +1,22 @@
|
|||||||
|
#include <iostream>
|
||||||
|
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();
|
||||||
|
}
|
87
lab7/file.org
Normal file
87
lab7/file.org
Normal file
@@ -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 <iostream>
|
||||||
|
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 <iostream>
|
||||||
|
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 <iostream>
|
||||||
|
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
|
Reference in New Issue
Block a user