My assignment is soo wrong..

I duno what i was doing anymore...

keep adding things even knowing that i am wrong...guide me please?

PointTwoD.h

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
#ifndef POINTTWOD_H
#define POINTTWOD_H

#include <cstdlib>
#include <cctype>
#include <cstring>
#include <sstream>
#include <fstream>
#include<iostream>
#include<string>

#include "LocationData.h"




using namespace std;

class PointTwoD
{

private:

	int x;
	int y;
	LocationData ld;
	float civIndex;

public:

	int getX();
	void setX(int);

	int getY();
	void setY(int);	

	LocationData getLocationData();
	void setLocationData(LocationData);

};

#endif 



PointTwoD.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 "PointTwoD.h"



void PointTwoD::setX(int x)
{
	x = x;
}

int PointTwoD::getX()
{
	return x;
}

void PointTwoD::setY(int y)
{
	y = y;
}

int PointTwoD::getY()
{
	return y;
}

//LocationData PointTwoD::getLocatioNData()
//{
//	return locationData;
//} 
Last edited on
LocationData.h

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
#ifndef LOCATIONDATA_H
#define LOCATIONDATA_H

#include <cstdlib>
#include <cctype>
#include <cstring>
#include <sstream>
#include <fstream>
#include<iostream>
#include<string>

using namespace std;

class LocationData
{
	private:

	string sunType;
	int noOfEarthLikePlanets;
	int noOfEarthLikeMoons;
	float aveParticulateDensity;
	float avePlasmaDensity;
	int sunTypePercent;


	public:
	LocationData();
	LocationData(string, int, int, float, float);

	string getSunType();
	void setSunType(string);

	int getNoOfEarthLikePlanets();
	void setNoOfEarthLikePlanets(int);

	int getnoOfEarthLikeMoons();
	void setNoOfEarthLikeMoon(int);

	float getAveParticulateDensity();
	void setAveParticulateDensity(float);

	float getAvePlasmaDensity();
	void setAvePlasmaDensity(float);

	float computeCivIndex(int, int, int, float, float);
	
	string toString();

};

#endif 


LocationData.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
#include "LocationData.h"

using namespace std;

//string LocationData::getSunType(sunT)
//{
//	if(sunT="Type O")
//	sunTypePercent=30;
//	else if(sunT="Type B")
//	sunTypePercent=45;
//	else if(sunT="Type A")
//	sunTypePercent=60;
//	else if(sunT="Type F")
//	sunTypePercent=75;
//	else if(sunT="Type G")
//	sunTypePercent=90;
//	else if(sunT="Type K")
//	sunTypePercent=80;
//	else if(sunT="Type M")
//	sunTypePercent=70;
//	else
//	cout<<"Input Invalid"<<endl;
//	return sunT
//}

LocationData::LocationData() 
{
	sunType = "";
	noOfEarthLikePlanets = 0;
	noOfEarthLikeMoons = 0;
	aveParticulateDensity = 0.0;
	avePlasmaDensity = 0.0;
}

LocationData::LocationData(string sunType, int noOfEarthLikePlanets, int noOfEarthLikeMoons, float aveParticulateDensity, float avePlasmaDensity) 
{

	this-> sunType = sunType;
	this-> noOfEarthLikePlanets = noOfEarthLikePlanets;
	this-> noOfEarthLikeMoons = noOfEarthLikeMoons;
	this-> aveParticulateDensity = aveParticulateDensity;
	this-> avePlasmaDensity = avePlasmaDensity;
}

string LocationData::getSunType() 
{
	return sunType;
}

void LocationData::setSunType(string sunT) 
{
	this -> sunType = sunT;
}

int LocationData::getNoOfEarthLikePlanets() 
{
	return noOfEarthLikePlanets;
}

void LocationData::setNoOfEarthLikePlanets(int noOfEarthLikePlanets) 
{
	this->noOfEarthLikePlanets = noOfEarthLikePlanets;
}

int LocationData::getnoOfEarthLikeMoons() 
{
	return noOfEarthLikeMoons;
}

void LocationData::setNoOfEarthLikeMoon(int noOfEarthLikeMoons) 
{
	this -> noOfEarthLikeMoons = noOfEarthLikeMoons;
}

float LocationData::getAveParticulateDensity() 
{
	return aveParticulateDensity;
}

void LocationData::setAveParticulateDensity(float aveParticulateDensity) 
{
	this -> aveParticulateDensity = aveParticulateDensity;
}

float LocationData::getAvePlasmaDensity() 
{
	return avePlasmaDensity;
}

void LocationData::setAvePlasmaDensity(float avePlasmaDensity) 
{
	this -> avePlasmaDensity = avePlasmaDensity;
}

string LocationData::toString() 
{
	string temp;
	temp += getSunType();
	temp += getNoOfEarthLikePlanets();
	temp += getnoOfEarthLikeMoons();
	temp += getAveParticulateDensity();
	temp += getAvePlasmaDensity();
	return (temp);
}

float LocationData::computeCivIndex()
{
	computeCivIndex = [(sunTypePercent /100)-(aveParticulateDensity+avePlasmaDensity)/200]*[noOfEarthLikePlanets+noOfEarthLikeMoons];
	return computeCivIndex;
}
Last edited on
MissionPlan.h

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
#ifndef MISIONPLAN_H
#define MISSIONPLAN_H

#include <cstdlib>
#include <iostream>
#include <cctype>
#include <cstring>
#include <sstream>
#include <fstream>
#include <cmath>

#include "PointTwoD.h"

using namespace std;

class MissionPlan
{
	public:
	void mainMenu();
	void showEntry();
	void showDistance();	
	
	string sunT;
	int x; 
	int y;
	int noOfEarthLikePlanets;
	int noOfEarthLikeMoons;
	float aveParticulateDensity;
	float avePlasmaDensity;
	float distance;

	PointTwoD dataStore[100];
	PointTwoD getData;
	int counter;

	LocationData ld;
	
};

#endif 


MissionPlan.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
#include "LocationData.h"
#include "MissionPlan.h"

using namespace std;

	counter = 0;

void MissionPlan::mainMenu()
{
cout<<"Welcome to Mission Plan program!"<<endl<<endl<<

"1)Input statistical data."<<endl<<
"2)Compute civ. index value (for all records)"<<endl<<
"3)Print top 5 exploration destinations."<<endl<< 
"4)Print total travel distance."<<endl<<endl<<
"Please select your choice :"<<endl;
}	

void MissionPlan::showEntry() 
{
	cout<<"Input statistical data"<<endl<<endl;
	cout<<"Please enter x-cordinate:";
	cin>>x;
	getData.setX(x);

	cout<<"Please enter y-cordinate:";
	cin>>y;
	getData.setY(y);

	cout<<"Please enter sun type: ";
	cin>>sunT;
	ld.setSunType(sunT);

	cout<<"Please enter no. of earth-like planets:";
	cin>>noOfEarthLikePlanets;
	ld.setNoOfEarthLikePlanets(noOfEarthLikePlanets);

	cout<<"Please enter no. of earth-like moons:";
	cin>>noOfEarthLikeMoons;
	ld.setNoOfEarthLikeMoon(noOfEarthLikeMoons);

	cout<<"Please enter ave. particulate density (%-tage):";
	cin>>aveParticulateDensity;
	ld.setAveParticulateDensity(aveParticulateDensity);

	cout<<"Please enter ave. plasma density (%-tage):";
	cin>>avePlasmaDensity;
	ld.setAvePlasmaDensity(avePlasmaDensity);	

	dataStore[counter]=ld.toString();
	counter++;

	cout<<"Record succesfully stored. Going back to main menu."<<endl;
}

//*
//void MissionPlan::showTopFive(list<PointTwoD> &clist)
//{
//	list <PointTwoD>::iterator i;
//	sort(clist.begin(), clist.end());
//
//	do
//{
//	for (i = clist.begin(); i != clist.end(); i++)
////{
//cout << "Civ Idx : " << ld.computeCivIndex(i->ld.getSunType(), i->ld.getNoOfEarthLikePlanets(), i->ld.getnoOfEarthLikeMoons(), i-////>ld.getAveParticulateDensity(), i->ld.getAvePlasmaDensity()) << " at sector(" << i->getX() << "," << i->getY() << ")" << endl;
//}

//}
//while(i==5);
//}
//*

//void InputArrays(int, int, string, int, int, float, float)
//{

//*********
//void showTopFive()
//{
//	cout<<endl<<"Total no. of records available = "<<endl;
//	cout<<endl<<"Printing top 5 deploration destinations ..."<<endl;
//	cout<<endl<<"1) "<<endl;	
//	cout<<endl<<"2) "<<endl;	
//	cout<<endl<<"3) "<<endl;	
//	cout<<endl<<"4) "<<endl;	
//	cout<<endl<<"5) "<<endl<<endl<<endl;
//	cout<<endl<<"Done!"<<endl;	
//}
//****************

void MissionPlan::showDistance() 
{
    distance = sqrt(((x*x) + (y*y))*100);
    //Output
    cout << "Total (approx) travel distance = ";
    cout << distance <<" million km"<< endl;
}

Last edited on
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 <iostream>
#include <string>

using namespace std;

	void mainMenu();
	void showEntry();
	void showDistance();
	float computeCivIndex();
	void showTopFive();

	int choice;

int main()
{		
	mainMenu();
	cin>>choice;

switch(choice)
{
	case 1 : 
	showEntry();
	mainMenu();

	break;

	case 2 : 
	computeCivIndex();
	cout<<endl<<"Computation Completed! (" "records were updated )"<<endl;

	break;

	case 3 : 
	showTopFive();
	
	break;

	case 4 : 
	showDistance();
	
	break;

	default: cout<<"Invalid choice, please re-enter your choice."<<endl; 

}

return 0; 

}

Last edited on
At a first glance:

You
#include "LocationData.h" into PointTwoD.h

and

#include "PointTwoD.h" into LocationData.h

that cannot work. Remove #include "PointTwoD.h" from LocationData.h since you don't use it there

Please use code tags: [code]Your code[/code]
ok have removed that and did some amendments on some mistake as well.

but still the whole thing is a mess. Im just a beginner...

a lot main function and arrays to done yet as well.
generally: you cannot have this circular/mutual include. That applies to MissionPlan.h as well.

just saying it's a mess doesn't suffice. Be more specific and I might help you.

The best approach is:

write code
compile it
test it
write more code

If you think it's a mess then you make it worse when you continue writing code. First make that existing work
no, but i believe we have the same assignment lol...
And the same errors, I'm guessing you were given this code?
our lecturer have guide us a little through this.

my error is crazy...

In file included from LocationData.h:11:0,
from PointTwoD.h:12,
from PointTwoD.cpp:9:
MissionPlan.h:22:2: error: ‘PointTwoD’ does not name a type
MissionPlan.h:23:2: error: ‘PointTwoD’ does not name a type
MissionPlan.h:24:14: error: ISO C++ forbids initialization of member ‘counter’ [-fpermissive]
MissionPlan.h:24:14: error: making ‘counter’ static [-fpermissive]
MissionPlan.h:24:14: error: ISO C++ forbids in-class initialization of non-const static member ‘counter’
MissionPlan.h:26:2: error: ‘LocationData’ does not name a type
MissionPlan.h:33:2: error: ‘LocationData’ does not name a type
MissionPlan.h:34:13: error: ‘LocationData’ has not been declared
PointTwoD.cpp:27:5: error: ‘pointTwoD’ has not been declared
PointTwoD.cpp: In function ‘int getY()’:
PointTwoD.cpp:29:9: error: ‘y’ was not declared in this scope
PointTwoD.cpp: At global scope:
PointTwoD.cpp:32:14: error: prototype for ‘LocationData PointTwoD::getLocationData(int, int)’ does not match any in class ‘PointTwoD’
PointTwoD.h:34:15: error: candidate is: LocationData PointTwoD::getLocationData()
In file included from LocationData.h:11:0,
from PointTwoD.h:12,
from LocationData.cpp:2:
MissionPlan.h:22:2: error: ‘PointTwoD’ does not name a type
MissionPlan.h:23:2: error: ‘PointTwoD’ does not name a type
MissionPlan.h:24:14: error: ISO C++ forbids initialization of member ‘counter’ [-fpermissive]
MissionPlan.h:24:14: error: making ‘counter’ static [-fpermissive]
MissionPlan.h:24:14: error: ISO C++ forbids in-class initialization of non-const static member ‘counter’
MissionPlan.h:26:2: error: ‘LocationData’ does not name a type
MissionPlan.h:33:2: error: ‘LocationData’ does not name a type
MissionPlan.h:34:13: error: ‘LocationData’ has not been declared
LocationData.cpp:105:7: error: prototype for ‘float LocationData::computeCivIndex()’ does not match any in class ‘LocationData’
LocationData.h:45:8: error: candidate is: float LocationData::computeCivIndex(std::string, int, int, float, float)
In file included from LocationData.h:11:0,
from PointTwoD.h:12,
from MissionPlan.h:11,
from MissionPlan.cpp:1:
MissionPlan.h:22:2: error: ‘PointTwoD’ does not name a type
MissionPlan.h:23:2: error: ‘PointTwoD’ does not name a type
MissionPlan.h:24:14: error: ISO C++ forbids initialization of member ‘counter’ [-fpermissive]
MissionPlan.h:24:14: error: making ‘counter’ static [-fpermissive]
MissionPlan.h:24:14: error: ISO C++ forbids in-class initialization of non-const static member ‘counter’
MissionPlan.h:26:2: error: ‘LocationData’ does not name a type
MissionPlan.h:33:2: error: ‘LocationData’ does not name a type
MissionPlan.h:34:13: error: ‘LocationData’ has not been declared
In file included from MissionPlan.cpp:1:0:
MissionPlan.h:15:7: error: redefinition of ‘class MissionPlan’
MissionPlan.h:15:7: error: previous definition of ‘class MissionPlan’
MissionPlan.cpp:3:27: error: variable or field ‘TopFive’ declared void
MissionPlan.cpp:3:27: error: ‘list’ was not declared in this scope
MissionPlan.cpp:3:41: error: expected primary-expression before ‘>’ token
MissionPlan.cpp:3:44: error: ‘clist’ was not declared in this scope
In file included from MissionPlan.h:11:0,
from LocationData.h:11,
from main.cpp:4:
PointTwoD.h:23:2: error: ‘LocationData’ does not name a type
PointTwoD.h:34:2: error: ‘LocationData’ does not name a type
PointTwoD.h:35:23: error: ‘LocationData’ has not been declared
In file included from LocationData.h:11:0,
from main.cpp:4:
MissionPlan.h:24:14: error: ISO C++ forbids initialization of member ‘counter’ [-fpermissive]
MissionPlan.h:24:14: error: making ‘counter’ static [-fpermissive]
MissionPlan.h:24:14: error: ISO C++ forbids in-class initialization of non-const static member ‘counter’
MissionPlan.h:26:2: error: ‘LocationData’ does not name a type
MissionPlan.h:33:2: error: ‘LocationData’ does not name a type
MissionPlan.h:34:13: error: ‘LocationData’ has not been declared
In file included from main.cpp:6:0:
MissionPlan.h:15:7: error: redefinition of ‘class MissionPlan’
MissionPlan.h:15:7: error: previous definition of ‘class MissionPlan’

Now my error have left with this below....


LocationData.cpp:105:7: error: prototype for ‘float LocationData::computeCivIndex()’ does not match any in class ‘LocationData’
LocationData.h:45:8: error: candidate is: float LocationData::computeCivIndex(int, float, float, int, int)
In file included from MissionPlan.cpp:2:0:
MissionPlan.h:34:14: error: ISO C++ forbids initialization of member ‘counter’ [-fpermissive]
MissionPlan.h:34:14: error: making ‘counter’ static [-fpermissive]
MissionPlan.h:34:14: error: ISO C++ forbids in-class initialization of non-const static member ‘counter’
MissionPlan.cpp: In member function ‘void MissionPlan::showEntry()’:
MissionPlan.cpp:50:33: error: no match for ‘operator=’ in ‘((MissionPlan*)this)->MissionPlan::dataStore[MissionPlan::counter] = LocationData::toString()()’
MissionPlan.cpp:50:33: note: candidate is:
PointTwoD.h:19:7: note: PointTwoD& PointTwoD::operator=(const PointTwoD&)
PointTwoD.h:19:7: note: no known conversion for argument 1 from ‘std::string {aka std::basic_string<char>}’ to ‘const PointTwoD&’
1> LocationData.cpp:105:7: error: prototype for ‘float LocationData::computeCivIndex()’ does not match any in class ‘LocationData’

You have this declared in LocationData float computeCivicIndex(string, int, int, float, float); but you implement computeCivIndex()

2 > MissionPlan.h:34:14: error: ISO C++ forbids initialization of member ‘counter’ [-fpermissive]

In MissionPlan header you have this int counter=0; this is illegal. Write it like int counter; Then inside the constructor for MissionPlan do... counter = 0; (Really you should use member initialize list to get in the habit of it.)

3 > MissionPlan.cpp: In member function ‘void MissionPlan::showEntry()’:
MissionPlan.cpp:50:33: error: no match for ‘operator=’ in ‘((MissionPlan*)this)->MissionPlan::dataStore[MissionPlan::counter] = LocationData::toString()()’

You need to overload the assignment operator for pointTwoD
LocationData.cpp:107:7: error: prototype for ‘float LocationData::computeCivIndex()’ does not match any in class ‘LocationData’
LocationData.h:45:8: error: candidate is: float LocationData::computeCivIndex(int, int, int, float, float)
MissionPlan.cpp:6:2: error: ‘counter’ does not name a type
MissionPlan.cpp: In member function ‘void MissionPlan::showEntry()’:
MissionPlan.cpp:50:33: error: no match for ‘operator=’ in ‘((MissionPlan*)this)->MissionPlan::dataStore[((MissionPlan*)this)->MissionPlan::counter] = LocationData::toString()()’
MissionPlan.cpp:50:33: note: candidate is:
PointTwoD.h:19:7: note: PointTwoD& PointTwoD::operator=(const PointTwoD&)
PointTwoD.h:19:7: note: no known conversion for argument 1 from ‘std::string {aka std::basic_string<char>}’ to ‘const PointTwoD&’


I have a typo error in 1> and have change to computeCivIndex but same error.

change 2> as well.

not sure at 3>, could you guide me please?
1> Yes you not only had a typo in that one (which I did not point out), you also had different signatures for those functions. e.g. One takes void params computeCivicIndex() and the other takes 5 params computeCivicIndex(int, int, int, float, float) ... this is what you need to fix here.

3> In MissionPlan.cpp Line 50 you try to do this...
dataStore[counter]=ld.toString();

dataStore is an array of PointTwoD objects. //PointTwoD dataStore[]; Which means that dataStore[counter] is an object of type PointTwoD. ld is a LocationData Object, you call ld.toString() which returns a string object. You have no assignment operator for PointTwoD that takes a type string.

You do not have this:
1
2
3
4
5
PointTwoD& operator=(const std::string &src)
{
    //Handle assigning string to members of PointTwoD...
    return *this;
}
er...i need to store the x and y into array so that i could compute distances and other function later...

how do i really do that?

1
2
3
4
5
PointTwoD& operator=(const std::string &src)
{
    //Handle assigning string to members of PointTwoD...
    return *this;
}


what should i put in this?

i tried this and it couldnt work..

1
2
3
4
5
6
7
PointTwoD& PointTwoD::operator=(const PointTwoD& src)
{
	x = src.x;
	y = src.y;
	
    return *this;
}
Last edited on
in this case how to do store the input of x and y into one array.

i tried with many method but it only shows me one(first) input.

Topic archived. No new replies allowed.