I'm having a little difficulties with my program.
I'm trying to create a function "Star generateStars(int, int, string)" that generates Stars for my galaxy array.
Can someone please be kind enough to tell me what I did wrong, or how do I fix it?
Thanks a lot and sorry for the trouble
here is my main.cpp
#include "Class&Functions.h"
#include <iostream>
#include <string>
using std:: cin;
using std:: cout;
using std:: endl;
using std:: string;
using namespace std;
void createGalaxy();
Star generateStar(int, int, string);
int main () {
createGalaxy();
return 0;
}
void createGalaxy () {
int totalGalaxies;
cout << "What is the total number of galaxies in "
<< "the universe? ";
cin >> totalGalaxies;
while ((totalGalaxies < 0) || (totalGalaxies > 1000)) {
cout << "Please try again [0-1000]";
cin >> totalGalaxies;
}
Galaxy universe[totalGalaxies];
string tempName;
int tempStarCount;
for (int i = 0; i < totalGalaxies; i++) {
cout << "What is the name of galaxy " << i+1 << "? ";
cin >> tempName;
cout << "How many star(s) are in " << tempName << "? ";
cin >> tempStarCount;
cout << "Galaxy Created: " << tempName
<< ", contain(s) " << tempStarCount
<< " stars." << endl;
for (int j = 0; j < tempStarCount; j++) {
universe[i] = Galaxy (tempName, tempStarCount);
}
}
cout << totalGalaxies << "galaxies Added to the universe:" << endl;
for (int i = 0; i < totalGalaxies; i++)
cout << universe[i].gettempName() << endl;
}
Star generateStar(int starID, int starCount, string starLocation) {
return Star(0, 0, "0");
}
and here is my headers.h
#include <iostream>
#include <stdlib.h>
#include <string>
using std:: cin;
using std:: cout;
using std:: endl;
using std:: string;
using namespace std;
//Functions
class Star {
int starID, starIlluminationDegree;
string starLocation;
public:
Star (int, int, string);
};
Star:: Star (int a, int b, string c) {
this->starID = a;
this->starIlluminationDegree = b;
this->starLocation = c;
}
class Galaxy {
string tempName;
int size;
Star *galaxy[500][500];
public:
Galaxy();
Galaxy(string, int);
string gettempName();
};
Galaxy:: Galaxy (){
}
Galaxy:: Galaxy (string a, int B)/> {
this->tempName = a;
this->size = b;
}
string Galaxy:: gettempName() { return tempName;}

New Topic/Question
Reply



MultiQuote






|