#include <iostream>
#include <fstream>
#include <cstring>
#include <cstdlib>
#include <iomanip>
#define C 15
using namespace std;

void SubName(string, string [], string []);
int SubCode(string);

ofstream out;

int main()
{
	int count, num=0, total=0;
	char ID[14], name[30], ID1[14];
	string code[11], fcode[11], fname[11];
	
	cout <<"Please enter the student's Name: ";
	cin.ignore();
	cin.clear();
	cin.getline(name, 30);
	cout << endl;
	
	cout << "Please enter the student's ID: ";
	cin >> ID;
	cout << endl;
	strcpy(ID1, ID);
	strcat(ID,".txt");
	out.open(ID);
	ifstream inp("subjects.txt");
	
	cout << "Please enter the subjects code" << endl;
	int i=0;
	do
	{
		cin.ignore();
		getline(cin, code[i]);
		cout << "Anymore subjects registered?(1-yes 0-no)";
		cin >> count;
		i++;
	}while(count==1);
	
	getline(inp, fcode[0], '\t');
	//inp.ignore('\t');
	getline(inp, fname[0],'\n');
	//inp.ignore('\n');

	for(int r=1; r<11; r++)
	{
		getline(inp, fcode[r],'\t');
		//inp.ignore('\t');
		getline(inp, fname[r],'\n');
		//inp.ignore('\n');
	}

	out << "Name: " << name << "ID: "<< ID1 << endl << endl;
	
	out <<"No\t" << "Subject Code\t" << "Credit Hour\t" << "Subject Name\t"<< endl;
	for (int z=0; z<i; z++)
	{
		out << (z+1) <<"\t" << code[z] <<"\t";
		num+=SubCode(code[z]);
		out<<"\t";
		SubName(code[z], fcode, fname);
		out << endl;
	}
	
	out << "The total credit hours is " << num << endl;
	out.close();
	inp.close();
	return 0;
}

void SubName(string code, string fcode[], string fname[])
{
	for(int j=1; j<11; j++)
	{
		if (code == fcode[j])
		{
			out << fname[j];
		}
		
		else
		continue;
	}	
}

int SubCode(string ode)
{
	char num;
	int p;
	num=ode[7];
	out << setw(13)<< num;
	p=static_cast<int>(num);
	return p;
}




