C CLASSES AND OBJECT STRUCTURE AND CLASSES SPECIFYING

C++ CLASSES AND OBJECT

STRUCTURE AND CLASSES








SPECIFYING A CLASS

SPECIFICATION OF A CLASS: • Specification of a class consists of two parts: 1. Class declaration 2. Function definition


Demo code: • • • • • #include <iostream> using namespace std; class add { public: int a; int b; }; int main( ) { add 1; add 1. a=2; add 1. b=5; int sum = add 1. a+add 1. b; cout << "after addition of two no: "<<sum; return 0; }

• #include<iostream> • using namespace std; • class test • { • public: • char name[30], clas[10]; • int rol, age; • void enter() • { • cout<<"Enter Student Name: "; • cin>>name; • cout<<"Enter Student Age: "; • cin>>age; • cout<<"Enter Student Roll number: "; • cin>>rol; • cout<<"Enter Student Class: "; • cin>>clas; • } • void display() • { • cout<<"n Aget. Namet. R. No. t. Class"; • cout<<"n";

Referrences: • http: //www. slideshare. net/shailendraveeru/classes-and-objects 25758779 • http: //www. w 3 schools. in/cplus/objects-classes/ • http: //www. slideshare. net/waqasazamkml/object-orientedprogramming-using-c-32608968 • http: //www. cpp. thiyagaraaj. com/c-programs/simple-program-forsingle-inheritance-using-c-programming
- Slides: 15