Advertisement
szdani96

Untitled

Oct 15th, 2017
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.38 KB | None | 0 0
  1. #include <iostream>
  2. #include <fstream>
  3. using namespace std;
  4. class Interval{
  5. protected:
  6. double kezdo,veg;
  7. public:
  8. Interval(double a,double b);
  9. Interval();
  10. Interval(char * );
  11. void save(char*);
  12. void print();
  13. double length();
  14. };
  15. Interval::Interval(double a,double b){
  16. kezdo=a;
  17. veg=b;
  18.  
  19. }
  20. double Interval::length(){
  21. return veg-kezdo;
  22. }
  23. void Interval::print(){
  24. cout<<"[ "<<kezdo<<" , "<<veg<<" ]";
  25. }
  26. Interval::Interval(char* file){
  27. ifstream ebbol;
  28. ebbol.open(file);
  29. ebbol.get();
  30. ebbol>>kezdo;
  31. ebbol.get();
  32. ebbol.get();
  33. ebbol>>veg;
  34. ebbol.get();
  35. ebbol.close();
  36. }
  37. void Interval::save(char* file){
  38. ofstream hova;
  39. hova.open(file);
  40. hova<<"( "<<kezdo<<" , "<<veg<<" )";
  41. hova.close();
  42. }
  43. Interval::Interval(){
  44. cout<<"Kérem add meg az intervalt: (";
  45. cin>>kezdo;
  46. cout<<" , ";
  47. cin>>veg;
  48. cout<<" )"<<endl;
  49.  
  50. }
  51. class ColorInterval:public Interval{
  52.     char* szin;
  53.     public:
  54.     ColorInterval(double,double,char*);
  55.     void print();
  56. };
  57. ColorInterval::ColorInterval(double kezdo,double veg,char* szin):Interval(kezdo,veg){
  58.  
  59. this->szin=szin;
  60. }
  61. void ColorInterval::print(){
  62. cout<<" [ "<<kezdo<<" , "<<veg<<" ] ( "<<szin<<" )";
  63. }
  64. int main(){
  65. /*ColorInterval ez(10,20,"piros");
  66. ez.print();*/
  67. ColorInterval *ci=new ColorInterval(10,20,"piros");
  68. ci->print();
  69. cout<<endl;
  70. ci->save("haha.txt");
  71. Interval *i=new Interval("haha.txt");
  72. //i->save("haha");
  73.  
  74. i->print();
  75.  
  76. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement