Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <fstream>
- using namespace std;
- class Interval{
- protected:
- double kezdo,veg;
- public:
- Interval(double a,double b);
- Interval();
- Interval(char * );
- void save(char*);
- void print();
- double length();
- };
- Interval::Interval(double a,double b){
- kezdo=a;
- veg=b;
- }
- double Interval::length(){
- return veg-kezdo;
- }
- void Interval::print(){
- cout<<"[ "<<kezdo<<" , "<<veg<<" ]";
- }
- Interval::Interval(char* file){
- ifstream ebbol;
- ebbol.open(file);
- ebbol.get();
- ebbol>>kezdo;
- ebbol.get();
- ebbol.get();
- ebbol>>veg;
- ebbol.get();
- ebbol.close();
- }
- void Interval::save(char* file){
- ofstream hova;
- hova.open(file);
- hova<<"( "<<kezdo<<" , "<<veg<<" )";
- hova.close();
- }
- Interval::Interval(){
- cout<<"Kérem add meg az intervalt: (";
- cin>>kezdo;
- cout<<" , ";
- cin>>veg;
- cout<<" )"<<endl;
- }
- class ColorInterval:public Interval{
- char* szin;
- public:
- ColorInterval(double,double,char*);
- void print();
- };
- ColorInterval::ColorInterval(double kezdo,double veg,char* szin):Interval(kezdo,veg){
- this->szin=szin;
- }
- void ColorInterval::print(){
- cout<<" [ "<<kezdo<<" , "<<veg<<" ] ( "<<szin<<" )";
- }
- int main(){
- /*ColorInterval ez(10,20,"piros");
- ez.print();*/
- ColorInterval *ci=new ColorInterval(10,20,"piros");
- ci->print();
- cout<<endl;
- ci->save("haha.txt");
- Interval *i=new Interval("haha.txt");
- //i->save("haha");
- i->print();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement