

 #include <cstdlib>
 #include<iomanip>
#include <iostream>
#include <string>
#include <vector>
#include <sstream>
#include<fstream>
using namespace std;
int main()
{  
 int details;	 
 int n;
	string line;
    const int NUM_ELMTS = 18;

	// netID, major and GPA are parallel arrays
	int netID[NUM_ELMTS]; // Original netID array
	string major[NUM_ELMTS]; // Original major array
	double GPA[NUM_ELMTS]; // Original GPA array

						   // sortedGPAbyGPA is sorted by GPA, and sortedNetIDbyGPA and sorted.MajorbyGPA are parallel arrays
double sortedGPAbyGPA[NUM_ELMTS]; // GPA array, sorted by GPA
//	int sortedNetIDbyGPA[NUM_ELMTS];
//	string sortedMajorbyGPA[NUM_ELMTS];

	// sortedNetIDbyID is sorted by netID, and sorted.Major by ID and sortedGPAbyID are parallel arrays
	//int sortedNetIDbyID[NUM_ELMTS]; // netID array,sorted by netID
	//string sortedMajorbyID[NUM_ELMTS];
	//double sortedGPAbyID[NUM_ELMTS];
	int option; //Menu option

	string filename=("test.txt");
	int index;
	//int index2;
	//int index3;
	index = 0;
	cout << "Enter the file name: " << endl;
	cin >> filename;


  	ifstream myfile("test.txt",ios::out);
      
	
		if (myfile.is_open()){
	  		while (getline( myfile,line))
		{
			
			myfile >> netID[index];
			myfile >> GPA[index];
			myfile >> major[index];
			cout<<netID[index]<<endl;
            cout<< GPA[index]<<endl;
			cout<< major[index]<<endl;
			index ++;
		//	 Here, I am telling the compiler to read the data just like this
			// The data will be stored into subsequent arrays
		//	cout << netID << " " << major << " " << GPA << " ";
        //index++;
			cout << line << '\n';
		
		cout << index;
		myfile.close();
		}
		}

	else 
	cout << "Could not open file " << "\n Exiting" << endl;
	
	do
	{
		cout << "\n The purpose of this program is to manage student records" << endl << "Please select a menu option" << endl;
		cout << "1.List the top n students" << endl << "2.Search for a student" << endl << "3.Exit the program" << endl;
		cin >> option;
		switch (option)
		{
		case 1:{ //List the top n students
		cout<<"enter  n students to be displayed"<<endl;
		cin>>n;									//telling the user to input the number of students
		if(n<=18){
			cout<<"the details of n students are:\n";
			myfile >> netID[index];
			myfile >> GPA[index];
			myfile >> major[index];
			cout<<netID[index]<<endl;
            cout<< GPA[index]<<endl;
			cout<< major[index]<<endl;
			index ++;
			//cout << netID [index]<< "\n " << major[index] << "\n " << GPA[index] << " \n";
			// telling the compiler to read this details of n students
		}
		else
		{
        cout<<"larger  than array elements"<<endl;
		}
          
			break;}
		case 2:{
			cout<<"enter the netID of the students"<<endl;//checking if the net id of the students
			cin>>details;
			if(details==index){
				cout<<"the details of n students are:"<<endl;
			myfile >> netID[index];
			myfile >> GPA[index];
			myfile >> major[index];
			cout<<netID[index]<<endl;
            cout<< GPA[index]<<endl;
			cout<< major[index]<<endl;
			index ++;
				
			}else {
				cout<<"please check if the netID you have entered is correcty"<<endl;
			}
		}     //Search for a student
			break;
		case 3://Exit the program
			cout << "Exiting \n";
			return 0;
		default:
			cout << "That option is not valid";

		}
	} while (option != '3');
	//Displays arrays through a loop of index
	for (int i=0; i<index; i++)
	{
	cout<<netID[i];
	}
	for (int i = 0; i < index; i++)
	{
		cout << major;
	}
	for (int i = 0; i < index; i++) {
		cout << GPA;
	}
	system("pause");
    return 0;
}

