Toubleshooting Array

Hey all,

I'm solving this problem for a college programming class. I'm having trouble getting the array to output correctly.


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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
#include<iostream>
#include<cmath>
#include<cstdlib>

using namespace std;

const int maxFinHeight = 100;
const int maxFinWidth = 100;

class Steampipe
{
private:
	int height, width;
	double steamTemp;
public:
	Steampipe (int H = 0, int W = 0, double sT = 0.0)
	{
		height = H;
		width = W;
		steamTemp = sT;
	}

	// Access function definitions
	int get_width()const{return width;};
	int get_height()const{return height;};
	double get_steamTemp()const{return steamTemp;};
	void set_width(int dummysteamwidth) {width = dummysteamwidth;};
	void set_height(int dummysteamheight){height = dummysteamheight;};
	void set_steamTemp(double dummysteamtemp){steamTemp = dummysteamtemp;};

	// Access function definitions
	friend istream& operator>>(istream& , Steampipe& ); // YOU MUST DEFINE
	friend ostream& operator<<(ostream& , const Steampipe& ); // YOU MUST DEFINE
	
};


class GridPt
{
private:
	double temperature;
	char symbol;
public:
	GridPt(double t = 0.0, char s = '?')
	{
		temperature = t;
		symbol = s;
	}

	// Access function definitions
	double get_temperature()const{return temperature;}
	double get_symbol()const{return symbol;}
	void set_t(int dummyt){temperature = dummyt;}
	void set_s(int dummys){symbol = dummys;}

	friend istream& operator>>(istream& , GridPt& ); // YOU MUST DEFINE
	friend ostream& operator<<(ostream& , const GridPt& ); // YOU MUST DEFINE

};

class Fin
{
private:
	int width, height; //width and height of fin
	int pipeLocationX, pipeLocationY; //grid location of lower left corner of steampipe
	double boundaryTemp; //temperature of fin surroundings
	Steampipe Pipe; //steampipe object - COMPOSITION
	GridPt GridArray[maxFinHeight][maxFinWidth]; // array of GridPts - COMPOSITION
public:


	int get_width()const{return width;}
	int get_height()const{return height;}
	int get_pipeLocationX()const{return pipeLocationX;}
	int get_pipeLocationY()const{return pipeLocationX;}
	double get_boundarytemp()const{return boundaryTemp;}

	friend istream& operator>>(istream& , Fin& ); // YOU MUST DEFINE
	friend ostream& operator<<(ostream& , const Fin& ); // YOU MUST DEFINE

	void initialize(); // YOU MUST DEFINE

		
};

void Fin::initialize()
{
	for (int i = 0; i <= (height - 1); i++)
	{
		for (int j = 0; j <= (width - 1); j++)
		{
			if (j == pipeLocationX && i == pipeLocationY 
				&& i < Pipe.get_height() + pipeLocationY && j < Pipe.get_width() + pipeLocationX)
			{
				GridArray [j][i].set_t(Pipe.get_steamTemp());
				GridArray [j][i].set_s('H');
			}
			else if (j == (width -1) || i == (height -1) || j == 0 || i == 0)
			{
				GridArray [j][i].set_t(boundaryTemp);
				GridArray [j][i].set_s('C');
			}
			else
			{
				GridArray [j][i].set_t((Pipe.get_steamTemp() + boundaryTemp)/2);
				GridArray [j][i].set_s('X');
			}

		}
	}
}

istream &operator >> (istream & in, Fin& data)
{
	int   dummysteamwidth = 0, dummysteamheight = 0; 
	double  dummysteamtemp = 0, dummyboundarytemp = 0;
	char comma;

	cout << "Enter the height of the fin (integer) >>> ";
	in >> data.height;

	cout << "Enter the width of the fin (integer) >>> " ;
	in >> data.width;

	cout << "Enter the height of the streampipe (integer) >>> ";
	in >> dummysteamheight;

	cout << "Enter the width of the steampipe (integer) >>> ";
	in >> dummysteamwidth;

	cout << "Enter coordinates of lower left corner of steampipe (X,Y) >>> ";
	in >> data.pipeLocationX >> comma >> data.pipeLocationY;

	cout << "Enter the steam temperature (floating point) >>> ";
	in >> dummysteamtemp;

	cout << "Enter the temperature around the fin (floating point) >>> "; 
	in >> data.boundaryTemp;

	data.Pipe.set_height(dummysteamheight);
	data.Pipe.set_width(dummysteamwidth);
	data.Pipe.set_steamTemp(dummysteamtemp);

	return in;
}

ostream &operator << (ostream &stream, const Fin& data2)
{
	int i = 0;
	int j = 0;

	stream << "The width of the fin is " << data2.width << endl;

	stream << "The height of the fin is " << data2.height << endl;

	stream << "The outside temperature is " << data2.boundaryTemp << endl;

	stream << "The lower left corner of the steam pipe is at " << data2.pipeLocationX << "," << data2.pipeLocationY << endl;

	stream << "The steampipe width is " << data2.Pipe.get_width() << endl;

	stream << "the steampipe height is " << data2.Pipe.get_height() << endl;

	stream << "The temperature of the steam is " << data2.Pipe.get_steamTemp() << endl;

	for (i = 0; i <= (data2.height - 1); i++)
	{
		for (j = 0; j <= (data2.width - 1); j++)
		{
			stream << data2.GridArray[j][i].get_symbol();
		}

		stream << endl;
	}
		

	//stream << β€œThe temperature of location β€œ <<(whatever)<< β€œ is β€œ<<whatever.

	return stream;
}


The output should look like this:

CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC
CXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXC
CXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXC
CXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXC
CXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXC
CXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXC
CXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXC
CXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXC
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CCCCCCCCCCCC


Any help you can offer would be outstanding.
Last edited on
Your program has no main method!
1
2
3
4
5
int main()
{
//	Your classes and objects and programming logic here as this is the point which executes.
	return 0;
}

Sorry, I should have mentioned it was a .h file, with a source code that calls it! the main function is in the source file
Please include it here also.
Here ya go:

1
2
3
4
5
6
7
8
9
10
#include "hw13.h"

int main()
{
	Fin one; 
	cin >> one;
	one.initialize();
	cout << one;
	return 0;
}
Last edited on
Topic archived. No new replies allowed.