How to store the input into Arrays?

Hi I have 2 class now that need to store x and y to one array and some other attributes to another array so that i could do some computing and display both arrays as a top 5 list.

here is my codings.

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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
#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 locationData;
	float civIndex;

public:

	int getX();
	void setX(int);

	int getY();
	void setY(int);	

	LocationData getLocationData();
	void setLocationData(LocationData);

//	PointTwoD();
//	~PointTwoD();
//	PointTwoD& operator = (PointTwoD&);

//	char szBuffer[256];
//	for(int i = 0; i < num; i++) // loop through all the points
//{
//	sprintf_s(szBuffer, 256, "X Coord %i", i); // ask for x coord and store in xArray
//	cout << szBuffer;
//	cin >> x[i];

//	sprintf_s(szBuffer, 256, "Y Coord %i", i); // ask for y coord and store in yArray
//	cout << szBuffer;
//	cin >> y[i];

//}


	string toString();

};

#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
29
30
31
32
33
34
35
36
37
#include "PointTwoD.h"



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

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

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

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

string PointTwoD::toString() 
{
	string point2D;
	point2D += getX();
	point2D += getY();
	return (point2D);
}


//LocationData PointTwoD::getLocatioNData()
//{
//	return locationData;
//} 
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(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(string sunType)
//{
//	if(sunType="Type O")
//	sunTypePercent=30;
//	else if(sunType="Type B")
//	sunTypePercent=45;
//	else if(sunType="Type A")
//	sunTypePercent=60;
//	else if(sunType="Type F")
//	sunTypePercent=75;
//	else if(sunType="Type G")
//	sunTypePercent=90;
//	else if(sunType="Type K")
//	sunTypePercent=80;
//	else if(sunType="Type M")
//	sunTypePercent=70;
//	else
//	cout<<"Input Invalid"<<endl;
//	return sunType;
//}

//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) 
//{

//	sunType = sunType;
//	noOfEarthLikePlanets = noOfEarthLikePlanets;
//	noOfEarthLikeMoons = noOfEarthLikeMoons;
//	aveParticulateDensity = aveParticulateDensity;
//	avePlasmaDensity = avePlasmaDensity;
//}

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

void LocationData::setSunType(string sunType) 
{
	sunType = sunType;
}

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

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

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

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

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

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

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

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

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

//float LocationData::computeCivIndex()
//{
//	computeCivIndex = [(sunTypePercent /100)-(aveParticulateDensity+avePlasmaDensity)/200]*[noOfEarthLikePlanets+noOfEarthLikeMoons];
//	return computeCivIndex;
//} 
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
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
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
#include <iostream>
#include <string>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <cstring>
#include <sstream>
#include <fstream>
#include "PointTwoD.h"

using namespace std;

class MissionPlan
{
	
};

	string sunType;

	

	LocationData ld;

	int i;
	int x;
	int y;
	
	int noOfEarthLikePlanets;
	int noOfEarthLikeMoons;
	float aveParticulateDensity;
	float avePlasmaDensity;
	float distance;

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

//PointTwoD& PointTwoD::operator=(const PointTwoD &aPointTwoD)
//{
//	x = aPointTwoD.x;
//	y = aPointTwoD.y;
	
//	xArray = new int[x];
//for (i = 0; i < aPointTwoD.x; ++i)
//{
//	xArray[i] = aPointTwoD.xArray[i];
//}	
//    return *this;
//}




	void 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;
}

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





//*********
//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 showEntry()
{


	int xArray[10];
	for (i = 0; i < 1; i++)

	cout<<"Input statistical data"<<endl<<endl;
	
	cout<<"Please enter x-cordinate:";
	cin>>xArray[i];

//	dataStore.getX(x);
	
	int yArray[10];
	for (i = 0; i < 1; i++)

	cout<<"Please enter y-cordinate:";
	cin>>yArray[i];
//	y = new int[num];

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

	cout<<"Please enter sun type: ";
	cin>>sunType;
	//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[i]=ld.toString();
	i++;

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

	int choice;

int main()
{	
	const int x = 100;
	int list[x];

	mainMenu();
	cout<<"Please select your choice : ";
	cin>>choice;
	
switch(choice)
{
	case 1 : 
	showEntry();
	mainMenu();
	cout<<"Please select your choice : ";
	cin>>choice;
	return 0;
	break;

	case 2 : 
	for (int i = 0; i <1; i++)
	cout<<endl<<x<<endl;
//	computeCivIndex();
	cout<<endl<<"Computation Completed! (" "records were updated )"<<endl;

	break;

	case 3 : 
//	showTopFive();
//void 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);
//}

	cout<<"Please select your choice : ";
	cin>>choice;
	return 0;
	break;

	case 4 : 
	//showDistance();
	cout<<"Please select your choice : ";
	cin>>choice;
	return 0;
	break;

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

return 0;

}


I have no error in this and have use the for (i = 0; i < 1; i++) method,
but it doesnt seems to be working...how to make it display the first list of 5 input?
Topic archived. No new replies allowed.