Skip to main content

Object Orientation Enlarged by an Example!


This program illustrates how to implement the arithmetic operation in an object oriented way.

Here we have a class with 2 variables. For each operation an object of this class is created to do the operation instead of declaring such much variables. Therefore, this method is, for a large scale implementation, is quite efficient.
so have a try on it.



Program:


//simple operations in object oriented method
#include<conio.h>
#include<iostream.h>

class dom
{
int a,b;
public:
void get()
{
cout<<"oops..!\nnumbers:";
cin>>a>>b;
cout<<"passed";
}
void add()
{
cout<<endl<<"a+b="<<a+b;
}
void diff()
{
cout<<endl<<"a-b="<<a-b;
}
void mult()
{
cout<<endl<<"a*b="<<a*b;
}
void div()
{
cout<<endl<<"a/b="<<a/b;
}

};

void main()
{
clrscr();
dom add, mult,diff,div;

cout<<"\n+";
add.get();

cout<<"\n-";
diff.get();

cout<<"\n*";
mult.get();

cout<<"\n/";
div.get();

cout<<"\n\nprocessing...";

add.add();
diff.diff();
mult.mult();
div.div();
cout<<"\n\nover";
getch();

}

Have u tried this?

Comments

Popular posts from this blog

Talky Messenger Documentation & Setup

( Github ) Just created a chat app that runs in Node and Socket. the attempt was worthy. Talky is a messenger app built with Node, Express, Socket, Angular & Bootstrap. It's like a server-client structure. (But obviously not like the one we done at OS lab using shared memory). It has a broadcasting structure. Talky does not keep a log on chat. i.e., It doesn't have a memory or database. When we close the browser window, chat history is lost. There I also added a basic console, protected by a password, to send real-time notifications to active clients. The name 'Talky' was suggested by a friend of mine. (hey, thank you for that. The fact is that I am not really good at naming...😝) What if sometimes your college blocks WhatsApp? Try Talky. ( There is also a website on internet in the name of 'Talky' which has no connection with this one. ) Download Talky Messenger To use Talky, all you need is 3 things: Node server Source code...

Repairing my keyboard gone wrong and then right.

Few months ago I tried to repair an old unused keyboard. I opened it cleaned and put everything back in place. But didn't work. Thinking it has met it's end-of-life, I gave it to my sister's daughter, 2 year old Komal. She went hard with it. Once she even thrown it. To my surprise, after a few throws, it's now working properly 🙆.