Professional Documents
Culture Documents
NAME:
ATTRIBUTES:
FUNCTIONS:
SYNTAX:
name :Class Student
attributes {Id, Name}
methods: constructors, print function etc.
Student
class Student {
public :
Student () {
Cout<<"Student Created\n";
}
};
void main () {
Student st;
}
- Implicit Call (as you make object, it is implicitly called) person p; student st;
class Student {
public :
Student () {
// allocate memory, (1)garbage, (2) default 0, unknown, (3) what ever will be
needed at run time. out of first two only may exist.
if no constructor then default constructor is written by compiler.
Cout<<"Student Created\n";
}
};
void main () {
Student st;// function call in the main body of class
.........................................
Initialize Student Class Members Using Constructor
#include <iostream.h>
#include <string.h>
class Student {
private:
int id;
string name;
public :
Student (){
id=0;
name=“unknown";
}
void print() {
cout<<id<<endl;
cout<<name<<endl;
}
};
void main () {
Student st;
st.print();
}
...............................................
Constructor Overloading (input parameter)
#include <iostream.h>
#include <string.h>
class Student {
private:
int id;
string name;
public :
Student (){
id=0;
name=“unknown";
cout<<"Student Created\n";
}
Student(int d, string n){
id=d;
name=n;
cout<<"Student Created with Parameter\n";
}
Ivoid print() {
cout<<id<<endl;
cout<<name<<endl;
}
};
void main () {
Student st1;
st1.print();
Student st2(10,"Farooq");
st2.print();
}
...............................................