Weird Error

I run my code here, and i receive a weird windows error that says
"student.exe has stopped working" anyone have an idea?

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
#include <iostream>
#include <string>
#include <stdlib.h>

using namespace std;
class student
{
	
	public:
		student();// need to resolve this one too
		student(string StudentName);//
		student(int ClassCount);//
		student(string classNames[]);// need to resolve
		student(string StudentName, int ClassCount );//
		student(string StudentName, int ClassCount, string classNames[]);	//											
		
		void input();
		void setName(string StudentName);
		void setNumClasses(int ClassCount);
		void setClassList(string classNames[]);
		
		string getName();
		int getNumClasses();
	private:
		string name;			//name of Student
		int numClasses;
		string classList[];
				
};

int main()
{
	student joey;
	joey.input();
	
	return 0;
}

student::student( ) 
		: name(""), numClasses(6), classList()//name(""); numClasses(0)
			{	
			classList[numClasses];
			}
student::student(string StudentName)
		: name(StudentName),numClasses(6),classList()
			{
			classList[numClasses];
			}
student::student(int ClassCount)
		:name(""), numClasses(ClassCount), classList()
			{
				classList[numClasses];
			}
student::student(string classNames[]) 						//help with this constructor how to i get number of classes from 'classNames' length?
		:name(""), classList(), numClasses(6)
			{
				for(int i = 0; i < numClasses; i++)
					classList[i] = classNames[i];
			}
student::student(string StudentName, int ClassCount)
		:name(StudentName), numClasses(ClassCount), classList()
			{
				classList[numClasses];
			}

student::student(string StudentName, int ClassCount, string classNames[])
			:name(StudentName), numClasses(ClassCount), classList()
			{
				for(int i = 0; i < numClasses; i++)
					classList[i] = classNames[i];
			}			
void student::input()
{
	cout << "Enter the name of the student : ";
	cin >> name;
	cout << endl << "Enter number of classes : ";
	cin >> numClasses; 
	for(int i = 0; i < numClasses; i++)
		{
		cout << "Enter the name of the class " << i+1 << " : ";
		cin >> classList[i];
		cout << endl;
		}
}
void student::setName(string StudentName)
{
	name = StudentName;
}
void student::setNumClasses(int ClassCount)
{
	numClasses = ClassCount;
}
void student::setClassList(string classNames[])  // trouble with the size of 'classNames[]' to use in my for loop.
{
	
}
string student::getName()
{
	return name;
}
int student::getNumClasses()
{
	return numClasses;
}
//trouble with returning an array ?? and variables ?? or variables?? 
Last edited on
The errors are in this:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
class Foo
{
public:
  Foo();
private:
  int num;
  float list[]; // How many elements are in the list? Must know here.
};

Foo::Foo( )
: num( 42 ),
  list() // This is not the way to initialize an array
{	
  list[ num ]; // This just attempts to access an element
}

int main()
{
  Foo joey;
  return 0;
}
Topic archived. No new replies allowed.