0% found this document useful (0 votes)
153 views3 pages

C++ Saurabh Shukla

a course of c++ language by saurabh shukla

Uploaded by

Saud khan
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
153 views3 pages

C++ Saurabh Shukla

a course of c++ language by saurabh shukla

Uploaded by

Saud khan
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 3

{program}/for structure/

#include<conio.h>
#include<iostream.h>
struct book
{
int bookid;
char title[20];
float price;
void input()
{
cout<<" Enter bookid,title,and price";
cin>>bookid>>title>>price;
}
void display()
{
cout<<"\n"<<bookid<<" "<<title<<" "<<price;
};
void main()
{
clrscr();
book b1;
b1.input();
b1.display();
getch{};
}
{program}/for structure with access modifier/
#include<conio.h>
#include<iostream.h>
struct book
{
private:
int bookid;
char title[20];
float price;
void input()
{
public:
cout<<" Enter bookid,title,and price";
cin>>bookid>>title>>price;
}
void display()
{
cout<<"\n"<<bookid<<" "<<title<<" "<<price;
};
void main()
{
clrscr();
book b1;
b1.input();
b1.display();
getch{};
}

"static member variable"


"static member function"
;they are qualified with the keyboard static.
;they are also called class member function.
;they can invoked with or without object.
;they can only access static members of the class.
"" Constructor in c++""
" Construtor"
;constructor is a member function of a class.
;THe name of the constructor is same as the name of the class
;it has no return type,so can't use return keyword.
;it must be an instance member function,that is , it can never be static.
;constructor is implicitly invoked when an objesct is created.
;constructor is used to solve problem of initialization.

{program}/for constructor/
#include<conio.h>
class complex
{
private:
int a,b;
public:
complex()
{ cout<<"hello constructor";}
};
void main()
{
clrscr();
complex c1,c2,c3;
getch();
}
;Default constructor
; parameterized constructor

{program}/for default and parameterized constructor/


#include<conio.h>
class complex
{
private:
int a,b;
public:
complex(int x,int y) //parameterized constructor//
{ a=x; b=y; }
complex (int k)
{ a=k;}
complex() //default constructor//
{ }
};
void main()
{
clrscr();
complex c1,c2,c3;
getch();
}
"" Destructor""
; Destructor is an instance member function of a class
;the name of the destructor is same as the name of a class but preceded by tilde
(~) symbol
;Destructor can never be static
;Destructor has no return type '
;Destructor takes no argument(no overloading is possible)
; it is invoked implicity when going to destroy
{program}/for destructor/
#include<conio.h>
#include<iostream.h>
class complex
{
private:
int a,b;
public:
complex()
{cout<<"Destructor;}
};
void fun {}
{
complex obj;
}
void main{}
{
clrscr{};
fun{};
getch{};
};
{program}/for operator overloading/
#include<conio.h>
#include<iostream.h>
class comlplex
{
private;
int a,b;
public;
void setdata(int x, int y)
{ a=x; b=y;}
void showdata{}
{cout<<"/na"<<a<<"b"<<b;}
};
void main{}
{
clrscr{};
complex c1,c2,c3;
c1.setdata{3,4};
c2.setdata{5,6};
c3=c1.add{c2};
c3

You might also like