Saturday 19 August 2017

OOP example

Int.h
class Int{
private:
    int i;
public:
    Int() :i(0){

    }
    Int(int n){
    }
    void add(Int x, Int y){
    }
    void display(){
    }

};
Int.cpp
#include "Int.h"
# include <iostream>
using namespace std;
Int::Int():i(0){
    cout << "empty";
}
Int::Int(int n){
    i = n;
}
void Int::add(Int x, Int y){
    i = x.i + y.i;

}
void Int::display(){
    cout << " the ineger is" << i;
}
source.cpp
# include "Int.h"
# include <iostream>
using namespace std;
int main()
{
    Int first, second(320), third(455);
    first add(second,third);
    first.display();
    system("pause");
    return 0;

}

0 comments: