You are here:

C++/Student Detail Recording System

Advertisement


Question









i am required to develop a system to record details of student.
This system should be implemented using structure and array. i am required to develop a structure which contains student details such as Student ID, Student Name, Nationality and Gender.

1st-i have to insert new record
2nd-delete record
3rd-sort record
4th-display record

my question is how to use a structure and array in this program. i haven't done my coding. but i wish to know the steps. i have learned this but not in coding. please show me the way so that i can improve. can i know what's the function of file/io and pointer? below is my codes that used to declare my variables. after that what should i do to insert my record,delete,sort the detail.. can teach me how the next steps?





#include <string>

struct student_information
{
      int id ;
      std::string name ;
      std::string nationality ;

      enum gender_t { MALE, FEMALE };
      gender_t gender ;
};
enum { MAX_STUDENTS = 100 } ;

student_information student_info_array[ MAX_STUDENTS ] ;
int number_of_students = 0 ;  

Answer
Hello spoink, thank you for the question.

If you want insert into your array, just start at index 0 and increment a counter to hold your current empty spot in the array.

int counter = 0;
student_info_array[counter] = // whatever you are inserting in;
counter++;

That way, each time you are inserting you go to the next empty slot in the array. Does that make sense?

If you want to delete, you simply ask the user which ID they wish to delete:

int ID;
cout << "Enter ID to delete: ";
cin >> ID;

for(int i = 0; i < MAX_STUDENTS; i++)
{
if(student_info_array[i].id == ID) // it matches
{
// clear the data

}
}

Details will just print the data out for each item in the array:

void PrintStudent(const student_information &toPrint)
{
cout << toPrint.id << endl;
cout << toPrint.name << endl;
cout << toPrint.nationality << endl;

if(student.gender == student_information::MALE)
cout << "Male" << endl;
else
cout << "Female" << endl;
}


For sorting, it all depends on what you need to sort by, but you simply swap places in the array until the array is sorted.

I hope this information was helpful.

- Eddie

C++

All Answers


Answers by Expert:


Ask Experts

Volunteer


Eddie

Expertise

I can answer questions about the C++ language, object oriented design and architecture. I am knowledgable in a lot of the math that goes into programming, and am certified by ExpertRating.com. I also know a good deal about graphics via OpenGL, and GUIs.

Experience

I have completed numerous games and demos created with the C++ programming language. Currently employed as a software engineer in the modeling and simulation field. I have about 7 years experience.

©2016 About.com. All rights reserved.