Introduction to C++ - Google Sites

4 downloads 171 Views 313KB Size Report
Keywords are the words already used by C++ in its compiler. They are also known ...... ofile.open("tamils",ios::app|ios:
Introduction to C++ Table of Contents 1. Paradigm of C++ 1.1 OOP 1.2 ; dynmem name1(first); dynmem name2("and Communication "); dynmem name3("Engineering"); dynmem s1,s2; s1.join(name1,name2); s2.join(s1,name3); name1.display(); Page 34 of 82 Copyright Einstein College of Engineering Department of Civil Engineering

www.EEENotes.in

Introduction to C++ name2.display(); name3.display(); s1.display(); s2.display(); } Destructor: The purpose of destructor is to release the memory when the compiler memory is reduced or insufficient to execute certain program. Some times there may several objects opened and it may occupy more memory which may lead to reduced memory for new objects to be created. Therefore to increase the memory; objects which are idle may be destruct or killed using the destructor. The destructor is written in same way as constructor with following rule.  Destructor must have the class name.  Destructor must be preceded with ~ (tilde).  Destructor cannot have any argument or return type.  Destructor is initiated implicitly.  Only one destructor for each class.  Destructor must be public.  Destructor can be defined any where in the public usually it is written at the end.  Destructor can have prototype. class item { int number; float cost; public: void put; String name1(first); String name2("and Communication ");String name3("Engineering"); String s1,s2; s1.join(name1,name2); s2.join(s1,name3); s1=name1+name2; s2=s1+name3; name1.display();name2.display();name3.display(); s1.display(); s2.display(); } Different Methods in unary operator overloading: class sign {int a,b,c; public: sign(){}; sign(int,int,int); void putdata(void); //int operator-(); //This is also a method I sign changeI(sign ); //Method II void changeII(sign & ); //Method III friend void operator-(sign &); //Method IV }; /* This is also a method int sign::operator-() {a=-a;b=-b;c=-c; return 1;} Page 42 of 82 Copyright Einstein College of Engineering Department of Civil Engineering

www.EEENotes.in

Introduction to C++ */ sign sign::changeI(sign s) {s.a=-s.a;s.b=-s.b;s.c=-s.c;

return s;}

void sign::changeII(sign &s) {a=-s.a;b=-s.b;c=-s.c; } void operator-(sign &s) {s.a=-s.a;s.b=-s.b;s.c=-s.c;

}

void sign::putdata(void) {cout

Suggest Documents