Lecture By Shery khan [email protected] C++ Programmer.

26
Lecture By Shery khan [email protected] C++ Programmer

Transcript of Lecture By Shery khan [email protected] C++ Programmer.

Page 1: Lecture By Shery khan sherykhan186@gmail.com C++ Programmer.

Lecture ByShery khan

[email protected]++ Programmer

Page 2: Lecture By Shery khan sherykhan186@gmail.com C++ Programmer.
Page 3: Lecture By Shery khan sherykhan186@gmail.com C++ Programmer.

Class Name

Public:

General Class Flow Chart

Functions Are Given

Like set get etc Further one Example is explained

Constructors

Constructor are used to

initialize the data members

Here We Can Give Constructor and its

Arguments

and also Give the Arguments to constructor if we did not define a Constructor C++ Also Provide A default constructor with no argument

Destructor

Tilde Sign is used with Class name to use destructor like

~class name

Private:

VISIBILTY IS HIDDEN BY DEFAULT

MEMBER OF CLASS ARE ONLY ACCESSIBLE FROM THEIR FRIEND

Page 4: Lecture By Shery khan sherykhan186@gmail.com C++ Programmer.

General Class Understanding Flow Chart Continue

Here Class is close with this };

Now outside the class Definitions are made

Constructor Defined Initialized and Destructor is Defined

Function Definition

Like getfunction,set function

Main() is now written and object is declared with class name like MyFeeofvu myFeeofvu1,myFeeofvu2(6500,1100); myFeeofvu1.Vufeedisplay(); myFeeofvu2.Vufeedisplay();

Page 5: Lecture By Shery khan sherykhan186@gmail.com C++ Programmer.

This End Of Flow Charting Now See the Code Each and Every Line Explain itself I take the Program of Time Class Which Show Time and proper constructor and Destructor calling See Next Pages You think Like a Programmer it will Help you to Understand the concept of Class Moreover visit my link www.sherykhan.jimdo.com download Material And learn much more C++ and C functionality.

Shery khan

Please See the Next Slide

Page 6: Lecture By Shery khan sherykhan186@gmail.com C++ Programmer.

#include<iostream.h>#include<stdio.h>class Time{ public: void display();//to dispaly the time of screen void setHours(int i);// setting Hours void setMinutes(int i);// setting minutes void setSeconds(int i);// setting seconds int getHours();// getting the value of Time int getMinutes();// getting the value of Minutes int getSeconds(); //getting the value of Seconds // constructor of a class Time(); Time(int,int); Time(int,int,int); // destructor of the class ~Time(); // hidden part of program private: int hours,minutes,seconds; };

Page 7: Lecture By Shery khan sherykhan186@gmail.com C++ Programmer.

Time::Time() { hours=6; minutes=30; seconds=60; cout<<"The Default Constructor is called"<<endl; } Time::Time(int theHours, int theMinutes)// constructor with two argument is called { hours=theHours; minutes= theMinutes; seconds= 45; cout<<"The constructor with Two argument is called"<<endl; }// the constructor with three argument is called Time::Time(int theHours,int theMinutes,int theSeconds) { hours= theHours; minutes=theMinutes; seconds=theSeconds; cout<<"The constructor with three argument is called"<<endl; }

Page 8: Lecture By Shery khan sherykhan186@gmail.com C++ Programmer.

Time::~Time() { cout<<"The Destructor will called and the object is Destroyed"<<endl; } void Time::display() { cout<<"The Pakistan Standard Time is "<<getHours()<<":"<<getMinutes()<<":"<<getSeconds()<<endl; } void Time:: setHours(int i) { hours=i; } void Time::setMinutes(int i) { minutes=i; } void Time::setSeconds(int i) { seconds=i; } int Time::getHours() { return hours; } int Time::getMinutes() { return minutes; } int Time::getSeconds() { return seconds; }

Page 9: Lecture By Shery khan sherykhan186@gmail.com C++ Programmer.

int main(){cout<<"********** SHEHARYAR KHAN Time Class PROJECT **************\n";cout<<"********* SOFTWARE DEVELOPER COMPANY SAILKOT **********\n";cout<<"********** [email protected] ****************\n";cout<<" "<<endl; Time time1,time2(6,6),time3(6,45,35); time1.display(); time2.display(); time3.display(); system("Pause"); }

Page 10: Lecture By Shery khan sherykhan186@gmail.com C++ Programmer.

Output: My Time Class:

Page 11: Lecture By Shery khan sherykhan186@gmail.com C++ Programmer.

This is Complete Class of Time you copy Slide 6,Slide7Slide8 ,slide 9 paste in your Developer of C then you see the out of Time More Examples Are Made So keep reading the stuff You can Develop your own Class at the End some more phenomena's are discussed so read it carefully think like a programmer then you will achieve the goals

::::Presented By Sherykhan::::

Page 12: Lecture By Shery khan sherykhan186@gmail.com C++ Programmer.

Now Another Program of Class is Your Vu Fee Structure

See the Code and enhance your proficiency in developing Classes in C++

Thanks to giving me a Time ::::::::::::::

Page 13: Lecture By Shery khan sherykhan186@gmail.com C++ Programmer.

#include<iostream.h>class MyFeeofvu{ public: void Vufeedisplay(); void setSemesfee(int k);// setting semester fee void setMonthlyFee(int k);// setting Monthly fee int getSemesfee();// getting Semester fee int getMonthlyfee();//getting semester fee

MyFeeofvu(); MyFeeofvu(int,int); ~MyFeeofvu(); //destructor private: int semesfee,monthlyfee; };

Page 14: Lecture By Shery khan sherykhan186@gmail.com C++ Programmer.

// default constructor MyFeeofvu::MyFeeofvu() { semesfee=8500; monthlyfee=1200; cout<<"The Default Constructor is called"<<endl; } // constructor with two argument MyFeeofvu:: MyFeeofvu(int myFee, int myMonthlyfee)// constructor with two argument is called { semesfee=myFee; monthlyfee=myMonthlyfee; cout<<"The constructor with Two argument is called"<<endl; }

Page 15: Lecture By Shery khan sherykhan186@gmail.com C++ Programmer.

// destructor MyFeeofvu::~MyFeeofvu() { cout<<"The Destructor will called and the object is Destroyed"<<endl; } void MyFeeofvu::Vufeedisplay() { cout<<"My Total Fee In Vu is"<<getSemesfee()<<endl; cout<<"My monthly Fee in vu is"<<getMonthlyfee()<<endl; } void MyFeeofvu::setSemesfee(int k) { semesfee=k; } void MyFeeofvu::setMonthlyFee(int k) { monthlyfee=k; } int MyFeeofvu::getSemesfee() { return semesfee; } int MyFeeofvu::getMonthlyfee() { return monthlyfee; }

Page 16: Lecture By Shery khan sherykhan186@gmail.com C++ Programmer.

int main() {cout<<"********** SHEHARYAR KHAN Class PROJECT **************\n";cout<<"********* SOFTWARE DEVELOPER COMPANY SAILKOT **********\n";cout<<"********** [email protected] ****************\n";cout<<" "<<endl;MyFeeofvu myFeeofvu1,myFeeofvu2(6500,1100); myFeeofvu1.Vufeedisplay(); myFeeofvu2.Vufeedisplay(); getchar();}

Page 17: Lecture By Shery khan sherykhan186@gmail.com C++ Programmer.

Output: My Class Fee Structure of Vu:

Page 18: Lecture By Shery khan sherykhan186@gmail.com C++ Programmer.

Here I can Explain the Fee System of Vu

The one Fee is Regular Student Fee which use Vu premises And other is Home base and I expalin the Monthlyfee and Full fee I think you can understand if yes then Good If no then Ask me Questions on my mail adress [email protected]

Now see the next program which tells you marks and age so learn more then I can Explain

Now Few Concept that I can learn

Page 19: Lecture By Shery khan sherykhan186@gmail.com C++ Programmer.

#include<iostream.h>#include<stdio.h>class Shery{ public: void display(); void setAge(int i); void setMarks(int i); int getAge(); int getMarks();Shery();Shery(int,int); ~Shery();

Page 20: Lecture By Shery khan sherykhan186@gmail.com C++ Programmer.

private: int age,marks; }; Shery::Shery() { age=23; marks=895; cout<<"The Default Constructor is called"<<endl; } Shery:: Shery(int myAge, int myMarks)// constructor with two argument is called { age=myAge; marks= myMarks; cout<<"The constructor with Two argument is called"<<endl; }

Page 21: Lecture By Shery khan sherykhan186@gmail.com C++ Programmer.

Shery::~Shery() { cout<<"The Destructor will called and the object is Destroyed"<<endl; } void Shery::display() { cout<<"I am Shery khan my Age is"<<getAge()<<endl; cout<<"My marks in Intermiadiate are"<<getMarks()<<endl; } void Shery:: setAge(int i) { age=i; } void Shery::setMarks(int i) { marks=i; } int Shery::getAge() { return age; } int Shery::getMarks() { return marks; }

Page 22: Lecture By Shery khan sherykhan186@gmail.com C++ Programmer.

int main() { cout<<"********** SHEHARYAR KHAN Class PROJECT **************\n";cout<<"********* SOFTWARE DEVELOPER COMPANY SAILKOT **********\n";cout<<"********** [email protected] ****************\n";cout<<" "<<endl;Shery shery1,shery2(25,800); shery1.display(); shery2.display(); getchar();}

Page 23: Lecture By Shery khan sherykhan186@gmail.com C++ Programmer.

Output: of Class Age and Marks

Page 24: Lecture By Shery khan sherykhan186@gmail.com C++ Programmer.

Question answer session:

What is Constructor?

•Constructor is special function called when ever we instantiate an object

•If we do not define constructor C++ provides a default constructor

•Constructor give us the opportunity to initialize the data members of an object

•Constructor doest not return any thing so it has no return type

Who create space for data members?

The constructor create space for data and put values in them

What are the important key points of constructor?

Constructor is a function which has same name as class

It has no return type statement whenever an instance of a class comes into scope the constructor is executed

Page 25: Lecture By Shery khan sherykhan186@gmail.com C++ Programmer.

Constructor can be overloaded .we can write as many constructor as we require.

You can see the constructor in Example but I can explain the Syntax of constructor

Syntax of Default Constructor

Time();

Syntax of Parameterized constructor:

Time(int,int) we see time is name of class which take three argument

Important Note :

Information is Given from some Reference books my Personal Programs Reviews By Many Professionals so 100% Correct

I restrict my self to classes because Programming is like a entire world so no one complete all .

Page 26: Lecture By Shery khan sherykhan186@gmail.com C++ Programmer.

THANKS I know some important Aspects are missing due to Lack of Time I done some part many mails are related to Classes so I should done: If you want to learn more please visit the Free website where you can get knowledge about C programmingPlease Comment us whether it is use full or not? Official Mail :[email protected]:www.sherykhan.jimdo.com Social Pageswww.facebook.com/[email protected] Log on towww.linkedin.com/SheharyarkhanYahoo address:[email protected]:Sheharyar khan Just Strive For success!!!!!!!