crash in program

Hi everybody this my code for submitting student info and searching them by id number. no compile error and warning just crash
Enter data work correctly but crash happens in print function.
cout<<course; crash
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
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
#include "windows.h"
#include "iostream"
#include <io.h>
#include <sstream>
#include <conio.h>
#include <stdlib.h>
#include <iostream>
#include <string>
#define SIZE 5

using namespace std;
int   menu();

class student {
    public :
     char  name[20];
     char  family[20];
	 int   year;
	 int   stno;
     float ave;
	 int id;
	 char namep[20];//father name
	 float grade[2];
	 string  course;
public:
     student() { name[0] = '\0';}
     void  enter();
     int   getStno() { return stno; }
     void  print(int &);
     int  search(int no);
     void put();

};
//*************************


void gotoxy(int x,int y){
  HANDLE hConsole;
  COORD cursorLoc;
  std::cout.flush();
  cursorLoc.X = x;
  cursorLoc.Y = y;
  hConsole = GetStdHandle(STD_OUTPUT_HANDLE);
  SetConsoleCursorPosition(hConsole, cursorLoc);
}
//********************
void student::enter()
{
int i;
float sum=0;
string s;
 system("cls");



   //************Submit **************
   cout <<"Name	"<<"family	"<<"course		"<<"Rollno	"<<"year	"<<"ID	"<<"Father-n"<<endl;
   cin >> name;
   gotoxy(8, 13);
   cin >> family;
   gotoxy(16, 13);
   cin >> course;
   gotoxy(32, 13);
   cin >> stno;
   gotoxy(48, 13);
   cin >> year;
    gotoxy(56, 13);
   cin >> id;
    gotoxy(64, 13);
   cin >> namep;
   cout<<endl;

    //cout<<course;
    cout << "please enter  grade for each student:"<<endl;
    if (course.compare("MBA") == 0){

	      cout <<"Physic ";
          cin >>grade[0];
          cout <<"Mathmatic ";
          cin >>grade[1];
           cout <<"Chemeist ";
          cin >>grade[2];

            sum=0;
      for(i=0;i<3;i++){
                        sum=sum+grade[i];
                    }
        ave=sum/3;}

   else if(course.compare("Art") == 0)
	   {
	         cout <<"history ";
          cin >>grade[0];
          cout <<"Geography";
          cin >>grade[1];
           cout <<"English ";
          cin >>grade[2];

            sum=0;
      for(i=0;i<3;i++){
                        sum=sum+grade[i];
                    }
        ave=sum/3;}

   else if(course.compare("Sience") == 0)

	   {
     cout <<"Biology ";
          cin >>grade[0];
          cout <<"Mathmatic ";
          cin >>grade[1];
           cout <<"Chemeist ";
           cin >>grade[2];

            sum=0;
      for(i=0;i<3;i++){
                        sum=sum+grade[i];
                    }
        ave=sum/3;}
        cout<<endl;

   }
//*****************
void student::print(int& row)
{

    cout<<row;
	gotoxy(4,15);
   cout << "name is:"<<name<<"\n";

   cout <<"family:"<< family<<endl;
   cout <<"father name:"<< namep<<endl;
   cout <<"id:"<< id<<endl;
   cout <<"course:"<<course<<endl;


   cout <<"year:"<<year<<endl;

   cout <<"Roll no:"<<stno<<endl;
   cout << endl;
   cout <<"\t **Mark sheet** "<<endl;

if(course.compare("MBA") == 0){
          cout <<"Physic ";
          cout<<grade[0];
          cout <<"Mathmatic ";
          cout<<grade[1];
           cout <<"Chemeist ";
          cout<<grade[2];

 cout <<"\t **moadel kol for this student** "<<endl;
   cout <<ave;
}
if(course.compare("Sience") == 0){
          cout <<"Biology ";
          cout<<grade[0];
          cout <<"Mathmatic ";
          cout<<grade[1];
           cout <<"Chemeist ";
          cout<<grade[2];
   cout <<"\t **moadel kol for this student** "<<endl;
   cout <<ave;
}
if(course.compare("Art") == 0){
          cout <<"history ";
          cout<<grade[0];
          cout <<"Geography";
          cout<<grade[1];
          cout <<"English ";
          cout<<grade[2];

 cout <<"\t **result  for this student** "<<endl;
   cout <<ave;
}
   row ++;
   std::cin.get();
}
//******************

int main()
{
    student *st;
   int i, c,tno;

   st=new student[SIZE];
   for(;;) {
	  system("cls");
      c = menu();
      switch (c) {
	     case 1 :

	       cout<<"how many student you want";
	       cin>>tno;
	      for(i=1;i<=tno;i++)
		        st[i].enter();
	        break;
	     case 2 :
	        //findMax();
	        break;
	     case 3 :
	       // del();
	        break;
	     case 4 :
                    int flag;
                    st[i].put();
                    cout << "\nEnter Roll no to search :";
                    cin>>tno;
            for(int i=0;i<=SIZE;i++){
                            flag=st[i].search(tno);
                            if(flag==1)
                            st[i].print(tno);

                            }
            if(flag==0) {
             cout << "Student " << tno << " not exist."
                << "Press a key to continue...";
                std::cin.get();
            }
                std::cin.get();
	        break;
	     case 5 :
	        exit(0) ;
      } // end of switch
   } //end of for(;;)
}
//*************************
int menu()
{
  int c;
 // system("cls");
  gotoxy(5, 1);
  cout << "1) Enter a student.";
  gotoxy(5, 2);
  cout << "2) Find best student.";
  gotoxy(5, 3);
  cout << "3) Delete a student.";
  gotoxy(5, 4);
  cout << "4) Search a student.";
  gotoxy(5, 5);
  cout << "5) Exit.";

  do {
     gotoxy(5, 7);
     cout << "Enter your select(1-5) : ";
     cin >> c;
  } while (c < 1 && c > 5);
  return c;
}

int  student::search(int no)
{

    int flag=0;
    int i;
    int tno=stno;


   if(tno == no) {

            return 1;
   }
  else {
        return 0;
   }

}
void student::put(){
      cout<<course;
}


1
2
3
float grade[2];//Declaration of float array
               //consisting of two numbers: grade[0] and grade[1]
cout<<grade[2];//trying to access third element which can lead to crash 


Line 205: st[i].put(); i used uninitialized here, so probably a crash too.
Last edited on
Topic archived. No new replies allowed.