# Code problems (Composition and Arrays)

• (2 Pages)
• 1
• 2

## 26 Replies - 3611 Views - Last Post: 01 December 2010 - 08:22 AMRate Topic: //<![CDATA[ rating = new ipb.rating( 'topic_rate_', { url: 'http://www.dreamincode.net/forums/index.php?app=forums&module=ajax&section=topics&do=rateTopic&t=202918&amp;s=250b550a20b752f4265c3c376653b0dc&md5check=' + ipb.vars['secure_hash'], cur_rating: 0, rated: 0, allow_rate: 0, multi_rate: 1, show_rate_text: true } ); //]]>

### #1 protomanzero

• New D.I.C Head

Reputation: 0
• Posts: 37
• Joined: 09-November 10

# Code problems (Composition and Arrays)

Posted 30 November 2010 - 07:26 PM

Hello, I have this code here and it keeps generating errors and I cannot seem to find out what to do about them
```
#include<iostream>
#include<cmath>
#include<cstdlib>
using namespace std;

// This is a skeleton hw13.h file.  You must complete it.
// You are not allowed to modify the parts of the class
// definitions provided for you with the exception that you
// have to provide public member functions to allow the
// access that you need.

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;
}
int getheight()const{return height;}
int getwidth()const{return width;}
double getsteamTemp()const{return steamTemp;}
void setheight(int h = 0){height = h;}
void setwidth(int w = 0){width = w;}
void setsteamtemp(double temp = 0){steamTemp = temp;}

// Access function definitions

};

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

void setTemperature(double temp = 0){temperature = temp;}
void setSymbol(char symb = '?'){symbol = symb;}

// Access function definitions

};

class Fin
{               //line 61
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:

double getboundaryTemp() const {return boundaryTemp;}
int getwidth()const{return width;}
int getheight()const{return height;}
int getpipeX()const{return pipeLocationX;}
int getpipeY()const{return pipeLocationY;}
void initialize(const Fin& F); // YOU MUST DEFINE
void setFwidth(int w = 0){width = w;}
void setFheight(int h = 0){height = h;}
void setPx(int x = 0){pipeLocationX = x;}
void setPy(int y = 0){pipeLocationY = y;}
void setFtemp(double temp = 0){boundaryTemp = temp;}

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

};

void Fin::initialize(const Fin& F)

{
//------SETS BOUNDARY OF FIN TEMP AND CHAR-------
for(int i = height - 1, int j = 0; j < width; j++)
{
F.GridArray[i][j].setTemperature(boundaryTemp);
char symb = 'C';
F.GridArray[i][j].setSymbol(symb);
}
for(int i = 0, int j = 0; j < width; j++)
{
F.GridArray[i][j].setTemperature(boundaryTemp);
char symb = 'C';
F.GridArray[i][j].setSymbol(symb);
}
for(int j = 0, int i = 0; i < height; i++)
{
F.GridArray[i][j].setTemperature(boundaryTemp);
char symb = 'C';
F.GridArray[i][j].setSymbol(symb);
}
for(int j = width - 1, int i = 0; i < height; i++)
{
F.GridArray[i][j].setTemperature(boundaryTemp);
char symb = 'C';
F.GridArray[i][j].setSymbol(symb);
}
//-------------------------------------------------

//------SETS PIPE TEMP AND CHAR--------------------
for(int i = height - 1 - pipeLocationY; i > height - 1 - pipeLocationY - F.Pipe.height; i--)
{
for(int j = pipeLocationX; j < F.Pipe.width + pipeLocationX; j++)
{
F.GridArray[i][j].setTemperature(F.Pipe.steamTemp);
char symb = 'H';
F.GridArray[i][j].setSymbol(symb);
}
}
}

```

Here are the errors it is giving me
```1>c:\users\zach\documents\visual studio 2010\projects\hw13\hw13\hw13.h(93): error C2062: type 'int' unexpected
1>c:\users\zach\documents\visual studio 2010\projects\hw13\hw13\hw13.h(93): error C2065: 'j' : undeclared identifier
1>c:\users\zach\documents\visual studio 2010\projects\hw13\hw13\hw13.h(93): error C2065: 'j' : undeclared identifier
1>c:\users\zach\documents\visual studio 2010\projects\hw13\hw13\hw13.h(93): error C2143: syntax error : missing ';' before ')'
1>c:\users\zach\documents\visual studio 2010\projects\hw13\hw13\hw13.h(93): error C2143: syntax error : missing ';' before ')'
1>c:\users\zach\documents\visual studio 2010\projects\hw13\hw13\hw13.h(94): error C2143: syntax error : missing ';' before '{'
1>c:\users\zach\documents\visual studio 2010\projects\hw13\hw13\hw13.h(95): error C2065: 'j' : undeclared identifier
1>c:\users\zach\documents\visual studio 2010\projects\hw13\hw13\hw13.h(95): error C2228: left of '.setTemperature' must have class/struct/union
1>c:\users\zach\documents\visual studio 2010\projects\hw13\hw13\hw13.h(97): error C2065: 'j' : undeclared identifier
1>c:\users\zach\documents\visual studio 2010\projects\hw13\hw13\hw13.h(97): error C2228: left of '.setSymbol' must have class/struct/union
1>c:\users\zach\documents\visual studio 2010\projects\hw13\hw13\hw13.h(99): error C2062: type 'int' unexpected
1>c:\users\zach\documents\visual studio 2010\projects\hw13\hw13\hw13.h(99): error C2065: 'j' : undeclared identifier
1>c:\users\zach\documents\visual studio 2010\projects\hw13\hw13\hw13.h(99): error C2065: 'j' : undeclared identifier
1>c:\users\zach\documents\visual studio 2010\projects\hw13\hw13\hw13.h(99): error C2143: syntax error : missing ';' before ')'
1>c:\users\zach\documents\visual studio 2010\projects\hw13\hw13\hw13.h(99): error C2143: syntax error : missing ';' before ')'
1>c:\users\zach\documents\visual studio 2010\projects\hw13\hw13\hw13.h(100): error C2143: syntax error : missing ';' before '{'
1>c:\users\zach\documents\visual studio 2010\projects\hw13\hw13\hw13.h(101): error C2065: 'j' : undeclared identifier
1>c:\users\zach\documents\visual studio 2010\projects\hw13\hw13\hw13.h(101): error C2228: left of '.setTemperature' must have class/struct/union
1>c:\users\zach\documents\visual studio 2010\projects\hw13\hw13\hw13.h(103): error C2065: 'j' : undeclared identifier
1>c:\users\zach\documents\visual studio 2010\projects\hw13\hw13\hw13.h(103): error C2228: left of '.setSymbol' must have class/struct/union
1>c:\users\zach\documents\visual studio 2010\projects\hw13\hw13\hw13.h(105): error C2062: type 'int' unexpected
1>c:\users\zach\documents\visual studio 2010\projects\hw13\hw13\hw13.h(105): warning C4552: '<' : operator has no effect; expected operator with side-effect
1>c:\users\zach\documents\visual studio 2010\projects\hw13\hw13\hw13.h(105): error C2143: syntax error : missing ';' before ')'
1>c:\users\zach\documents\visual studio 2010\projects\hw13\hw13\hw13.h(105): error C2143: syntax error : missing ';' before ')'
1>c:\users\zach\documents\visual studio 2010\projects\hw13\hw13\hw13.h(106): error C2143: syntax error : missing ';' before '{'
1>c:\users\zach\documents\visual studio 2010\projects\hw13\hw13\hw13.h(107): error C2662: 'GridPt::setTemperature' : cannot convert 'this' pointer from 'const GridPt' to 'GridPt &'
1>          Conversion loses qualifiers
1>c:\users\zach\documents\visual studio 2010\projects\hw13\hw13\hw13.h(109): error C2662: 'GridPt::setSymbol' : cannot convert 'this' pointer from 'const GridPt' to 'GridPt &'
1>          Conversion loses qualifiers
1>c:\users\zach\documents\visual studio 2010\projects\hw13\hw13\hw13.h(111): error C2062: type 'int' unexpected
1>c:\users\zach\documents\visual studio 2010\projects\hw13\hw13\hw13.h(111): warning C4552: '<' : operator has no effect; expected operator with side-effect
1>c:\users\zach\documents\visual studio 2010\projects\hw13\hw13\hw13.h(111): error C2143: syntax error : missing ';' before ')'
1>c:\users\zach\documents\visual studio 2010\projects\hw13\hw13\hw13.h(111): error C2143: syntax error : missing ';' before ')'
1>c:\users\zach\documents\visual studio 2010\projects\hw13\hw13\hw13.h(112): error C2143: syntax error : missing ';' before '{'
1>c:\users\zach\documents\visual studio 2010\projects\hw13\hw13\hw13.h(113): error C2662: 'GridPt::setTemperature' : cannot convert 'this' pointer from 'const GridPt' to 'GridPt &'
1>          Conversion loses qualifiers
1>c:\users\zach\documents\visual studio 2010\projects\hw13\hw13\hw13.h(115): error C2662: 'GridPt::setSymbol' : cannot convert 'this' pointer from 'const GridPt' to 'GridPt &'
1>          Conversion loses qualifiers
1>c:\users\zach\documents\visual studio 2010\projects\hw13\hw13\hw13.h(120): error C2248: 'Steampipe::height' : cannot access private member declared in class 'Steampipe'
1>          c:\users\zach\documents\visual studio 2010\projects\hw13\hw13\hw13.h(19) : see declaration of 'Steampipe::height'
1>          c:\users\zach\documents\visual studio 2010\projects\hw13\hw13\hw13.h(17) : see declaration of 'Steampipe'
1>c:\users\zach\documents\visual studio 2010\projects\hw13\hw13\hw13.h(122): error C2248: 'Steampipe::width' : cannot access private member declared in class 'Steampipe'
1>          c:\users\zach\documents\visual studio 2010\projects\hw13\hw13\hw13.h(19) : see declaration of 'Steampipe::width'
1>          c:\users\zach\documents\visual studio 2010\projects\hw13\hw13\hw13.h(17) : see declaration of 'Steampipe'
1>c:\users\zach\documents\visual studio 2010\projects\hw13\hw13\hw13.h(124): error C2248: 'Steampipe::steamTemp' : cannot access private member declared in class 'Steampipe'
1>          c:\users\zach\documents\visual studio 2010\projects\hw13\hw13\hw13.h(20) : see declaration of 'Steampipe::steamTemp'
1>          c:\users\zach\documents\visual studio 2010\projects\hw13\hw13\hw13.h(17) : see declaration of 'Steampipe'
1>c:\users\zach\documents\visual studio 2010\projects\hw13\hw13\hw13.h(124): error C2662: 'GridPt::setTemperature' : cannot convert 'this' pointer from 'const GridPt' to 'GridPt &'
1>          Conversion loses qualifiers
1>c:\users\zach\documents\visual studio 2010\projects\hw13\hw13\hw13.h(126): error C2662: 'GridPt::setSymbol' : cannot convert 'this' pointer from 'const GridPt' to 'GridPt &'
1>          Conversion loses qualifiers

```

Is This A Good Question/Topic? 0

## Replies To: Code problems (Composition and Arrays)

### #2 anonymous26

• D.I.C Lover

Reputation: 1
• Posts: 3,638
• Joined: 26-November 10

## Re: Code problems (Composition and Arrays)

Posted 30 November 2010 - 07:52 PM

Have you ever heard of the 'ripple effect'? It's when one major error causes the compiler to effectively get confused and assume otherwise correct code it incorrect. Here is one of your culprits:

```...
for(int i = height - 1, int j = 0; j < width; j++)
...

```

You can't do the above with int i = height - 1, int j = 0; - that isn't valid C++. You need to remove the second 'declaration'.

```...
for(int i = height - 1, j = 0; j < width; j++)
...

```

I'll leave you to sort out the rest.

This post has been edited by ButchDean: 30 November 2010 - 07:52 PM

### #3 protomanzero

• New D.I.C Head

Reputation: 0
• Posts: 37
• Joined: 09-November 10

## Re: Code problems (Composition and Arrays)

Posted 30 November 2010 - 08:03 PM

Ah that eliminated a good chunk of my errors! I am still pretty confused on what is causing
```1>c:\users\zach\documents\visual studio 2010\projects\hw13\hw13\hw13.h(95): error C2662: 'GridPt::setTemperature' : cannot convert 'this' pointer from 'const GridPt' to 'GridPt &'
1>          Conversion loses qualifiers
1>c:\users\zach\documents\visual studio 2010\projects\hw13\hw13\hw13.h(97): error C2662: 'GridPt::setSymbol' : cannot convert 'this' pointer from 'const GridPt' to 'GridPt &'
1>          Conversion loses qualifiers
1>c:\users\zach\documents\visual studio 2010\projects\hw13\hw13\hw13.h(101): error C2662: 'GridPt::setTemperature' : cannot convert 'this' pointer from 'const GridPt' to 'GridPt &'
1>          Conversion loses qualifiers
1>c:\users\zach\documents\visual studio 2010\projects\hw13\hw13\hw13.h(103): error C2662: 'GridPt::setSymbol' : cannot convert 'this' pointer from 'const GridPt' to 'GridPt &'
1>          Conversion loses qualifiers
1>c:\users\zach\documents\visual studio 2010\projects\hw13\hw13\hw13.h(107): error C2662: 'GridPt::setTemperature' : cannot convert 'this' pointer from 'const GridPt' to 'GridPt &'
1>          Conversion loses qualifiers
1>c:\users\zach\documents\visual studio 2010\projects\hw13\hw13\hw13.h(109): error C2662: 'GridPt::setSymbol' : cannot convert 'this' pointer from 'const GridPt' to 'GridPt &'
1>          Conversion loses qualifiers
1>c:\users\zach\documents\visual studio 2010\projects\hw13\hw13\hw13.h(113): error C2662: 'GridPt::setTemperature' : cannot convert 'this' pointer from 'const GridPt' to 'GridPt &'
1>          Conversion loses qualifiers
1>c:\users\zach\documents\visual studio 2010\projects\hw13\hw13\hw13.h(115): error C2662: 'GridPt::setSymbol' : cannot convert 'this' pointer from 'const GridPt' to 'GridPt &'
1>          Conversion loses qualifiers
1>c:\users\zach\documents\visual studio 2010\projects\hw13\hw13\hw13.h(120): error C2248: 'Steampipe::height' : cannot access private member declared in class 'Steampipe'
1>          c:\users\zach\documents\visual studio 2010\projects\hw13\hw13\hw13.h(19) : see declaration of 'Steampipe::height'
1>          c:\users\zach\documents\visual studio 2010\projects\hw13\hw13\hw13.h(17) : see declaration of 'Steampipe'
1>c:\users\zach\documents\visual studio 2010\projects\hw13\hw13\hw13.h(122): error C2248: 'Steampipe::width' : cannot access private member declared in class 'Steampipe'
1>          c:\users\zach\documents\visual studio 2010\projects\hw13\hw13\hw13.h(19) : see declaration of 'Steampipe::width'
1>          c:\users\zach\documents\visual studio 2010\projects\hw13\hw13\hw13.h(17) : see declaration of 'Steampipe'
1>c:\users\zach\documents\visual studio 2010\projects\hw13\hw13\hw13.h(124): error C2248: 'Steampipe::steamTemp' : cannot access private member declared in class 'Steampipe'
1>          c:\users\zach\documents\visual studio 2010\projects\hw13\hw13\hw13.h(20) : see declaration of 'Steampipe::steamTemp'
1>          c:\users\zach\documents\visual studio 2010\projects\hw13\hw13\hw13.h(17) : see declaration of 'Steampipe'
1>c:\users\zach\documents\visual studio 2010\projects\hw13\hw13\hw13.h(124): error C2662: 'GridPt::setTemperature' : cannot convert 'this' pointer from 'const GridPt' to 'GridPt &'
1>          Conversion loses qualifiers
1>c:\users\zach\documents\visual studio 2010\projects\hw13\hw13\hw13.h(126): error C2662: 'GridPt::setSymbol' : cannot convert 'this' pointer from 'const GridPt' to 'GridPt &'
1>          Conversion loses qualifiers

```

### #4 anonymous26

• D.I.C Lover

Reputation: 1
• Posts: 3,638
• Joined: 26-November 10

## Re: Code problems (Composition and Arrays)

Posted 30 November 2010 - 08:15 PM

I'm about to go to bed now, but I'm guess your remaining trouble are because you haven't overloaded your array subscripts for your classes operator[]() which is a topic for tomorrow.

Good luck.

### #5 jimblumberg

Reputation: 4734
• Posts: 14,761
• Joined: 25-December 09

## Re: Code problems (Composition and Arrays)

Posted 30 November 2010 - 09:14 PM

Because of the number of errors I would comment out all but one section of your code and get that one section to compile without warnings/errors then add another small section of code and work on that section until it too compiles without errors/warnings. Continue until no more errors.

This section seems to be what you are working on:

```void Fin::initialize(const Fin& F)

{
//------SETS BOUNDARY OF FIN TEMP AND CHAR-------
for(int i = height - 1, int j = 0; j < width; j++)
{
F.GridArray[i][j].setTemperature(boundaryTemp);
char symb = 'C';
F.GridArray[i][j].setSymbol(symb);
}
for(int i = 0, int j = 0; j < width; j++)
{
F.GridArray[i][j].setTemperature(boundaryTemp);
char symb = 'C';
F.GridArray[i][j].setSymbol(symb);
}
for(int j = 0, int i = 0; i < height; i++)
{
F.GridArray[i][j].setTemperature(boundaryTemp);
char symb = 'C';
F.GridArray[i][j].setSymbol(symb);
}
for(int j = width - 1, int i = 0; i < height; i++)
{
F.GridArray[i][j].setTemperature(boundaryTemp);
char symb = 'C';
F.GridArray[i][j].setSymbol(symb);
}
//-------------------------------------------------

//------SETS PIPE TEMP AND CHAR--------------------
for(int i = height - 1 - pipeLocationY; i > height - 1 - pipeLocationY - F.Pipe.height; i--)
{
for(int j = pipeLocationX; j < F.Pipe.width + pipeLocationX; j++)
{
F.GridArray[i][j].setTemperature(F.Pipe.steamTemp);
char symb = 'H';
F.GridArray[i][j].setSymbol(symb);
}
}
}

```

So I would start by commenting out everything in this function and compiling.

```void Fin::initialize(const Fin& F)

{
/*
//------SETS BOUNDARY OF FIN TEMP AND CHAR-------
for(int i = height - 1, int j = 0; j < width; j++)
{
F.GridArray[i][j].setTemperature(boundaryTemp);
char symb = 'C';
F.GridArray[i][j].setSymbol(symb);
}
for(int i = 0, int j = 0; j < width; j++)
{
F.GridArray[i][j].setTemperature(boundaryTemp);
char symb = 'C';
F.GridArray[i][j].setSymbol(symb);
}
for(int j = 0, int i = 0; i < height; i++)
{
F.GridArray[i][j].setTemperature(boundaryTemp);
char symb = 'C';
F.GridArray[i][j].setSymbol(symb);
}
for(int j = width - 1, int i = 0; i < height; i++)
{
F.GridArray[i][j].setTemperature(boundaryTemp);
char symb = 'C';
F.GridArray[i][j].setSymbol(symb);
}
//-------------------------------------------------

//------SETS PIPE TEMP AND CHAR--------------------
for(int i = height - 1 - pipeLocationY; i > height - 1 - pipeLocationY - F.Pipe.height; i--)
{
for(int j = pipeLocationX; j < F.Pipe.width + pipeLocationX; j++)
{
F.GridArray[i][j].setTemperature(F.Pipe.steamTemp);
char symb = 'H';
F.GridArray[i][j].setSymbol(symb);
}
}
*/
}

```

Now does the code compile without errors/warnings?

If so add in the code for the first for loop and recompile.

Same question as above.

Jim

This post has been edited by jimblumberg: 30 November 2010 - 09:17 PM

### #6 protomanzero

• New D.I.C Head

Reputation: 0
• Posts: 37
• Joined: 09-November 10

## Re: Code problems (Composition and Arrays)

Posted 30 November 2010 - 09:46 PM

The code gave me the following errors when I commented out where you showed me
```1>c:\users\zach\documents\visual studio 2010\projects\hw13\hw13\hw13.cpp(39): error C4716: 'operator>>' : must return a value
1>c:\users\zach\documents\visual studio 2010\projects\hw13\hw13\hw13.cpp(50): error C4716: 'operator<<' : must return a value

```

### #7 jimblumberg

Reputation: 4734
• Posts: 14,761
• Joined: 25-December 09

## Re: Code problems (Composition and Arrays)

Posted 30 November 2010 - 09:49 PM

Please post the code for hw13.cpp.

Jim

### #8 protomanzero

• New D.I.C Head

Reputation: 0
• Posts: 37
• Joined: 09-November 10

## Re: Code problems (Composition and Arrays)

Posted 30 November 2010 - 09:58 PM

```
#include <iostream>
#include <fstream>
#include <iomanip>
#include <string>
#include "hw13.h"
using namespace std;

istream& operator>>(istream& in, Fin& F)
{
char trash;
int fHeight, fWidth, pHeight, pWidth, pX, pY;
double sTemp, fTemp;
cout << "Enter the height of the fin (integer) >>> ";
in >> fHeight;
F.setFheight(fHeight);

cout << "Enter the width of the fin (integer) >>> ";
in >> fWidth;
F.setFwidth(fWidth);

cout << "Enter the height of the steampipe (integer) >>> ";
in >> pHeight;
F.Pipe.setheight(pHeight);

cout << "Enter the width of the steampipe (integer) >>> ";
in >> pWidth;
F.Pipe.setwidth(pWidth);

cout << "Enter integer coordinates of lower left corner of the steampipe (X,Y) >>> ";
in >> pX >> trash >> pY;
F.setPx(pX);
F.setPy(pY);

cout << "Enter the steam temperature (floating point) >>> ";
in >> sTemp;
F.Pipe.setsteamtemp(sTemp);

cout << "Enter the temperature around the fin (floating point) >>> ";
in >> fTemp;
F.setFtemp(fTemp);
}

ostream& operator<<(ostream& out, const Fin& F)
{
cout << "The width of the fin is " << F.getwidth() << endl;
cout << "The height of the fin is " << F.getheight() << endl;
cout << "The outside temperature is " << F.getboundaryTemp() << endl;
cout << "The lower left corner of the steam pipe is at (" << F.getpipeX() << ", " << F.getpipeY() << ")" << endl;
cout << "The steam pipe width is " << F.Pipe.getwidth() << endl;
cout << "The steam pipe height is " << F.Pipe.getheight() << endl;
cout << "The temperature of the steam is " << F.Pipe.getsteamTemp() << endl << endl;
}

```

### #9 jimblumberg

Reputation: 4734
• Posts: 14,761
• Joined: 25-December 09

## Re: Code problems (Composition and Arrays)

Posted 30 November 2010 - 10:03 PM

Quote

1>c:\users\zach\documents\visual studio 2010\projects\hw13\hw13\hw13.cpp(39): error C4716: 'operator>>' : must return a value

Ok so can you tell me by looking at the above error message what is wrong?

What line does the compiler say is the problem?

Jim

### #10 protomanzero

• New D.I.C Head

Reputation: 0
• Posts: 37
• Joined: 09-November 10

## Re: Code problems (Composition and Arrays)

Posted 30 November 2010 - 10:23 PM

I dont know what to set it to return to I assumed istream& and ostream& respectively.

### #11 jimblumberg

Reputation: 4734
• Posts: 14,761
• Joined: 25-December 09

## Re: Code problems (Composition and Arrays)

Posted 30 November 2010 - 10:27 PM

That is correct. Now in the code do you see any ifstream& or ofstream& that you might be able to return? (hint look at you function prototype).

Quote

istream& operator>>(istream& in, Fin& F)

Jim

This post has been edited by jimblumberg: 30 November 2010 - 10:28 PM

### #12 protomanzero

• New D.I.C Head

Reputation: 0
• Posts: 37
• Joined: 09-November 10

## Re: Code problems (Composition and Arrays)

Posted 30 November 2010 - 10:38 PM

Now I have a little something like this
```#include <iostream>
#include <fstream>
#include <iomanip>
#include <string>
#include "hw13.h"
using namespace std;

int main()
{
istream& operator>>(istream& in, Fin& F)
{
char trash;
int fHeight, fWidth, pHeight, pWidth, pX, pY;
double sTemp, fTemp;
cout << "Enter the height of the fin (integer) >>> ";
in >> fHeight;
F.setFheight(fHeight);

cout << "Enter the width of the fin (integer) >>> ";
in >> fWidth;
F.setFwidth(fWidth);

cout << "Enter the height of the steampipe (integer) >>> ";
in >> pHeight;
F.Pipe.setheight(pHeight);

cout << "Enter the width of the steampipe (integer) >>> ";
in >> pWidth;
F.Pipe.setwidth(pWidth);

cout << "Enter integer coordinates of lower left corner of the steampipe (X,Y) >>> ";
in >> pX >> trash >> pY;
F.setPx(pX);
F.setPy(pY);

cout << "Enter the steam temperature (floating point) >>> ";
in >> sTemp;
F.Pipe.setsteamtemp(sTemp);

cout << "Enter the temperature around the fin (floating point) >>> ";
in >> fTemp;
F.setFtemp(fTemp);

return (in);
}

ostream& operator<<(ostream& out, const Fin& F)
{
cout << "The width of the fin is " << F.getwidth() << endl;
cout << "The height of the fin is " << F.getheight() << endl;
cout << "The outside temperature is " << F.getboundaryTemp() << endl;
cout << "The lower left corner of the steam pipe is at (" << F.getpipeX() << ", " << F.getpipeY() << ")" << endl;
cout << "The steam pipe width is " << F.Pipe.getwidth() << endl;
cout << "The steam pipe height is " << F.Pipe.getheight() << endl;
cout << "The temperature of the steam is " << F.Pipe.getsteamTemp() << endl << endl;

return (out);
}
}

```

This is giving me the error
```1>MSVCRTD.lib(crtexe.obj) : error LNK2019: unresolved external symbol _main referenced in function ___tmainCRTStartup
1>C:\Users\Zach\Documents\Visual Studio 2010\Projects\hw13\Debug\hw13.exe : fatal error LNK1120: 1 unresolved externals

```

### #13 jimblumberg

Reputation: 4734
• Posts: 14,761
• Joined: 25-December 09

## Re: Code problems (Composition and Arrays)

Posted 30 November 2010 - 10:45 PM

You are trying to implement the two functions inside of main(). That's a no-no.

For now you could just have:

```int main()
{
return 0;
}

// Your two functions here.

```

Jim

This post has been edited by jimblumberg: 30 November 2010 - 10:45 PM

### #14 protomanzero

• New D.I.C Head

Reputation: 0
• Posts: 37
• Joined: 09-November 10

## Re: Code problems (Composition and Arrays)

Posted 30 November 2010 - 10:48 PM

Haha whew after all that the code did run with no errors, all of that code in the header file is still commented out however so what should I do to resolve that issue?

### #15 jimblumberg

Reputation: 4734
• Posts: 14,761
• Joined: 25-December 09

## Re: Code problems (Composition and Arrays)

Posted 30 November 2010 - 10:52 PM

Now take one small chunk of the code in the header file and uncomment it, recompile, try to analyze the error messages to fix them. I would start with just one of your for loops.

If you can't understand the error messages, post them along with the modified code.

Jim

This post has been edited by jimblumberg: 30 November 2010 - 10:53 PM