Lecture 3-DS
Lecture 3-DS
𝑓(𝑖)
𝑖=𝑛
𝑓 𝑖 = 2𝑖 + 6
// pointer to function
#include<iostream>
#include<cmath>
using namespace std;
double f(double x){
return 2*x+6;
}
double sum(double (*f)(double),int n, int m)
{
double result=0;
for(int i=n;i <=m; i++){
result=result+f(i);
cout<<result<<endl;
}
return result;
}
int main(){
cout<<sum(f,3,5);
}
Templates
Initialize genType:
Example
Inheritance
BseClass
Derived1_Level1 Derived2_Level1
Multiple
inheritance
Derived_Level2
Inheritance
Base Class
Inheritance
Derived level 1
Derived2 level 1
Inheritance
Derived level 2
Main function
output
Inheritance
• Hierarchy of classes
• ParentClass/BaseClass,SuperClass
• ChildClass/DrivedClass
• BaseClass can decide which member
functions and data members can be
revealed to derived classes
Derived class can decide which parts of the public and
protected member functions and data members to retain and
use and which to modify