c++ assignment no.4-1
c++ assignment no.4-1
Program No : 01 A
Name : Ghanashyam Basaveshwar Kumbhar.
Class :BCA-II. Roll No: 59
Program Name: : Write a C ++ program to demonstrate compile time polymorphism
using:- A) function overloading
B) operator overloading
-------------------------------------------------------------------------------------------------------
Program Code:
A) Function overloading :-
#include<iostream>
using namespace std;
class Function{
public:
void fun(int x){
cout<<"This value is Integer... "<<x<<endl;
}
void fun(string x){
cout<<"This value is String..."<<x<<endl;
}
};
int main(){
Function F;
F.fun(07);
F.fun("WhyShyam");
return 0;
}
/*Output:
*/
-------------------------------------------------------------------------------------------------------
Program No : 01 A
Name : Pavan Dnyaneshwar Mali.
Class :BCA-II. Roll No: 60
Program Name: : Write a C ++ program to demonstrate compile time polymorphism
using:- A) function overloading
B) operator overloading
-------------------------------------------------------------------------------------------------------
Program Code:
A) Function overloading :-
#include<iostream>
using namespace std;
class Function{
public:
void fun(int x){
cout<<"This value is Integer... "<<x<<endl;
}
void fun(string x){
cout<<"This value is String..."<<x<<endl;
}
};
int main(){
Function F;
F.fun(07);
F.fun("WhyShyam");
return 0;
}
/*Output:
*/
-------------------------------------------------------------------------------------------------------
Program No : 01 B
Name : Ghanashyam Basaveshwar Kumbhar.
Class :BCA-II. Roll No: 59
Program Name: Write a C ++ program to demonstrate compile time polymorphism
using:- a) function overloading
b) operator overloading
-------------------------------------------------------------------------------------------------------
Program Code:
B) Operator overloading :-
#include<iostream>
using namespace std;
class Test{
private:
int num;
public:
Test():num(8){
}
void operator ++(){
num=num+2;
}
void print(){
cout<<"The count is : "<<num;
}
};
int main() {
Test t;
++t;
t.print();
return 0;
}
/*Output:
*/
-------------------------------------------------------------------------------------------------------
Program No : 02
Name : Ghanashyam Basaveshwar Kumbhar.
Class :BCA-II. Roll No: 59
Program Name: Write a C ++ program to demonstrate run time polymorphism using
virtual function.
-------------------------------------------------------------------------------------------------------
Program Code:
#include<iostream>
using namespace std;
class FC{
public:
virtual void display(){
cout<<"Which club is best?"<<endl;
}
};
class RM : public FC{
void display(){
cout<<"Real Madrid Is The Best Club In The World...";
}
};
int main(){
FC *f;
RM r;
f=&r;
f ->display();
return 0;
}
/*Output:
*/
-------------------------------------------------------------------------------------------------------
Program No : 03
Name : Ghanashyam Basaveshwar Kumbhar.
Class :BCA-II. Roll No: 59
Program Name: Write a C ++ program to demonstrate this pointer.
-------------------------------------------------------------------------------------------------------
Program Code:
#include<iostream>
using namespace std;
class Student{
private:
int Id;
string Name;
string Class;
public:
Student(int i,string n,string c){
Id = i;
Name = n;
Class = c;
}
void set(int i,string n,string c){
this->Id;
this->Name;
this->Class;
}
void display(){
cout<<"Student ID:"<<this->Id<<endl;
cout<<"Student NAME:"<<this->Name<<endl;
cout<<"Student CLASS:"<<this->Class<<endl;
cout<<"----------------------------------"<<endl;
}
};
int main(){
Student S(01,"Whyshyam","BCA-I");
Student S1(02,"Stillshyam","BCA-II");
Student S2(03,"Shyam","BCA-III");
S.display();
S1.display();
S2.display();
return 0;
}
/*Output:
jcj-bca-pc24@jcjbcapc24:~/whyshyam$ gedit thispointer.cpp
jcj-bca-pc24@jcjbcapc24:~/whyshyam$ g++ -o thispointer thispointer.cpp
jcj-bca-pc24@jcjbcapc24:~/whyshyam$ ./thispointer
Student ID:1
Student NAME:Whyshyam
Student CLASS:BCA-I
----------------------------------
Student ID:2
Student NAME:Stillshyam
Student CLASS:BCA-II
----------------------------------
Student ID:3
Student NAME:Shyam
Student CLASS:BCA-III
----------------------------------
*/
-------------------------------------------------------------------------------------------------------
Program No : 04
Name : Ghanashyam Basaveshwar Kumbhar.
Class :BCA-II. Roll No: 59
Program Name: Write a C ++ program to demonstrate pure virtual function.
-------------------------------------------------------------------------------------------------------
Program Code:
#include<iostream>
using namespace std;
class Shape{
public:
virtual void draw()=0;
};
class Circle:public Shape{
public:
void draw(){
cout<<"Drawing Circle....";
}
};
int main(){
Circle c;
c.draw();
return 0;
}
/*Output:
*/