#include <iostream>
#include <cctype>
#include <fstream>
#include <cstring>
#include "ass1.h"

using namespace std;

const int MAXSIZE = 100;
int records = 0;
char Menu();

void ReadFile();
void DisplayRecs();
void AddRecord();
void SearchArray();

struct StudentRec
{
    string Number;
    string GName;
    string FName;
    string subjects[4];
    int results[4];
    int numsubs;
};

StudentRec StudentArray[MAXSIZE];


int main()
{

    bool quit = false;
    do
    {
        switch(Menu())
        {
            case 'r':
                ReadFile();
                break;
            case 'd':
                DisplayRecs();
                break;
            case 'a':
                AddRecord();
                break;
            case 's':
                SearchArray();
                break;
            case 'q':
                quit = true;
                        break;
                    default:
                        cerr << "Invalid command!\n";
        }
    } while(!quit);

    cout << "Thank you for using the student records database" << endl;



    return 0;
}

char Menu()
{
    char cmd;
    cout << "*********************************"<< endl;
    cout << "*    Student Records Database   *"<< endl;
    cout << "*     (r)ead data file          *"<< endl;
    cout << "*     (d)isplay records         *"<< endl;
    cout << "*     (a)dd record to DB        *"<< endl;
    cout << "*     (s)earch records          *"<< endl;
    cout << "*     (q)uit                    *"<< endl;
    cout << "*********************************"<< endl;
    cout << "Command: ";
    cin  >> cmd;
    cin.ignore(100,'\n');
    return tolower(cmd);
}



void ReadFile()
{
    int i = 0, j;   

    {
        ifstream fin;

        fin.open("students.txt");   

        if (fin.fail()) 
        {       
            cerr << "Not sucessful in opening file" << endl;
        }

        cout << "Sucessfull in opening file" << endl;

        fin >> StudentArray[i].Number;


        while (!fin.eof() && fin.good())
        {
            fin >> StudentArray[i].GName;
            fin >> StudentArray[i].FName;
            j = 0;
            fin >> StudentArray[i].subjects[j];
            int len = StudentArray[i].subjects[j].length();
            fin >> StudentArray[i].results[j];

            while (j < 3)
            {
                j++;
                fin >> StudentArray[i].subjects[j];
                len = StudentArray[i].subjects[j].length();
                fin >> StudentArray[i].results[j];
            }

            i++;
            fin >> StudentArray[i].Number;

        }       

        records = i;

        fin.close();
        cout << "There are " << records << " records in the student records database." << "\n" << endl;

    }
}


void DisplayRecs()
{   
    char ans;
    int i,j;
    for (i=0; i < records; i++)
    {   
        cout << "Student No:      " << StudentArray[i].Number << endl;
        cout << "Given Name:  " << StudentArray[i].GName << endl;
        cout << "Family Name: " << StudentArray[i].FName << endl;
        cout << "Subjects:    ";
        for (j=0; j < 4; j++)
        {
            cout << StudentArray[i].subjects[j] << "    ";
        }
        cout << "\n";
        cout << "Results      ";
        for (j=0; j < 4; j++)
        {
            if (StudentArray[i].results[j] <= 44 && StudentArray[i].results[j] >= 0)
            {   
                cout << " F  " << StudentArray[i].results[j] << " ";
            }
            else if (StudentArray[i].results[j] <= 49 && StudentArray[i].results[j] >= 45)
            {   
                cout << "PC  " << StudentArray[i].results[j] << " ";
            }
            else if (StudentArray[i].results[j] <= 64 && StudentArray[i].results[j] >= 50)
            {   
                cout << " P  " << StudentArray[i].results[j] << " ";
            }
            else if (StudentArray[i].results[j] <= 74 && StudentArray[i].results[j] >= 65)
            {   
                cout << " C  " << StudentArray[i].results[j] << " ";
            }
            else if (StudentArray[i].results[j] <= 84 && StudentArray[i].results[j] >= 75)
            {   
                cout << " D  " << StudentArray[i].results[j] << " ";
            }
            else if (StudentArray[i].results[j] <= 100 && StudentArray[i].results[j] >= 85)
            {   
                cout << "HD  " << StudentArray[i].results[j] << " ";
            }
            else
            {   
                cout << "Error Result  " << StudentArray[i].results[j] << "   ";
            }
        }
        cout << "\n";
        cout << "Display next record (y/n): ";


    do
    {
        cin >> ans;

    }while(ans !='y');

}   
}
void AddRecord()
{

}

void SearchArray()
{

}

Edited 3 Years Ago by mike_2000_17: Fixed formatting

Wow! You're so close! Just fill in the last two functions and you're done. Then you'll see that you don't even need our help.

You also need to attach the ass1.h file to your post and give proper code tags...

theres not even any "hello, could you help me with this etc etc" just a command in the title and a buch of code!

well here my problem I cant get the array to read properly e.g it get up to the third piece of text and cant check just two subjects and i have no clue how to do the next two functions
91711912
Cook
Mary
MATH112 46
ELEC113 53
CSCI102 79
ISIT114 48
16171829
Hendley
Mavis
ISIT114 57
MATH112 54
CSCI102 54
CSCI114 70
38473517
Grey
Jim
ISIT114 56
ELEC113 75

void ReadFile();
void DisplayRecs();
void AddRecord();
void SearchArray();
#include <iostream>
#include <cctype>
#include <fstream>
#include <cstring>
#include "ass1.h"

using namespace std;

const int MAXSIZE = 100;
int records = 0;
char Menu();

void ReadFile();
void DisplayRecs();
void AddRecord();
void SearchArray();

struct StudentRec
{
	string Number;
	string GName;
	string FName;
	string subjects[4];
	int results[4];
	int numsubs;
};

StudentRec StudentArray[MAXSIZE];


int main()
{

	bool quit = false;
	do
	{
		switch(Menu())
		{
			case 'r':
				ReadFile();
				break;
			case 'd':
				DisplayRecs();
				break;
			case 'a':
				AddRecord();
				break;
			case 's':
				SearchArray();
				break;
			case 'q':
				quit = true;
                		break;
            		default:
                		cerr << "Invalid command!\n";
		}
    } while(!quit);

    cout << "Thank you for using the student records database" << endl;

	

    return 0;
}

char Menu()
{
	char cmd;
	cout << "*********************************"<< endl;
	cout << "*    Student Records Database   *"<< endl;
	cout << "*     (r)ead data file          *"<< endl;
	cout << "*     (d)isplay records         *"<< endl;
	cout << "*     (a)dd record to DB        *"<< endl;
	cout << "*     (s)earch records          *"<< endl;
	cout << "*     (q)uit                    *"<< endl;
	cout << "*********************************"<< endl;
	cout << "Command: ";
	cin  >> cmd;
	cin.ignore(100,'\n');
	return tolower(cmd);
}



void ReadFile()
{
	int i = 0, j;	

	{
		ifstream fin;
		
		fin.open("students.txt");	
		
		if (fin.fail())	
		{		
			cerr << "Not sucessful in opening file" << endl;
		}
		
		cout << "Sucessfull in opening file" << endl;
		
		fin >> StudentArray[i].Number;
		
		
		while (!fin.eof() && fin.good())
		{
			fin >> StudentArray[i].GName;
			fin >> StudentArray[i].FName;
			j = 0;
			fin >> StudentArray[i].subjects[j];
			int len = StudentArray[i].subjects[j].length();
			fin >> StudentArray[i].results[j];
			
			while (j < 3)
			{
				j++;
				fin >> StudentArray[i].subjects[j];
				len = StudentArray[i].subjects[j].length();
				fin >> StudentArray[i].results[j];
			}

			i++;
			fin >> StudentArray[i].Number;

		}		
		
		records = i;
		
		fin.close();
		cout << "There are " << records << " records in the student records database." << "\n" << endl;
		
	}
}


void DisplayRecs()
{	
	char ans;
	int i,j;
	for (i=0; i < records; i++)
	{	
		cout << "Student No:   	" << StudentArray[i].Number << endl;
		cout << "Given Name:	" << StudentArray[i].GName << endl;
		cout << "Family Name:	" << StudentArray[i].FName << endl;
		cout << "Subjects:	";
		for (j=0; j < 4; j++)
		{
			cout << StudentArray[i].subjects[j] << "	";
		}
		cout << "\n";
		cout << "Results		";
		for (j=0; j < 4; j++)
		{
			if (StudentArray[i].results[j] <= 44 && StudentArray[i].results[j] >= 0)
			{	
				cout << " F  " << StudentArray[i].results[j] << "	";
			}
			else if (StudentArray[i].results[j] <= 49 && StudentArray[i].results[j] >= 45)
			{	
				cout << "PC  " << StudentArray[i].results[j] << "	";
			}
			else if (StudentArray[i].results[j] <= 64 && StudentArray[i].results[j] >= 50)
			{	
				cout << " P  " << StudentArray[i].results[j] << "	";
			}
			else if (StudentArray[i].results[j] <= 74 && StudentArray[i].results[j] >= 65)
			{	
				cout << " C  " << StudentArray[i].results[j] << "	";
			}
			else if (StudentArray[i].results[j] <= 84 && StudentArray[i].results[j] >= 75)
			{	
				cout << " D  " << StudentArray[i].results[j] << "	";
			}
			else if (StudentArray[i].results[j] <= 100 && StudentArray[i].results[j] >= 85)
			{	
				cout << "HD  " << StudentArray[i].results[j] << "	";
			}
			else
			{	
				cout << "Error Result  " << StudentArray[i].results[j] << "	";
			}
		}
		cout << "\n";
		cout << "Display next record (y/n): ";
		
	
	do
	{
		cin >> ans;
		
	}while(ans !='y');
	
}	
}
void AddRecord()
{
	int i = records;
	int j;
	StudentRec temp;
	
	i ++;

	cout << "**********************************************" << endl;
	cout << "	    Add Record to Database" << endl;
	cout<< "***********************************************" << endl;
	cout << "Student No: " << endl;
	cin >> StudentArray[i].Number[j];
	cout << "Given Name: " << endl;
	cin >> StudentArray[i].GName[j];
	cout << "Family Name: " << endl;
	cin >> StudentArray[i].FName[j];
	cout << "Subjects: " << endl;
	cout << "Results: " << endl;
	cout << "\n";
	records = i;
	i++;
	cout << "**********************************************" << endl;
	cout << records << " records are in the database" << endl;
	cout << "**********************************************" << endl;
}

void SearchArray()
{
	
}
This question has already been answered. Start a new discussion instead.