Array

Pages: 1234
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

* CTempSensor.cpp
 *
 *  Created on: 23.06.2017
 *      Author: buergy
 */

#include "CTempSensor.h"
#include <iostream>		// Header fuer die Standard-IO-Objekte (z.B. cout, cin)
#include <cstdlib>      // fuer random values
#include <iomanip>      // fuer setw()
#include <string>


using namespace std;	// Erspart den scope vor Objekte der
						// C++-Standard-Bibliothek zu schreiben
						// z.B. statt "std::cout" kann man "cout" schreiben



CTempSensor::CTempSensor(float minTemp,float maxTemp)
{
	CTempSensor::retrieveLastMeasurements();
    m_minTemp = minTemp;

    m_maxTemp = maxTemp;



}

// generiert 24 Zufallswerte zw. 5 und 95 Grad [vorgegeben]
void CTempSensor::retrieveLastMeasurements()
{
	for (int i=0; i<24;i++) {
		m_last24hrsTemp[i] = (rand() % 900 + 50) / (float)10;
	}
}


// gibt min/max und die 24 Messwerte aus [vorgegeben]
void CTempSensor::print()
{
	cout << "min: " << m_minTemp << " | max: " << m_maxTemp << " | Letzte 24 Messwerte: ";

	for (int i=0; i<24;i++) {
		cout << setw(4) << m_last24hrsTemp[i] << " | " ;
	}
	cout << endl;

}


// gibt den Prozentsatz der Werte in der Range zurueck [gegeben fuer Aufgane 3c]
float CTempSensor::checkTempRange(float low, float high)
{
	int inRange = 0;
	int outOfRange = 0;

	for (int i=0; i<24;i++) {
		if (m_last24hrsTemp[i] < low || m_last24hrsTemp[i] > high) {
			outOfRange++;
		}
		else {
			inRange++;
		}
	}
	return 100*inRange/24.;
}



CTempSensor::~CTempSensor()
{
	// TODO Auto-generated destructor stub
}

 void CTempSensor::calculateMinMaxTemp(){

	m_minTemp = m_last24hrsTemp[0];
	m_maxTemp = m_last24hrsTemp[0];



	 for(int i = 1; i < 24 ; i++)
	 {
	     if(m_last24hrsTemp[i] > m_maxTemp)
	         m_maxTemp = m_last24hrsTemp[i];
	     if(m_last24hrsTemp[i] < m_minTemp)
	         m_minTemp = m_last24hrsTemp[i];
	 }


	 }





main.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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
#include <stdlib.h>

// TODO: Fuegen Sie hier weitere benoetigte Header-Dateien der
// Standard-Bibliothek ein z.B.
// #include <string>
#include <ctime>

using namespace std;	// Erspart den scope vor Objekte der
						// C++-Standard-Bibliothek zu schreiben
						// z.B. statt "std::cout" kann man "cout" schreiben

// Inkludieren Sie hier die Header-Files Ihrer Klassen, z.B.
// #include "CFraction.h"
#include "CTempSensor.h"


// Hauptprogramm
// Dient als Testrahmen, von hier aus werden die Klassen aufgerufen
int main (void)
{
    // fuer Zufallszahlen [vorgegeben]
	srand(time(0));


	// TODO: Fuegen Sie hier Ihren Namen & Ihre Matr.-Nr. ein.
	cout << "GIT-Exam gestartet." << endl << endl;
	cout << "Name: Max Mustermann, Matrikel-Nr.: 123456" << endl << endl;


    // TODO: Fuegen Sie ab hier Ihren Programmcode ein.

	CTempSensor test;

	test.print();







	// zum Testen fuer Aufgae 3 - Aufgabe 1 vorher loesen
	//cout << "Prozentsatz der Werte innerhalb 30 & 50: " << ts.checkTempRange(30., 50.) << endl;


	cout << endl << "Programm beendet" << endl;
	return 0;
}



The code is showing no errors now.

The next task is:
Test your previous implementation by creating a CTempSensor object in main.cpp and calling the existing print () method. You should then see in the console the min./max. Values and all 24 measured values - in the corresponding value range.




Is my test right in main?
You aren't actually calling calculateMinMaxTemp() anywhere at the moment.
Since its access is private you will have to either call it from within a member function or change the access to public.

You could just call it from within the constructor once you have populated values.

1
2
3
4
5
6
7
8
9
CTempSensor::CTempSensor(float minTemp,float maxTemp)
{
    retrieveLastMeasurements();

//  m_minTemp = minTemp;                        // No idea why you do this
//  m_maxTemp = maxTemp;

    calculateMinMaxTemp();        // <==== find minimum and maximum here
}


Then your code produces
GIT-Exam gestartet.

Name: Max Mustermann, Matrikel-Nr.: 123456

min: 8.9 | max: 87.5 | Letzte 24 Messwerte: 37.7 | 87.5 |   54 | 14.2 | 27.3 | 40.8 |   79 | 70.4 | 19.5 | 11.4 | 66.1 | 41.1 | 49.3 | 58.3 | 36.2 | 39.1 | 29.5 | 70.7 | 53.5 | 12.4 | 40.5 |  8.9 | 27.7 |   39 | 

Programm beendet




d) Add a private method double calculateMeanTemp () that returns the average temperature of the 24 metrics from m_last24hrsTemp [24].

My code:

1
2
3
4
5
6
7
8
9
10
11

double CTempSensor::calculateMeanTemp(){
	 double summe = 0;
	 for(int i = 0; i<24 ; i++){

		 summe += m_last24hrsTemp[i];
	 }
	 summe = (summe)/(2);


 }


Is it ok?

Can I test it also so?

CTempSensor::CTempSensor()
{
CTempSensor::retrieveLastMeasurements();


CTempSensor::calculateMinMaxTemp(); // <==== find minimum and maximum here
}

Or should I let the CTempSensor... away?
Last edited on
Lex33 wrote:
Is it ok?

No.
(a) You gave it a return type of double, but you fail to return anything. (Turn your compiler error messages up and it will tell you that.)
(b) Why are you dividing by 2 and not 24? (And why do you feel the need to surround ordinary numbers with brackets? It leads to diminishing readability.)

You can call it from main() as long as you make it public access.
Last edited on
1
2
3
4
5
6
7
8
9
10
11
12

double CTempSensor::calculateMeanTemp(){
	 double summe = 0;
	 for(int i = 0; i<24 ; i++){

		 summe += m_last24hrsTemp[i];
	 }
	 summe = (summe)/(24);
return summe;

 }



I think , that s it?


The next task is a little difficult:

I habe problem with task f)

d) Add a private method double calculateMeanTemp () that returns the average temperature of the 24 metrics from m_last24hrsTemp [24].
e) Declare a tSensorType enumeration that defines the following constants to later determine the nature of the sensor (for example, if the sensor measures water, oil, or air temperature):
GENERAL, WATER, OIL, AIR. Add an attribute m_sensorType of the type
tSensorType in class CTempSensor.
f) Implement a private method void generateSensorType (), which randomly assigns the value for the sensor type. Call this method in the constructor of the CTempSensor class
to assign a sensor type to each sensor.
Note 1: You can find the CTempSensor :: retrieveLastMeasurements () method
Example of how random numbers are generated.
Note 2: You need to think about how to turn numbers into tSensorType constants. Note 3: If you can not implement the method, initialize the m_sensorType attribute in the constructor with any allowed value.


My code :
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

#ifndef CTEMPSENSOR_H_
#define CTEMPSENSOR_H_

#include <iostream>


using namespace std;


enum tSensorType{GENERAL ,WATER , OIL , AIR};
class CTempSensor
{

private:
	float m_last24hrsTemp[24]; // array of last 24 measurements [vorgegeben]
	float m_minTemp;           // minimum Temp of last 24hrs [vorgegeben]
	float m_maxTemp;           // maximum Temp of last 24hrs [vorgegeben]
	void calculateMinMaxTemp();
	tSensorType m_sensorType;



public:
	CTempSensor(float minTemp = 0 , float maxTemp = 0);
	virtual ~CTempSensor();

	void retrieveLastMeasurements();  // erzeugt 24 Zufallswerte [vorgegeben]
	void print();                     // gibt die Messdaten aus [vorgegeben]
	float checkTempRange(float, float); // [vorgegeben]
	double calculateMeanTemp();


};

#endif /* CTEMPSENSOR_H_ */





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
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


/*
 * CTempSensor.cpp
 *
 *  Created on: 23.06.2017
 *      Author: buergy
 */

#include "CTempSensor.h"
#include <iostream>		// Header fuer die Standard-IO-Objekte (z.B. cout, cin)
#include <cstdlib>      // fuer random values
#include <iomanip>      // fuer setw()
#include <string>
#include<cmath>


using namespace std;	// Erspart den scope vor Objekte der
						// C++-Standard-Bibliothek zu schreiben
						// z.B. statt "std::cout" kann man "cout" schreiben



CTempSensor::CTempSensor(float minTemp,float maxTemp)
{
	CTempSensor::retrieveLastMeasurements();
    CTempSensor::calculateMinMaxTemp();



}

// generiert 24 Zufallswerte zw. 5 und 95 Grad [vorgegeben]
void CTempSensor::retrieveLastMeasurements()
{
	for (int i=0; i<24;i++) {
		m_last24hrsTemp[i] = (rand() % 900 + 50) / (float)10;
	}
}


// gibt min/max und die 24 Messwerte aus [vorgegeben]
void CTempSensor::print()
{
	cout << "min: " << m_minTemp << " | max: " << m_maxTemp << " | Letzte 24 Messwerte: ";

	for (int i=0; i<24;i++) {
		cout << setw(4) << m_last24hrsTemp[i] << " | " ;
	}
	cout << endl;

}


// gibt den Prozentsatz der Werte in der Range zurueck [gegeben fuer Aufgane 3c]
float CTempSensor::checkTempRange(float low, float high)
{
	int inRange = 0;
	int outOfRange = 0;

	for (int i=0; i<24;i++) {
		if (m_last24hrsTemp[i] < low || m_last24hrsTemp[i] > high) {
			outOfRange++;
		}
		else {
			inRange++;
		}
	}
	return 100*inRange/24.;
}



CTempSensor::~CTempSensor()
{
	// TODO Auto-generated destructor stub
}

 void CTempSensor::calculateMinMaxTemp(){

	m_minTemp = m_last24hrsTemp[0];
	m_maxTemp = m_last24hrsTemp[0];



	 for(int i = 1; i < 24 ; i++)
	 {
	     if(m_last24hrsTemp[i] > m_maxTemp)
	         m_maxTemp = m_last24hrsTemp[i];
	     if(m_last24hrsTemp[i] < m_minTemp)
	         m_minTemp = m_last24hrsTemp[i];
	 }


	 }


 double CTempSensor::calculateMeanTemp(){
	 double summe = 0;
	 for(int i = 0; i<24 ; i++){

		 summe += m_last24hrsTemp[i];
	 }
	 summe = (summe)/(24);
return summe;

 }





void CTempSensor::generateSensorType(){

m_sensorType = (rand() % 900 + 50) / (float)10;



So?
You have 4 sensor types, hence:

m_sensorType = static_cast<tSensorType>(rand() % 4);

The cast is needed otherwise the compiler should throw an error.
Is there anowther way? I never used static_cast?

What does this line?
(rand() % 4)
What does this line?
The % is modulo. See:

http://www.cplusplus.com/doc/tutorial/operators/

It means that you get value from 0 to 3 (which are [accidentally] the values of enum tSensorType).

Another way to cast is this:

m_sensorType = (tSensorType)(rand() % 4);

without casting the compiler won't accept the values as enum.

g) Implement a public method string getSensorTypeAsString () that returns the (6) sensor type of a CTempSensor object as string.
h) Overload the output operator << and output m_sensorType, m_minTemp, (6) m_maxTemp and the average of the 24 measured values ​​to the console. Orient
using the format at the print () method; see. also the following picture.
Note 1: Calling the print () method in the operator is not allowed.
Note 2: The displayed values ​​may differ on your display because they are random.

g) is solved by me .
But I have a little problem with h) . The structure of the operator << is not given ?

The display should show this:
https://www.pic-upload.de/view-35193176/Bildschirmfoto2018-04-19um15.52.23.png.html



My code :

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
* CTempSensor.h
 *
 *  Created on: 23.06.2017
 *      Author: buergy
 */

#ifndef CTEMPSENSOR_H_
#define CTEMPSENSOR_H_

#include <iostream>


using namespace std;


enum tSensorType{GENERAL ,WATER , OIL , AIR};
class CTempSensor
{

private:
	float m_last24hrsTemp[24]; // array of last 24 measurements [vorgegeben]
	float m_minTemp;           // minimum Temp of last 24hrs [vorgegeben]
	float m_maxTemp;           // maximum Temp of last 24hrs [vorgegeben]
	void calculateMinMaxTemp();
	tSensorType m_sensorType;



public:
	CTempSensor(float minTemp = 0 , float maxTemp = 0);
	virtual ~CTempSensor();

	void retrieveLastMeasurements();  // erzeugt 24 Zufallswerte [vorgegeben]
	void print();                     // gibt die Messdaten aus [vorgegeben]
	float checkTempRange(float, float); // [vorgegeben]
	double calculateMeanTemp();
	string getSensorTypeAsString();

	void generateSensorType();


};

#endif /* CTEMPSENSOR_H_ */





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
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

/*
 * CTempSensor.cpp
 *
 *  Created on: 23.06.2017
 *      Author: buergy
 */

#include "CTempSensor.h"
#include <iostream>		// Header fuer die Standard-IO-Objekte (z.B. cout, cin)
#include <cstdlib>      // fuer random values
#include <iomanip>      // fuer setw()
#include <string>
#include<cmath>


using namespace std;	// Erspart den scope vor Objekte der
						// C++-Standard-Bibliothek zu schreiben
						// z.B. statt "std::cout" kann man "cout" schreiben



CTempSensor::CTempSensor(float minTemp,float maxTemp)
{
	CTempSensor::retrieveLastMeasurements();
    CTempSensor::calculateMinMaxTemp();



}

// generiert 24 Zufallswerte zw. 5 und 95 Grad [vorgegeben]
void CTempSensor::retrieveLastMeasurements()
{
	for (int i=0; i<24;i++) {
		m_last24hrsTemp[i] = (rand() % 900 + 50) / (float)10;
	}
}


// gibt min/max und die 24 Messwerte aus [vorgegeben]
void CTempSensor::print()
{
	cout << "min: " << m_minTemp << " | max: " << m_maxTemp << " | Letzte 24 Messwerte: ";

	for (int i=0; i<24;i++) {
		cout << setw(4) << m_last24hrsTemp[i] << " | " ;
	}
	cout << endl;

}


// gibt den Prozentsatz der Werte in der Range zurueck [gegeben fuer Aufgane 3c]
float CTempSensor::checkTempRange(float low, float high)
{
	int inRange = 0;
	int outOfRange = 0;

	for (int i=0; i<24;i++) {
		if (m_last24hrsTemp[i] < low || m_last24hrsTemp[i] > high) {
			outOfRange++;
		}
		else {
			inRange++;
		}
	}
	return 100*inRange/24.;
}



CTempSensor::~CTempSensor()
{
	// TODO Auto-generated destructor stub
}

 void CTempSensor::calculateMinMaxTemp(){

	m_minTemp = m_last24hrsTemp[0];
	m_maxTemp = m_last24hrsTemp[0];



	 for(int i = 1; i < 24 ; i++)
	 {
	     if(m_last24hrsTemp[i] > m_maxTemp)
	         m_maxTemp = m_last24hrsTemp[i];
	     if(m_last24hrsTemp[i] < m_minTemp)
	         m_minTemp = m_last24hrsTemp[i];
	 }


	 }


 double CTempSensor::calculateMeanTemp(){
	 double summe = 0;
	 for(int i = 0; i<24 ; i++){

		 summe += m_last24hrsTemp[i];
	 }
	 summe = (summe)/(24);
return summe;

 }

 void CTempSensor::generateSensorType(){


	 m_sensorType = static_cast<tSensorType>(rand() % 4);
 }

 string CTempSensor::getSensorTypeAsString(){
	 return("GENERAL","WATER","OIL","AIR","m_sensorType");


 }

only a warning here :Description Resource Path Location Type
expression result unused [-Wunused-value] CTempSensor.cpp /CTemp line 114 C/C++ Problem
string CTempSensor::getSensorTypeAsString(){
return("GENERAL","WATER","OIL","AIR","m_sensorType");


}
Has somebody some tipps for me ?
I don't think that you should return all sensor types. Just the sensor type according to m_sensorType. You may do this with a switch:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
string CTempSensor::getSensorTypeAsString(){

	 string result;

switch(m_sensorType)
{
  case WATER:
    result = "WATER";
  break;
  case OIL:
...

}
	 return result;
 }


Regarding operator<<(...). For an example see this:

http://en.cppreference.com/w/cpp/language/operators

In 'Stream extraction and insertion'.
My operator looks so?


Is it alright?

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
* CTempSensor.h
 *
 *  Created on: 23.06.2017
 *      Author: buergy
 */

#ifndef CTEMPSENSOR_H_
#define CTEMPSENSOR_H_

#include <iostream>


using namespace std;


enum tSensorType{GENERAL ,WATER , OIL , AIR};
class CTempSensor
{

private:
	float m_last24hrsTemp[24]; // array of last 24 measurements [vorgegeben]
	float m_minTemp;           // minimum Temp of last 24hrs [vorgegeben]
	float m_maxTemp;           // maximum Temp of last 24hrs [vorgegeben]
	void calculateMinMaxTemp();
	tSensorType m_sensorType;



public:
	CTempSensor(float minTemp = 0 , float maxTemp = 0);
	virtual ~CTempSensor();

	void retrieveLastMeasurements();  // erzeugt 24 Zufallswerte [vorgegeben]
	void print();                     // gibt die Messdaten aus [vorgegeben]
	float checkTempRange(float, float); // [vorgegeben]
	double calculateMeanTemp();
	string getSensorTypeAsString();

	void generateSensorType();
  friend ostream& operator << (ostream& lop, CTempSensor& rop);

};
ostream& operator << (ostream& lop, CTempSensor& rop);
#endif /* CTEMPSENSOR_H_ */



1
2
3
4
5
6
7
8
ostream& operator << (ostream& lop, CTempSensor& rop){

	 lop << "Typ:"  << rop.m_sensorType << "" << "min:" << rop.m_minTemp  << "" << "max:"<< rop.m_maxTemp<<""<<"Durchschnitt:"<<rop.calculateMeanTemp()<< endl;

	 return lop;
 }

Ok?
Did you test it?

Remove line 43. The second parameter better would be const. Otherwise when it compiles and does what you want, it is ok.
The problem is with my eclipse that the test doesnt work?
But the compiler shows no error .
So it must be alright.

I think thats a problem with my version
Last edited on
Now I am at task 2 .
It is showing me an error why ?
I donst understand .
Please help me guys


Implement the constructor and the destructor. Set the initial or (6) parameter values ​​in the constructor, set the default value if the assertion is violated.
You can be sure that a dynamic memory management has been modeled using the attributes m_pSensors, m_maxSensorIdx and m_nextSensorIdx. Convert them appropriately into constructor and destructor.
https://www.pic-upload.de/view-35213514/Bildschirmfoto2018-04-23um11.43.57.png.html
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
/*
 * CSensorGrid.h
 *
 *  Created on: 23.04.2018
 *      Author: macbook
 */

#ifndef CSENSORGRID_H_
#define CSENSORGRID_H_
#include "CTempSensor.h"
#include <iostream>
using namespace std;


class CSensorGrid {

private:
	CTempSensor* m_pSensor;
	int m_maxSensorIdx;
	int m_nextSensorIdx = 0;


public:
	CSensorGrid(int maxSensorIdx = 10);
	 ~CSensorGrid();
	 void operator += (const CTempSensor& rop);
	 void print(tSensorType type);
	 float calculateMedianTemp();
};

#endif /* CSENSORGRID_H_ */ 



cpp

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22

#include "CSensorGrid.h"

CSensorGrid::CSensorGrid(int maxSensorIdx) {

	if(m_maxSensorIdx >= 5 ){

		m_maxSensorIdx = maxSensorIdx;
	}
	else{
		int m_maxSensorIdx = 10;

	}
	m_pSensor = new CSensorGrid [m_maxSensorIdx]; showing error here ?

}

CSensorGrid::~CSensorGrid() {
	delete[] m_pSensor;
}




error:
Description Resource Path Location Type
assigning to 'CTempSensor *' from incompatible type 'CSensorGrid *' CSensorGrid.cpp /CTemp line 20 C/C++ Problem
make: *** [CSensorGrid.o] Error 1 CTemp C/C++ Problem
in-class initialization of non-static data member is a C++11 extension [-Wc++11-extensions] CSensorGrid.h /CTemp line 20 C/C++ Problem
unused variable 'm_maxSensorIdx' [-Wunused-variable] CSensorGrid.cpp /CTemp line 17 C/C++ Problem
It's exactly what the error message says it is. You've defined m_pSensor to be a pointer to CTempSensor. At line 14, you're trying to store a pointer to CSensorGrid in it. Those are incompatible.

Why are you making the CSensorGrid constructor allocate an array of more CSensorGrid objects? Surely you can see how that's going to lead to infinite recursion?
In the task its written to do in constructor.
c) Overload the operator + = This will insert the passed CTempSensor object into the array m_pSensors at the next free position. If the space is not
is sufficient, the array should grow by five additional objects before the new object is inserted.

I did it so but again error .

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

CSensorGrid::CSensorGrid(int maxSensorIdx) {

	if(m_maxSensorIdx >= 5 ){

		m_maxSensorIdx = maxSensorIdx;
	}
	else{
		int m_maxSensorIdx = 10;

	}
	m_pSensor = new CTempSensor [m_maxSensorIdx];

}

CSensorGrid::~CSensorGrid() {
	delete[] m_pSensor;
}

void CSensorGrid::operator += (const CTempSensor&rop){
	m_pSensor[m_nextSensorIdx] = rop;
	int m_maxSensorIdx = 10;
	for( int i = 0; i<m_maxSensorIdx;i++){
		if(m_pSensor[i] < m_maxSensorIdx){

			m_pSensor[m_maxSensorIdx+5] = rop;


		}


	}

}



Description Resource Path Location Type
invalid operands to binary expression ('CTempSensor' and 'int') CSensorGrid.cpp /CTemp line 32 C/C++ Problem
make: *** [CSensorGrid.o] Error 1 CTemp C/C++ Problem
in-class initialization of non-static data member is a C++11 extension [-Wc++11-extensions] CSensorGrid.h /CTemp line 20 C/C++ Problem
unused variable 'm_maxSensorIdx' [-Wunused-variable] CSensorGrid.cpp /CTemp line 17 C/C++ Problem


Is my if condition right to see , if the space is full?
Has somebody any idea ?
Is my if condition right to see , if the space is full?
No, escpecially line 24 dosen't make sense.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
void CSensorGrid::operator += (const CTempSensor&rop){

if(m_nextSensorIdx >= m_maxSensorIdx)
{
  CTempSensor *old_sensor = m_pSensor;
  m_pSensor = new CTempSensor [m_maxSensorIdx + 5];
  std::copy(old_sensor, old_sensor + m_maxSensorIdx, m_pSensor);
  delete[] old_sensor;
  m_maxSensorIdx += 5;
}

m_pSensor[++m_nextSensorIdx] = rop;

}
For copy(...) see this:

http://www.cplusplus.com/reference/algorithm/copy/?kw=copy
Pages: 1234