Program crashes, can't find issue.

When I run the program it immediately crashes, I have been looking over it but cannot seem to find the issue.

CircleType.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
#ifndef circleType_H
#define circleType_H


class circleType
{
     public:
            void setRadius(double r);
            double getRadius();
            double area();
            double circumference();
            circleType(double r = 0);
            
     private:
            double radius;
};

#endif 


circleType.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
#include <iostream>
#include "circleType.h"
using namespace std;

void circleType::setRadius(double r)
{
     radius = r;
}

double circleType::getRadius()
{
       return radius;
}

double circleType::area()
{
       return 3.1416 * radius * radius;
}

double circleType::circumference()
{
       return 2 * 3.1416 * radius;
}

circleType::circleType(double r)
{
       setRadius(r);
}


cylinderType.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
#ifndef cylinderType_H
#define cylinderType_H

#include "circleType.h"

class cylinderType: public circleType
{
      public:
            void setHeight(double h);
            double getHeight() const;
            double area();
            double Volume();
            cylinderType(double r = 1.0, double H = 1.0);
            
      private:
            double height;
            
};
 
#endif 


cylinderType.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
#include <iostream>
#include <cmath>
#include <iomanip>
#include <fstream>
#include "cylinderType.h"
using namespace std;
ofstream outdata;

cylinderType::cylinderType(double r, double h)
			 :circleType(r)
{
	height = h;
}

void cylinderType::setHeight(double h)
{
     height = h;
}

double cylinderType::getHeight() const
{
     return height;
}

double cylinderType::area()
{
     return (2 * area()) + (circumference() * height);
}

double cylinderType::Volume()
{
     return (height * 3.1416) * (getRadius() * getRadius());
}


Main
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
#include <iostream>
#include <fstream>
#include <iomanip>
#include "cylinderType.h"

using namespace std;

int main()
{
    cylinderType cylinder;
    double h, r, h1, r1;
    
    ifstream indata;
    ofstream outdata;
    
   indata.open("input.txt");
         if(not indata)
             {
                 cout << "Error cannot open file.";
                 return 1;
             }
             
         while(indata)
            {
                 indata >> r >> h;
            }     
             
            cylinder.setHeight(h);
            cylinder.setRadius(r);
            
             
             
    outdata.open("output.txt");
         if(not outdata)
             {
                 cout << "Error cannot open file.";
                 return 1;
             }
    
    
outdata << "RADIUS" << setw(3) << "HEIGHT" << setw(3) << "AREA" << setw(3) << "VOLUME" << endl; 
			             
    for(int i = 0; i<2; i++)
        {  
	outdata << cylinder.getRadius() << setw(3) << cylinder.getHeight() << setw(3) << cylinder.area() << setw(3) << cylinder.Volume() << endl;
	i++;
        }

indata.close(); outdata.close();        
return 0;
}
http://www.cplusplus.com/forum/general/112111/

1
2
3
4
5
double cylinderType::area()
{
     //return (2 * area()) + (circumference() * height); //infinite recursion
     return 2 * circleType::area() + circumference() * height;
}
Thanks! And I feel dumb I totally forgot about the debug utility! Brain fart moment! Thanks again!
Topic archived. No new replies allowed.