And I don't know why. I'm a bit of a newbie to coding and I know some C/C++.
I'm playing around with classes and objects, trying to get the hang of them, so I'm trying to create a database that keeps records of students-their ID number, their first and last names, and their mark. This worked fine, until I introduced a feature to allow the user to enter an ID number to look up a student, and for some reason my program crashes after displaying "ID number " with an error message.
So, without further ado, here is my code. Sorry if I've posted more than was nessesary, but feedback on what how I've done any thing would be appreciated
Code:
#include <iostream>
using namespace std;
class student
{
public:
int id,mark;
char fname[20],lname[20],grade;
void assignfname()
{
cout << "Enter the pupil's first name" << endl;
cin >> fname;
};
void assignlname()
{
cout << "Enter the pupil's last name" << endl;
cin >> lname;
};
void assignid()
{
cout << "Enter the studant's I.D. number" << endl;
cin >> id;
};
void marki()
{
cout << "Input the pupil's mark" << endl;
cin >> mark;
};
void display()
{
cout << "I.D. \t" << id << endl;
cout << "First name\t" << fname << endl;
cout << "Last name \t" << lname << endl;
cout << "Mark \t" << mark << endl;
}
};
int main()
{
int db;
student studentdb[1000];
for(int x=0;x<2;x++)
{
studentdb[x].assignfname();
studentdb[x].assignlname();
studentdb[x].assignid();
studentdb[x].marki();
system("cls");
}
cout << "Enter the id number of the database you wish to view" << endl;
cin >> db;
studentdb[db].display();
system("PAUSE");
}
Thanks in advance!