# data[].attributes.body
Team Member - G1:

1. MOHD MUIZZUDDIN BIN YUSMAN B011410154?

2. MOHD KHAIRUL NIZAM BIN AMRAN B011410205

3. NAWAWI HAMZA BIN AHMAD AFFENDI B011410228

4. MOHAMMAD EZWAN BIN ELIAS B011410265

5. AHMAD NUZAIHAN BIN MOHD SHUKRI B011410178

Report RECEIVED: 08-01-2015

DEMO: DONE 26-12-2014

CD: Empty

Using CLASS

Data Store: NONE

Input verification & validation: NONE

# data[].attributes.body
Team Member - G2:

1. LUQMAN BIN HASSAN B011410145

2. ZULKARNAEN B. KALET B011410197

3. HIDAYAT BIN MOHAMMAD ADAM B011410137

4. NUR HAPIZUL SYAZWAN BIN MOHD ZIM B011410262

5. MOHAMMAD HIZBULLAH DHIARDDIN BIN HALIM B011410164

6. MUHAMMAD AMIRUL ADIIB BIN AHMAD JOHARI B011410202

Data Store: 1 File ("account.txt") can ONLY store 1 data.

Input Verification & validation: NONE.

System FAIL if user key in char/string instead of numerical input.

Deposit function accept negative number.

Delete function: Error.

Using cin instead of cin.getline() to input Names.

# data[].attributes.body
Team Member - G3:

1. NUR SAFFA WATIQAH BT SAIDUN B011310203

2. NUR ATIA SYAMILA BINTI ABDUL RAZAK B011410172

3. NOR SHAHILA BINTI ALIAS B011410280

4. NUR AZHIRA BINTI RAHIM B011410237

5. AIN NUR UMAIRAH BINTI ABD TALIB B011410256

6. FITRIAH BINTI ALIDIN B011410283

Data Store: 1 File (user.txt)

Input verification & validation: NONE

System is NOT FAIL if the user enter char / string instead of numerical input.

Logic: NOT GOOD.

Using cin instead of cin.getline() to input Names.

# data[].attributes.body
Team Member - G4:

1. MOHD FARIS BIN MOHD SHAM B011410165

2. AHMAD ASYRAF BIN ZAINAL B011410199

3. MUHAMAD RAZALI BIN RAHMAD B011410248

4. MUHAMMAD SYAFIQ BIN MOHD FADZLI B011410238

5. AMRI MOKHTAR BIN MUHD ELIAS B011410104

Data Store: 1 File (bill.txt). The file shall be replaced with new information for each transaction.

Input verification & validation: NONE.

System FAIL if the operator key in char or string instead of numerical input.

# data[].attributes.body
Team Member G5:

1. UMMI FUHAIRAH B011410258

2. NURUL B011410209

2. M. ADLI B011410146

4. M. SYAFIQ B011410219

5. M. AFIQ B011410188

Data Store: NONE

Input verification & validation: NONE.

# data[].attributes.body
Team Member G6:

1. NUR NABILA BINTI ZUBIR B011410103
2. NURUL HUDA HIDAYAT BINTI HASSAN B011410261
3. ANIS IZZATY BINTI AKMALUDDIN B011410247
4. SUHAILAWATI BINTI MOHAMAD B011410141
5. NURUL MAHFUZA BINTI SAMDIN B011410217

Data Store: NONE

Input verification & validation: NONE

The system is the same with G1.

# data[].attributes.body
Team Member G7:
1. NUR AMIRA BINTI ZAMANEE B011410233
2. AQEELA NAZEHA BINTI ZAABA B011410157
3. SUCILAFITRIE BINTI KAFLI B011410170

Data Store: 13 Files --> can be combined into TWO Files.

Input verification & validation: NONE

# data[].attributes.body
Team Member G1:

1. MOHD MUIZZUDDIN B. YUSMAN B011410154

2. MOHAMMAD KHAIRUL NIZAM B. AMRAN B011410205

3. MOHD EZWAN B. ELIAS B011410265

4. NAWAWI HAMZA B. AHMAD AFFANDI B011410228

5. AHMAD NUZAIHAN B011410178

Data Store: NONE

Input verification & validation: NONE

# data[].attributes.body
Team Member G8:

1. FILDZA HELMI BIN RAMLI B011310201

2. MOHD ZULKARNAIN B. BAHARUDIN B011210194

3. MUHAMMAD NUR HAZZIM BIN ABU HANIPAH B011310257

Data Store: 1 File.

# data[].attributes.body
Team Member G9:

1. LEE CHUAN HOW B011410094

2. CHEONG MING KIT B011410126

3. OW WEI LUN B011410117

4. TAN CHENG KWANG B011410095

5. BONG GUANG HUI B011410128

Data store: 1 File ("info.dat")

Withdrawal function: accept negative number.

Demo: Thursday, 18 Dec 2014

# data[].attributes.body
how to bind:

g++ -o manageStudent manageStudent.cpp student.cpp

# data[].attributes.attachment_link.readable_text
#include "student.h"
#include <iostream>
using namespace std;
#include <cstdlib>
#include <windows.h>

void manage_student_menu();
void search_student_menu();

int main()
{
	manage_student_menu();
	system("cls");
	
	return 0;
} //end of main

void search_student_menu()
{
	char choice;
	do
	{
		system("cls");
		cout << "\n Search Student Menu: ";
		cout << "\n 1. Search student by Matric No.";
		cout << "\n 2. Search student by Name";
		cout << "\n 3. BACK \n\n";
		cout << "\n Enter your choice [1..3]: ";
		cin >> choice;
		cin.ignore(100, '\n');
			
		//action taken:
		switch (choice)
		{
			case '1': 		//Search student by Matric No.
				system("cls");
				search_and_displayStudent();
				system("pause");
				break;
					
			case '2':		//Search student by Name
				system("cls");
				search_and_displayStudent_byName();
				system("pause");
				break;
					
			case '3':		//BACK
				break;
					
			default:
				system("cls");
				cout << "\n Invalid input....\n\n";
				system("pause");
				break;
					
		} //end of switch
	}while(choice != '3');
} //end of search_student_menu



void manage_student_menu()
{
	char choice;
	do
	{
		system("cls");
		cout << "\n\n Manage Student Menu: ";
		cout << "\n 1. Add student";
		cout << "\n 2. Update student";
		cout << "\n 3. Search student";
		cout << "\n 4. Display ALL students";
		cout << "\n 5. Delete student";
		cout << "\n 6. EXIT \n";
		cout << "\n Enter your choice [1..6]: ";
		cin >> choice;
		cin.ignore(100, '\n');
			
		//action taken:
		switch (choice)
		{
			case '1': 		//Add student
				system("cls");
				addStudent();
				break;
					
			case '2':		//Update student
				system("cls");
				updateStudent();
				system("pause");
				break;
					
			case '3':		//Search student
				system("cls");
				search_student_menu();
				break;
					
			case '4':		//Display ALL students
				system("cls");
				displayStudents();
				system("pause");
				break;
					
			case '5':		//Delete student
				system("cls");
				deleteStudent();
				system("pause");
				break;
					
			case '6':		//EXIT
				//cout << "\nThank you.....\n\n";
				break;
					
			default:
				system("cls");
				cout << "\n Invalid input....\n\n";	
				system("pause");
			} //end of switch
	}while(choice != '6');
}  //end of manage_student_menu();

//=========END of CODE ===================

# data[].attributes.attachment_link.readable_text
#include "student.h"
#include<iostream>
#include<fstream>
using namespace std;
#include <cstring>

void addStudent()
{
	
	Student record;
	char moreData = 'n';
	
	fstream theFile("student.dat", ios::in | ios::out | ios::app | ios::binary);
	
	do
	{	
		cout << endl;
		cout << "Enter your Matric No.: ";
		cin.getline (record.Matric_No, MATRIC_SIZE, '\n');
		cout << "Enter your name: ";
		cin.getline(record.theName, NAME_SIZE, '\n');
		cout << "Enter your Faculty Code: ";
		cin.getline(record.Faculty_Code, FACULTY_CODE_SIZE, '\n');
		
		//check for Matric No duplication
		while (searchStudent(record.Matric_No) > 0)
		{
			cout << "Matric No has been used...\n";
			cout << "Enter NEW Matric No.: ";
			cin.getline (record.Matric_No, MATRIC_SIZE, '\n');
		}
		
		cout<<"Now writing record"<<endl;
		theFile.seekp(0, ios::end);	//go to the end of file.
		theFile.write(reinterpret_cast<char *>(&record), sizeof(record));
		cout<<"The data has been saved...\n";
		
		cout << "Do you want to add more data [y/n]?: ";
		cin >> moreData;
		cin.ignore(100, '\n');
	} while(moreData == 'Y' || moreData=='y');
	
	theFile.close();

} //end of addStudent



void updateStudent() 
{
	Student record;
	int record_number = 0;
	char theConfirmation = 'n';
	
	cout << endl;
	cout << "Enter your Matric No.: ";
	cin.getline (record.Matric_No, MATRIC_SIZE, '\n');
	record_number = search_and_displayStudent(record.Matric_No);
	cout << "Record Number: " << record_number
		<<endl;
	
	if(record_number >= 0)
	{
		cout << "Enter your name: ";
		cin.getline(record.theName, NAME_SIZE, '\n');
		cout << "Enter your Faculty Code: ";
		cin.getline(record.Faculty_Code, FACULTY_CODE_SIZE, '\n');
		
		cout <<"\n Matric No: " << record.Matric_No;
		cout <<"\n Name: " << record.theName;
		cout <<"\n Faculty: " << record.Faculty_Code;
	
		cout << "\n are you sure to update the record [y/n]? ";
		cin >> theConfirmation;
		if (theConfirmation =='Y' 
			|| theConfirmation =='y')
		{
			fstream theFile("student.dat",
				ios::in | ios::out | ios::binary);
			
			theFile.seekp(record_number * sizeof(record), 
				ios::beg);
			theFile.write(reinterpret_cast<char *>(&record), 
				sizeof(record));
			cout<<"The data has been updated...\n";
			theFile.close();
		}
		else
			cout<<"Cancelled...\n";
	}
} //end of updateStudent


int search_and_displayStudent(char kMatric_No[MATRIC_SIZE])
{ 
	//IS: The file exist and is not empty.
	//FS: if found then record_number >= 0  
	//		and the record shall be displayed
	//	else record_number = -1.
	// and not found message shall be displayed
	
	Student record;
	bool found = false;
	int record_number = 0;
		
	fstream theFile("student.dat", ios::in | ios::binary);
	theFile.read(reinterpret_cast<char *>(&record), sizeof(record));
	
	while(!theFile.eof() && !found)
	{
		if (strcmp(record.Matric_No, kMatric_No)==0)
		{
			found = true;
			continue;
		}
		record_number++;
		theFile.read(reinterpret_cast<char *>(&record), sizeof(record));
	}
	theFile.close();
	
	if(found)
	{
		cout<<"Matric No.: ";
		cout<<record.Matric_No<<endl;
		cout<<"Name: ";
		cout<<record.theName<<endl;
		cout<<"Faculty: ";
		cout<<record.Faculty_Code<<endl<<endl;
	}
	else
	{
		cout << "\n The Matric No. does not exist...\n";
		record_number = -1; 
	}
	return record_number;
} //end of search_and_displayStudent

int searchStudent()
{
	//IS: The file exist and is not empty.
	//FS: if found then record_number >= 0  
	//	else record number = -1.
	Student record;
	char kMatric_No[MATRIC_SIZE];
	bool found = false;
	int record_number = 0;
	
	cout << endl;
	cout << "Enter Matric No.: ";
	cin.getline(kMatric_No, MATRIC_SIZE, '\n');
	
	
	fstream theFile("student.dat", ios::in | ios::binary);
	theFile.read(reinterpret_cast<char *>(&record), sizeof(record));
	
	while(!theFile.eof() && !found)
	{
		if (strcmp(record.Matric_No, kMatric_No)==0)
		{
			found = true;
			continue;
		}
		record_number++;
		theFile.read(reinterpret_cast<char *>(&record), sizeof(record));
	}
	theFile.close();
	
	if(!found)
	{
		cout << "\n The Matric No. does not exist...\n";
		record_number = -1; 
	}
	return record_number;
} //end of searchStudent

int search_and_displayStudent()
{ 
	//IS: The file exist and is not empty.
	//FS: if found then record_number >= 0  
	//		and the record shall be displayed
	//	else record_number = -1.
	// and not found message shall be displayed
	
	Student record;
	char kMatric_No[MATRIC_SIZE];
	bool found = false;
	int record_number = 0;
	
	cout << endl;
	cout << "Enter Matric No.: ";
	cin.getline(kMatric_No, MATRIC_SIZE, '\n');
	
	
	fstream theFile("student.dat", ios::in | ios::binary);
	theFile.read(reinterpret_cast<char *>(&record), sizeof(record));
	
	while(!theFile.eof() && !found)
	{
		if (strcmp(record.Matric_No, kMatric_No)==0)
		{
			found = true;
			continue;
		}
		record_number++;
		theFile.read(reinterpret_cast<char *>(&record), sizeof(record));
	}
	theFile.close();
	
	if(found)
	{
		cout<<"Matric No.: ";
		cout<<record.Matric_No<<endl;
		cout<<"Name: ";
		cout<<record.theName<<endl;
		cout<<"Faculty: ";
		cout<<record.Faculty_Code<<endl<<endl;
	}
	else
	{
		cout << "\n The Matric No. does not exist...\n";
		record_number = -1; 
	}
	return record_number;
} //end of search_and_displayStudent



int searchStudent(char kMatric_No[MATRIC_SIZE])
{
	//IS: The file exist and is not empty.
	//FS: if found then record_number >= 0  
	//	else record number = -1.
	Student record;
	bool found = false;
	int record_number = 0;
		
	fstream theFile("student.dat", ios::in | ios::binary);
	theFile.read(reinterpret_cast<char *>(&record), sizeof(record));
	
	while(!theFile.eof() && !found)
	{
		if (strcmp(record.Matric_No, kMatric_No)==0)
		{
			found = true;
			continue;
		}
		record_number++;
		theFile.read(reinterpret_cast<char *>(&record), sizeof(record));
	}
	theFile.close();
	
	if(!found)
	{
		cout << "\n The Matric No. does not exist...\n";
		record_number = -1; 
	}
	return record_number;
} //end of searchStudent(char kMatric_No[MATRIC_SIZE])



int search_and_displayStudent_byName()
{
	//IS: The file exist and is not empty.
	//FS: if found then record_number >= 0  
	//		and the record shall be displayed
	//	else number of students = 0
	// and not found message shall be displayed
	
	Student record;
	char theName[NAME_SIZE];
	bool found = false;
	int number_of_students = 0;
	
	
	cout << endl;
	cout << "Enter part of the Name: ";
	cin.getline(theName, NAME_SIZE, '\n');
	
	
	fstream theFile("student.dat", ios::in | ios::binary);
	theFile.read(reinterpret_cast<char *>(&record), sizeof(record));
	
	while(!theFile.eof() )
	{
		if (strstr(record.theName, theName))
		{
			found = true;
			cout<<"\nMatric No.: ";
			cout<<record.Matric_No<<endl;
			cout<<"Name: ";
			cout<<record.theName<<endl;
			cout<<"Faculty: ";
			cout<<record.Faculty_Code<<endl<<endl;
			number_of_students++;
		}
		theFile.read(reinterpret_cast<char *>(&record), sizeof(record));
	}
	theFile.close();
	
	if(!found)
		cout << endl << theName << " does not exist...\n";
	else
		cout << "\nNumber of students whose names contain " << theName 
			<< " = " << number_of_students << endl << endl;
			
	return number_of_students;
} //end of search_and_displayStudent_byName


void displayStudents()
{
	Student record;
	int number_of_students = 0;
	
	fstream theFile("student.dat", ios::in | ios::binary);
	theFile.read(reinterpret_cast<char *>(&record), sizeof(record));
	
	while(!theFile.eof())
	{
		number_of_students++;
		cout<<"Matric No.: ";
		cout<<record.Matric_No<<endl;
		cout<<"Name: ";
		cout<<record.theName<<endl;
		cout<<"Faculty: ";
		cout<<record.Faculty_Code<<endl<<endl;
		theFile.read(reinterpret_cast<char *>(&record), sizeof(record));
	}
	theFile.close();
	cout << "\n Number of students = " << number_of_students << endl << endl;
} //end of displayStudents


void deleteStudent()
{
	Student record;
	int record_number = 0;
	char theConfirmation = 'n';
	char kMatric_No[MATRIC_SIZE];
	
	cout << endl;
	cout << "Enter your Matric No.: ";
	cin.getline (kMatric_No, MATRIC_SIZE, '\n');
	record_number = search_and_displayStudent(kMatric_No);
	
	if(record_number >= 0)
	{
		cout << "\n are you sure to delete the record [y/n]? ";
		cin >> theConfirmation;
		if (theConfirmation =='Y' 
			|| theConfirmation =='y')
		{
			//how to delete the record.
			//copy all data into tmp.dat file
			//except the deleted record.
			//delete sudent.dat file.
			//rename tmp.data file to sudent.dat file
		
			fstream theinputFile("student.dat", 
				ios::in | ios::binary);
			theinputFile.read(reinterpret_cast<char *>(&record), 
				sizeof(record));
			
			fstream theoutputFile("tmp.dat", 
				ios::out | ios::binary);
			
			while(!theinputFile.eof())
			{
				if(strcmp(kMatric_No, record.Matric_No)!= 0)
				{
					theoutputFile.write(reinterpret_cast<char *>(&record), 
						sizeof(record));
				}	
				theinputFile.read(reinterpret_cast<char *>(&record), sizeof(record));
			}
			theinputFile.close();
			theoutputFile.close();
			if (remove("student.dat") != 0)
			cout << "\n can not remove the file....\n ";
		
			if (rename("tmp.dat","student.dat") !=0)
			cout << "\n can not rename the file....\n ";
		}
		else
			cout<<"Cancelled...\n";		
	}
}













# data[].attributes.attachment_link.readable_text
#ifndef STUDENT_H
#define STUDENT_H
 
const int MATRIC_SIZE = 11;
const int NAME_SIZE = 50;
const int FACULTY_CODE_SIZE = 10;

struct Student
{
	char Matric_No[MATRIC_SIZE];
	char theName[NAME_SIZE];
	char Faculty_Code[FACULTY_CODE_SIZE];

};

void addStudent();//
int searchStudent(char kMatric_No[MATRIC_SIZE]);//

void updateStudent();//
int search_and_displayStudent(char kMatric_No[MATRIC_SIZE]);//


int searchStudent();//
//int searchStudent(char Matric_No[MATRIC_SIZE]);
int search_and_displayStudent();//
int search_and_displayStudent(char kMatric_No[MATRIC_SIZE]);
int search_and_displayStudent_byName();

void displayStudents();

void deleteStudent();
//int search_and_displayStudent(char kMatric_No[MATRIC_SIZE]);
	


 
#endif

# data[].attributes.body
Dear Students, The lecture session for today, 08 Dec 2014 at 14.00-16.00 and Lab session for tomorrow, 09 Dec 2014 08.00 - 10.00 are canceled. Focus to finish your project. Please be kindly informed. Muhammad Suryanata

Lecturer FTMK - UTeM