C++ Programmierung |
Jassy unregistriert
|
|
Hallo euler ich benutze eclipse .
Warum werden mir diese Fehler angezeigt:
Description Resource Path Location Type
No return, in function returning non-void ss.cpp /SS11T1 line 76 Code Analysis Problem
Description Resource Path Location Type
'pow' is ambiguous '
Und hast du keine Idee wie ich die pow meldung beseitigen kann?
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:
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:
|
#include<iostream>
#include <string>
#include "SS.h"
#include <math.h>
using namespace std;
CMeasValue::CMeasValue( double value, int exp , string baseUnit){
m_baseUnit = baseUnit;
if( exp%3 == 0){
m_exp = exp;
m_value = value;
}
else{
m_exp = 0;
m_value = 0.0;
}
}
int CMeasValue:: getExp(){
return m_exp;
}
void CMeasValue::setBaseUnit(string baseUnit){
m_baseUnit = baseUnit;
}
bool CMeasValue::setMeasValue(double value,int exp){
if( exp%3 == 0){
m_exp = exp;
m_value = value;
return true;
}
else{
return false;
}
};
ostream& operator << (ostream& out, CMeasValue& rop)
{
out << "MeasValue@" << &rop << ": " << rop.m_value << "*10^" << rop.m_exp << rop.m_baseUnit << endl;
}
double CMeasValue::getMeasValue(int exp){
return m_value * pow(10, m_exp - exp);
}
|
|
Da ich ja leider noch ANfänger bin muss ich nochmal nachfragen :
double d = test.getMeasValue(5)
Warum muss ich das machen ?
Warum schreibt man z.B links double hin?
In meiner Implementierung steht ja ( int exp)
Das verstehe ich nicht .
Wird der methode nun in der main.cpp durch double geändert oder wie?
|
|
08.12.2013 14:18 |
|
|
|
zu pow():
ich glaube, ich kenne die Ursache: es gibt mehrere Überladungen für pow, aber kein pow(int, int).
Du kannst wieder <cmath> verwenden und versuche in der Funktion:
pow(10.0, (double)(m_exp - exp)), das sollte es tun.
double d = test.getMeasValue(5);
getMeasValue gibt ein double zurück, also braucht man auch eine Variable vom Typ double, um das Ergebnis zu speichern.
Alternativ:
code: |
1:
2:
|
double d;
d = test.getMeasValue(5); |
|
__________________ Syntax Highlighting fürs Board (Link)
|
|
08.12.2013 16:04 |
|
|
Jassy unregistriert
|
|
Gibt es eigentlich einen anderen Weg außer POW die Methode zu implementieren ?
|
|
08.12.2013 16:08 |
|
|
Jassy unregistriert
|
|
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:
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:
|
#include<iostream>
#include <string>
#include "SS.h"
#include <cmath>
using namespace std;
CMeasValue::CMeasValue( double value, int exp , string baseUnit){
m_baseUnit = baseUnit;
if( exp%3 == 0){
m_exp = exp;
m_value = value;
}
else{
m_exp = 0;
m_value = 0.0;
}
}
int CMeasValue:: getExp(){
return m_exp;
}
void CMeasValue::setBaseUnit(string baseUnit){
m_baseUnit = baseUnit;
}
bool CMeasValue::setMeasValue(double value,int exp){
if( exp%3 == 0){
m_exp = exp;
m_value = value;
return true;
}
else{
return false;
}
};
ostream& operator << (ostream& out, CMeasValue& rop)
{
out << "MeasValue@" << &rop << ": " << rop.m_value << "*10^" << rop.m_exp << rop.m_baseUnit << endl;
}
double CMeasValue::getMeasValue(int exp){
pow(10.0, (double)(m_exp - exp));
}
|
|
Mir werden jetzt nur noch 4 warnungen angezeigt:
Description Resource Path Location Type
no return statement in function returning non-void [-Wreturn-type] /SS11T1 line 80 C/C++ Problem
Description Resource Path Location Type
No return, in function returning non-void line 77 Code Analysis Problem
Description Resource Path Location Type
no return statement in function returning non-void [-Wreturn-type line 90 C/C++ Problem
|
|
08.12.2013 16:20 |
|
|
|
Ein wenig könntest du dann doch selbst nachdenken, wenn du das return weglässt, geht es freilich nicht.
code: |
1:
2:
3:
4:
|
double CMeasValue::getMeasValue(int exp)
{
return m_value * pow(10.0, (double)(m_exp - exp));
} |
|
Es gibt auch Alternativen zu pow:
wenn der Exponent wie hier ganzzahlig ist, kann man einfach eine Schleife nehmen (bei negativem Exponenten mit Betrag und das Ergebnis invertieren).
oder:
a^x = exp(x*ln(a))
__________________ Syntax Highlighting fürs Board (Link)
|
|
08.12.2013 16:23 |
|
|
Jassy unregistriert
|
|
Ah alles klar danke.
Ich glaube der zweite Weg ist ein wenig komplizierter .
Ich probier noch bisschen die Aufgabe weiter und meld mich ein wenig später .
P:S Hoffe das du noch ein wenig on bist
|
|
08.12.2013 16:28 |
|
|
Jassy unregistriert
|
|
ostream& operator << (ostream& out, CMeasValue& rop)
{
out << "MeasValue@" << &rop << ": " << rop.m_value << "*10^" << rop.m_exp << rop.m_baseUnit << endl;
}
Hier wird mir allerdings immer noch eine Verwarnung angezeigt:
Description Resource Path Location Type
no return statement in function returning non-void [-Wreturn-type] line 80 C/C++ Problem
|
|
08.12.2013 16:31 |
|
|
|
Also, mein Compiler hat es geschluckt.
Dann eben so:
code: |
1:
2:
3:
4:
5:
|
ostream& operator << (ostream& out, CMeasValue& rop)
{
out << "MeasValue@" << &rop << ": " << rop.m_value << "*10^" << rop.m_exp << rop.m_baseUnit << endl;
return out;
} |
|
__________________ Syntax Highlighting fürs Board (Link)
|
|
08.12.2013 16:33 |
|
|
Jassy unregistriert
|
|
Ja endlich keine fehler mehr.
Danke .
Warum hast du denn diesen Befehl in dem code:
rop.m_baseUnit;
Das verstehe ich leider nicht so ganz.
|
|
08.12.2013 16:37 |
|
|
|
Um der Aufgabenstellung gerecht zu werden
Zitat: |
und zeigen Sie sowohl das Messwert-Objekt als auch
das Ergebnis der Umrechnung (mit Einheit) auf dem Bildschirm an |
__________________ Syntax Highlighting fürs Board (Link)
|
|
08.12.2013 16:39 |
|
|
Jassy unregistriert
|
|
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:
48:
49:
50:
51:
52:
53:
|
#include<iostream>
#include <string>
using namespace std;
class CMeasValue{
private:
double m_value;
int m_exp;
string m_baseUnit;
public:
CMeasValue(double value = 0.0 ,int exp = 0,string baseUnit= " " );
int getExp();
void setBaseUnit(string baseUnit);
bool setMeasValue(double value,int exp);
double getMeasValue( int exp);
friend ostream& operator << (ostream& out, CMeasValue& rop);
};
class CMeasSeries : public CMeasValue{
private:
CMeasValue* m_values;
int m_maxValues;
int m_curValues;
string m_baseUnit;
CMeasSeries(string baseUnit ="" , int maxValues = 10);
CMeasSeries();
bool put( double value, int exp, string baseUnit);
bool getMaxValue(CMeasValue& maxMeasValue);
void print();
};
|
|
Meinen neue header sieht so aus:
Muss jetzt eine neue Klasse implementieren :
Wie include ich das in die cpp?
So werden mir fehler angezeigt:
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:
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:
|
#include<iostream>
#include <string>
#include "_SS.h"
#include <cmath>
#include"CMeasSeries.h"
using namespace std;
CMeasValue::CMeasValue( double value, int exp , string baseUnit){
m_baseUnit = baseUnit;
if( exp%3 == 0){
m_exp = exp;
m_value = value;
}
else{
m_exp = 0;
m_value = 0.0;
}
}
int CMeasValue:: getExp(){
return m_exp;
}
void CMeasValue::setBaseUnit(string baseUnit){
m_baseUnit = baseUnit;
}
bool CMeasValue::setMeasValue(double value,int exp){
if( exp%3 == 0){
m_exp = exp;
m_value = value;
return true;
}
else{
return false;
}
};
ostream& operator << (ostream& out, CMeasValue& rop)
{
out << "MeasValue@" << &rop << ": " << rop.m_value << "*10^" << rop.m_exp << rop.m_baseUnit << endl;
return out;
}
double CMeasValue::getMeasValue(int exp){
return m_value*pow(10.0, (double)(m_exp - exp));
}
|
|
#include"CMeasSeries.h"
Kann man das nicht so machen?
|
|
08.12.2013 16:55 |
|
|
Jassy unregistriert
|
|
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:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
|
#ifndef _SS_H_
#define _SS_H_
#include<iostream>
#include <string>
using namespace std;
class CMeasValue{
private:
double m_value;
int m_exp;
string m_baseUnit;
public:
CMeasValue(double value = 0.0 ,int exp = 0,string baseUnit= " " );
int getExp();
void setBaseUnit(string baseUnit);
bool setMeasValue(double value,int exp);
double getMeasValue( int exp);
friend ostream& operator << (ostream& out, CMeasValue& rop);
};
class CMeasSeries : public CMeasValue{
private:
CMeasValue* m_values;
int m_maxValues;
int m_curValues;
string m_baseUnit;
CMeasSeries(string baseUnit ="" , int maxValues = 10);
CMeasSeries();
bool put( double value, int exp, string baseUnit);
bool getMaxValue(CMeasValue& maxMeasValue);
void print();
};
|
|
Meine Header sieht so aus.
Habe ich einen Fehler gemacht ?
Oder warum erkennt er nicht die Header ?
In der cpp habe ich schon paar methoden implementiert :
Aufgabe:
Implementieren Sie den Konstruktor (bei Verletzung der Zusicherung den Default-Wert
setzen), den Destruktor und die print()-Methode. Die print()-Methode soll die Adresse
des Messreihen-Objektes, die maximale Anzahl zu speichernder Messwerte, die
Grundeinheit der Messreihe und die aktuell gespeicherten Messwerte zusammen mit ihrem
Index anzeigen. Falls keine Messwerte gespeichert sind, soll sie eine entsprechende
Meldung anzeigen (siehe Beispiel unten).
CMeasSeries@0012FE9C[50]:
leere Messreihe
CMeasSeries@0012FE9C[50]:
0: MeasValue@003467CC: 3.5*10^‐3 V
1: MeasValue@003467FC: 500*10^‐6 V
2: MeasValue@0034682C: 2.5*10^0 V
Maximalwert der Messreihe: MeasValue@0012FE6C: 2.5*10^0 V
Drücken Sie eine beliebige Taste . . .
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:
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:
|
#include<iostream>
#include <string>
#include "SS.h"
#include <cmath>
#include"CMeasSeries.h"
using namespace std;
CMeasValue::CMeasValue( double value, int exp , string baseUnit){
m_baseUnit = baseUnit;
if( exp%3 == 0){
m_exp = exp;
m_value = value;
}
else{
m_exp = 0;
m_value = 0.0;
}
}
int CMeasValue:: getExp(){
return m_exp;
}
void CMeasValue::setBaseUnit(string baseUnit){
m_baseUnit = baseUnit;
}
bool CMeasValue::setMeasValue(double value,int exp){
if( exp%3 == 0){
m_exp = exp;
m_value = value;
return true;
}
else{
return false;
}
};
ostream& operator << (ostream& out, CMeasValue& rop)
{
out << "MeasValue@" << &rop << ": " << rop.m_value << "*10^" << rop.m_exp << rop.m_baseUnit << endl;
return out;
}
double CMeasValue::getMeasValue(int exp){
return m_value*pow(10.0, (double)(m_exp - exp));
}
CMeasSeries::CMeasSeries(string baseUnit , int maxValues){
if( 0 < maxValues ){
m_maxValues = maxValues;
m_baseUnit = baseUnit;
}
else {
m_baseUnit ="";
maxValues = 10;
}
CMeasSeries::CMeasSeries();
}
|
|
Erkennst du den Fehler?
|
|
08.12.2013 17:26 |
|
|
|
Mehrere.
code: |
1:
2:
|
#ifndef _SS_H_
#define _SS_H_ |
|
wo ist dein #endif?
deshalb verwende ich #pragma once, das macht diese 3 Zeilen in einer.
Du hast CMeasValue und CMeasSeries im selben Header, vermutlich hast du nicht einmal einen CMeasSeries.h angelegt, dann kannst du ihn auch nicht einbinden.
__________________ Syntax Highlighting fürs Board (Link)
|
|
08.12.2013 17:34 |
|
|
Jassy unregistriert
|
|
Das problem ist ich soll:
die Klasse CMeasSeries unter der Klasse
CMeasValue deklarieren .
Wie soll ich das dann richtig machen ?
wo ist dein #endif?
Das endif ist in meiner Header hatte ich aber vergessen in den Beitrag zu kopieren.
Verstehst du jetzt mein problem?
|
|
08.12.2013 17:39 |
|
|
|