- Every hard Disk has a capacity and Partition
- Every CD has capacity ,title and writeable or not
- Every DVD has capacity ,title
Use Inheritance Each class should have constructor and overload operator for every class.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#__Author__ Simulation Hub | |
#include<iostream> | |
using namespace std; | |
class Medium | |
{ | |
protected: | |
int capacity=0; | |
public: | |
Medium(int _capacity):capacity{_capacity}{} | |
friend ostream & operator <<(ostream & out,const Medium & m); | |
}; | |
ostream& operator <<(ostream &out,const Medium &m)// friend function not call by :: operator | |
{ | |
out<<"Capactiy of medium :"<<m.capacity<<endl; | |
return out; | |
} | |
class HardDisk:public Medium | |
{ | |
protected: | |
int NumOfPartition; | |
public: | |
HardDisk(int _capactiy,int n):Medium(_capactiy) | |
{ | |
NumOfPartition=n; | |
} | |
friend ostream& operator<<(ostream & out,HardDisk & hd); | |
}; | |
ostream& operator<<(ostream & out,HardDisk & hd) | |
{ | |
out<<"Capacity : "<<hd.capacity<<" Number of Partition :"<<hd.NumOfPartition<<endl; | |
return out; | |
} | |
class Optical_disk:public Medium | |
{ | |
protected: | |
string title; | |
public: | |
Optical_disk(string t,int cap):Medium(cap) | |
{ | |
title=t; | |
} | |
friend ostream& operator<<(ostream & out,Optical_disk & od); | |
}; | |
ostream& operator<<(ostream & out,Optical_disk & od) | |
{ | |
out<<"Title :"<<od.title<<"Capacatiy :"<<od.capacity<<endl; | |
return out; | |
} | |
class CD:public Optical_disk | |
{ | |
protected: | |
bool writeable=false; | |
public: | |
CD(int cap,string t,bool l):Optical_disk(t,cap) | |
{ | |
writeable=l; | |
} | |
friend ostream& operator<<(ostream & out,CD & c); | |
}; | |
ostream& operator<<(ostream & out,CD & c) | |
{ | |
out<<"Capacity :"<<c.capacity<<" Titke : "<<c.title<<" Writetable "<<c.writeable<<endl; | |
return out; | |
} | |
class DVD:public Optical_disk | |
{ | |
public: | |
DVD(string t,int capactiy):Optical_disk(t,capactiy) | |
{ | |
} | |
friend ostream& operator<<(ostream & out,DVD & c); | |
}; | |
ostream& operator<<(ostream & out,DVD & c) | |
{ | |
out<<"Capacity :"<<c.capacity<<" Title : "<<c.title<<endl; | |
return out; | |
} | |
int main() | |
{ | |
Medium m(100); | |
cout<<m; | |
HardDisk h(100,2); | |
cout<<h; | |
CD cd(1000,"Movie",true); | |
cout<<cd; | |
DVD dvd("Movie",100); | |
cout<< dvd; | |
return 0; | |
} |
Capactiy of medium :100 Capacity : 100 Number of Partition :2 Capacity :1000 Titke : Movie Writetable 1 Capacity :100 Title : Movie
0 Comments
If you have any doubt and suggestion Please let me know