PPT Lecture 1.2.2
PPT Lecture 1.2.2
Course Objectives
3
Scheme of Evaluation
Direct Evaluation Weightage of actual Final Weightage in Mapping with SIs Remarks
Sl No. Frequency of Task BT Levels CO Mapping Mapping with PIs
Instruments conduct Internal Assessment (ABET) (Graded/Non-Graded)
SO1 1a,1b,1c
10 marks for each
1 Assignment One per unit 10 Hard CO4,CO5 Graded
assignment
SO6
2 Exam 20 marks for one MST 2 per semester 20 Medium CO1,CO2,CO3,CO4 6a,6b Graded
3 Case Study 8 marks 1 per unit 8 Easy CO2 SO1, SO6 1c,6b Graded
NA NA NA NA
One per lecture
4 Homework NA topic (of 2 NA Non-Graded
questions)
NA NA NA NA
5 Discussion Forum NA One per unit NA Non-Graded
NA NA NA NA
6 Presentation NA NA NA Non-Graded
7 Attendance NA NA 2 NA NA NA NA Graded
Remarks
Direct Evaluation Final Weightage in Mapping with SIs
S No. Weightage of actual conduct Frequency of Task BT Levels CO Mapping Mapping with PIs (Graded/Non-
Instruments Internal Assessment (ABET)
Graded)
Unit wise Practical 1a, 1b, 1c, 6a, 6b SO1, SO6
1 15 marks 3 45 Medium 1,2,3,4,5 Graded
Evaluation
1a, 1b, 1c, 6a, 6b
2 Exam 15 marks for one MST 1 per semester 15 Medium 1,2,3 SO1, SO6 Graded
3 Attendance NA NA 2 NA NA NA NA Graded
4
What
. A function declared as a
member of a class is called
as a member function. Why
Member functions are Member functions and functions are
mostly given the attributes names used interchangeably in
of public because they reference classes. Function prototypes
have to be called outside are declared within the class definition.
the class either in a These prototypes can take the form of
non-class functions as well as class
program or in the function.
suitable prototypes. Functions can be
declared and defined within the class
definition.
5
CONTENTS
6
Defining a Member function
We define the function inside class then we don't not need to declare it first, we can
directly define the function,the class name and the scope resolution operator are
not specified in the function header.Moreover, the member functions defined inside a class
definition are by default inline functions.
class Cube
{
public:
int side;
int getVolume()
{
return side*side*side; //returns volume of cube
}
}; 8
Defining a Member function Inside class(Example)
Contd…
class sample
{
private:
float x;
float y;
public:
void get()
{
cout<<"enter any two number"<<endl;
cin >>x>>y;
}
9
Defining a Member function Inside class(Example) Contd…
void disp()
{
cout<<"First value = " <<x<<endl;
cout<<"Second value = "<<y<<endl;
cout<<"sum = "<<sum()<<endl;
cout<<"sub = "<<sub()<<endl;
cout<<"mul = "<<mul()<<endl;
cout<<"div = "<<div()<<endl;
}
float sum()
{ 10
Defining a Member function Inside class(Example) Contd…
float sub()
{
return(x-y);
}
float mul()
{
return(x*y);
}
float div()
{
return (x/y);
}
}; 11
Defining a Member function Inside class(Example) Contd…
int main()
{
sample temp;
temp.get();
temp.disp();
temp.sum();
temp.sub();
temp.mul();
temp.div();
}
12
Defining a Member function outside the class
But if we define the member function outside the class definition then we must declare
the function inside class definition and then define it outside.
The definition of member function outside the class differs from normal function
definition, as the function name in the function header is preceded by the class name and
the scope resolution operator (: :). The scope resolution operator informs the compiler
what class the member belongs to. The syntax for defining a member function outside
the
class is
class Cube
{
public:
int side;
int getVolume();
} // member function defined outside class definition
int Cube :: getVolume()
{
return side*side*side;
}
14
Defining a Member function outside the class(Example) Contd…
class sam
{
private:
float x;
float y;
public:
void get();
void disp();
float sum();
float diff();
float mul();
float div();
}; //End of the class 15
Defining a Member function outside the class(Example)
Contd…
void sam::get()
{
cout<<"Enter any two numbers"<<endl;
cin>>x>>y;
}
void sam::disp()
{
cout<<"First value="<<x<<endl;
cout<<"Second value="<<y<<endl;
cout<<"Sum="<<sum()<<endl;
16
Defining a Member function outside the class(Example) Contd…
cout<<"Diff="<<diff()<<endl;
cout<<"Mul="<<mul()<<endl;
cout<<"Div="<<div()<<endl;
}
float sam::sum()
{
return(x+y);
}
float sam::diff()
{
return(x-y);
}
17
Defining a Member function outside the class(Example)
Contd…
float sam::mul()
{
return(x*y);
}
float sam::div()
{
return(x/y);
}
18
Defining a Member function outside the class(Example) Contd…
void main()
{
clrscr();
sam temp;
temp.get();
temp.disp();
temp.sum();
temp.diff();
temp.mul();
temp.div();
getch();
} 19
Access Specifiers
Private
• A member data can only be accessed by the member functions and friends of
this class.
• The member functions and friends of this class can always read or write private
data members.
• Private data members is not accessible to the outside world.
Public
• Can be accessed by any function in the outside world.
• Public implementation operations are also called member functions or methods
or interfaces to out of the class.
Protected
• Members can only be accessed by member functions and friends of this class.
• Not accessible to the outside world
20
A Access Specifiersccess Specifiers
PUBLIC PRIVATE PROTECTED
• Data members and • No one can access the • Makes class member
member functions class members declared inaccessible outside the
declared public can be private outside that class. class.
accessed by other classes • Compile time error • But they can be accessed
too by any subclass of that
class.
21/01/2025 19
Summary
22
Frequently Asked question
24
Assessment Questions:
1. Which among the following best describes member functions?
a) Functions which are defined within the class
b) Functions belonging a class
c) Functions in public access of a class
d) Functions which are private to class
2. A member function can _______________ of the same class.
a) Call other member functions
b) Call only private member functions
c) Call only static member functions
d) Call only const member functions
25
Assessment Questions:
26
Discussion forum.
How to Define inside and outside the class?
https://youtu.be/7VdrwIvu21c
27
REFERENCES
Reference Books:
Websites:
• https://www.studytonight.com/cpp/member-functions-cpp.php
• https://ecomputernotes.com/cpp/classes-in-c/defining-member-functi
ons
YouTube Links:
https://youtu.be/7VdrwIvu21c
28
THANK YOU