CPalini has already written a solution for exactly 5 students.
But there would be much better approaches that would not have this problem in the first place and would also be much more flexible. Data in a class should better not be public, but rather private. The name of the member function intro() doesn't seem to fit well either. More suitable would be getdata(). In order to be able to use the data at any time, a constructor would be recommended, which takes over this. One possibility would be to manage only the (private) data of ONE student in the class studentinfo.
class studentinfo {
int sID;
string name;
int g1, g2, g3;
float t;
public:
studentinfo();
bool getdata();
void showresult();
};
studentinfo::studentinfo():
sID(0), g1(0), g2(0), g3(0), t(0.0){};
const int MAX_INFO = 5;
int main() {
studentinfo num[MAX_INFO];
cout << "Input 5 Student Record\n";
for (int i = 0; i < MAX_INFO; i++) {
num[i].getdata();
num[i].showresult();
}
cout << "program ended.\n\n";
return 0;
}