PA system
CC People :: Studies :: Programming
Page 1 of 2•
Page 1 of 2 • 1, 2 
PA system
How's your pa system progressing?
Here's my one
free to refer, charge on copy! (joking la~)
download link
Here's my one
download link
Last edited by Lion on Thu Mar 27, 2008 12:13 pm; edited 1 time in total
Re: PA system
walao. headache!!! Don't know what I am doing now. Next week need to present, still got many things don't know.
Re: PA system
too bad we all have the presentation together, if not u take my code go present oso can de~
Re: PA system
binary tree search : too complicated to put in the pa system, ignore it
tutorial : thursday nite, wan?
PAsystem : eureka!! i just completed!! wil upload the source code later

tutorial : thursday nite, wan?
PAsystem : eureka!! i just completed!! wil upload the source code later
Re: PA system
i will nvr forget the PA system... as this system make my lp come out with a FREAKING noise... when one problem solved, another one come... grrr~~ geik! 
Re: PA system
now, my problem is -> i dun know how much marks i will get from my presentation.. Aigh, problems are really come one by one.. haha 

Re: PA system
Here is my PA System source code. Can anyone give me some comments over it? Haha, mine is not asadvance as Lion's, but at least fit the requirements of Labs. There are total 3 files here: student.h, functions.cpp and PA_System.cpp.
In "student.h"
In "functions.cpp"
In "PA_System.cpp"
Thank you
In "student.h"
- Code:
#include<iostream>
#include<cstring>
#include<iomanip>
using namespace std;
struct student
{ string name, religious, gender, pob;
int matric, course;
// To print out the list
void print_list()
{ cout<<setiosflags(ios::left)<<" "<<setw(10)<<matric
<<setiosflags(ios::left)<<setw(50)<<name
<<setiosflags(ios::left)<<setw(10)<<course<<endl;
}
// To print out the detail of student
void print_student()
{ cout<<endl<<"+++++++++++++++++++++++++++++++++++++++++++++++++++++++"<<endl;
cout<<"+ THE DETAIL OF THE STUDENT +"<<endl;
cout<<"+++++++++++++++++++++++++++++++++++++++++++++++++++++++"<<endl<<endl;
cout<<" Name : "<<name<<endl;
cout<<" Matric Number : "<<matric<<endl;
cout<<" Course : "<<course<<endl;
cout<<" Gender : "<<gender<<endl;
cout<<" Religious : "<<religious<<endl;
cout<<" Place of Birth : "<<pob<<endl<<endl;
cout<<"+++++++++++++++++++++++++++++++++++++++++++++++++++++++"<<endl<<endl;
}
// Initialization of the constructor
student(int matric, string name, int course, string gender, string religious, string pob);
// A pointer of class student to point to the next object
student *next;
};
// Initialization of the head and tail of the object
student *head = NULL;
student *tail = NULL;
// Constructor of student
student::student(int m, string n, int c, string r, string g, string p)
{ matric = m;
name = n;
course = c;
religious = r;
gender = g;
pob = p;
}
// Check the validity of integer, return error when there is a non-integer input
int GetValidInt(int &integer)
{ char input[64];
bool b = true;
while(b)
{ fflush(stdin);
cin.getline(input,64);
for(int i=0;input[i]!='\0';i++)
{ if(!isdigit(input[i]))
{ b=false;
break;
}
}
if(!b || strlen(input)==0)
{ cout<<"Invalid entry of matric number! Please enter again: ";
b=true;
}
else
{ integer = atoi(input);
return integer;
}
}
}
// Check the validity of the selection
int GetValidSelection(int lower, int upper)
{ char sel[64];
bool b = true;
int j;
while(b)
{ fflush(stdin);
cin.getline(sel,64);
for(int i=0;sel[i]!='\0';i++)
{ if(!isdigit(sel[i]))
{ b=false;
break;
}
}
j = atoi(sel);
if(!b||j<lower||j>upper)
{ cout<<"Invalid input of choice! Please choose your option again: ";
b=true;
}
else
{ break;
}
}
return j;
}
// Chech the existance of the matric number
bool check_matric(int mat)
{ student *check = head;
while(check != NULL)
{ if(check -> matric == mat)
return true;
else
{ check = check -> next;
if(check == NULL)
return false;
}
}
}
In "functions.cpp"
- Code:
#include<iostream>
#include<cstring>
#include<iomanip>
#include<fstream>
#include"student.h"
using namespace std;
int main();
int GetValidMatric();
void empty();
ifstream load;
ofstream save;
// To print out empty list error
void empty()
{ cout<<"It is an empty list! Please add student into the list!"<<endl<<endl;
system("pause");
system("cls");
}
// To print out the student list
void print_student_list()
{ student *temp = head;
int i=1;
while(temp != NULL)
{ cout<<" "<<setw(3)<<i;
i++;
temp -> print_list();
temp = temp -> next;
}
}
// To add student at the beggining of the list
void add_head(student *std)
{ if(tail == NULL)
tail = std;
if(head != NULL)
std -> next = head;
else
std -> next = NULL;
head = std;
}
// To add student at the end of the list
void add_tail(student *std)
{ if(head == NULL)
return add_head(std);
if(tail != NULL)
tail -> next = std;
tail = std;
tail -> next = NULL;
}
// To add student to the list and sort them up
void add_student(student *std)
{ int mat = std -> matric;
if(head == NULL)
add_head(std);
else if(mat < head -> matric)
add_head(std);
else
{ student *here = head;
while(here != tail)
{ if(mat < here -> next -> matric)
{ std -> next = here-> next;
here -> next = std;
return;
}
else
here = here -> next;
}
return add_tail(std);
}
}
// To delete a student in the list
void delete_std()
{ student *temp = head;
if(head == tail)
{ head = NULL;
tail = NULL;
delete temp;
}
else
{ temp = head;
head = head -> next;
}
}
void delete_student(student *std)
{ int mat;
cout<<"Enter the matric number of student that you want to delete: ";
GetValidInt(mat);
while(mat<100000 || mat>200000)
{ cout<<"Invalid entry of matric number! Please enter again: ";
GetValidInt(mat);
}
while(true)
{ check_matric(mat);
if(check_matric(mat) == false)
{ cout<<endl<<"The student is not in the list!"<<endl<<endl;
system("pause");
break;
}
else
{ student *temp = head;
student *temp2 = NULL;
if(temp -> next == NULL)
return delete_std();
else
{ if(temp -> matric == mat)
return delete_std();
else
{ while(temp -> next != temp2)
{ temp2 = temp ->next;
if(temp2 -> matric == mat)
{ temp -> next = temp2 -> next;
delete temp2;
return;
}
else
temp = temp -> next;
}
}
}
}
}
}
// A function to input data
int input_data(int &mat, string &nam, int &cou, string &gen, string &rel, string &place)
{ cout<<"Note: Key in '_' for space bar."<<endl<<endl;
cout<<"Student Name : ";
getline(cin,nam);
fflush(stdin);
cout<<"Student Matric Number : ";
GetValidInt(mat);
while(mat<100000 || mat>150000)
{ cout<<"Invalid entry of matric number! Please enter again: ";
GetValidInt(mat);
}
while(true)
{ check_matric(mat);
if(check_matric(mat) == false)
break;
else
{ cout<<endl<<"This student is in the list! Please enter another student."<<endl<<endl;
system("pause");
return main();
}
}
cout<<"Student Course : ";
GetValidInt(cou);
cout<<"Student Gender : ";
getline(cin,gen);
fflush(stdin);
cout<<"Student Religious : ";
getline(cin,rel);
fflush(stdin);
cout<<"Student Place of Birth : ";
getline(cin,place);
fflush(stdin);
}
// Search a student
student *get_student()
{ int mat;
cout<<"Please enter the matric number of student that you want to search: ";
GetValidInt(mat);
while(mat<100000 || mat>150000)
{ cout<<"Invalid entry of matric number! Please enter again: ";
GetValidInt(mat);
}
student *std = head;
while(std != NULL)
{ if(std -> matric == mat)
return std;
std = std -> next;
}
cout<<"This student is not in the list!"<<endl;
return NULL;
}
In "PA_System.cpp"
- Code:
#include"functions.cpp"
int main()
{ static bool first = true;
int user = 1234;
int pass = 1234;
while(first)
{ cout<<"++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++"<<endl;
cout<<"+ +"<<endl;
cout<<"+ WELCOME TO ACADEMIC ADVISOR SYSTEM +"<<endl;
cout<<"+ +"<<endl;
cout<<"++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++"<<endl<<endl;
cout<<"Please enter your user id and password to log in..."<<endl<<endl;
cout<<" User id : ";
cin>>user;
cout<<" Password : ";
cin>>pass;
if(user == 1234 && pass == 1234)
{ cout<<endl<<"User id and password correct! Logging in..."<<endl<<endl;
system("pause");
}
else
{ cout<<endl<<"Warning: Wrong user id and password!"<<endl<<endl;
cout<<"The system will exit..."<<endl<<endl;
system("pause");
return 0;
}
if(first = false)
{ system("pause");
}
}
student *std;
int choice, mat, cou;
string nam, gen, rel, place;
// Checking
ifstream file("Student List.dat");
string test;
file>>test;
file.close();
if(test != "")
{ // Load student list from Student List.dat
load.open("Student List.dat");
while(!load.eof())
{ load>>mat;
load>>nam;
load>>cou;
load>>gen;
load>>rel;
load>>place;
add_tail(new student(mat, nam, cou, gen, rel, place));
}
load.close();
}
// Print out the student list
system("cls");
cout<<"++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++"<<endl;
cout<<"+ +"<<endl;
cout<<"+ STAFF PROFILE +"<<endl;
cout<<"+ +"<<endl;
cout<<"++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++"<<endl;
cout<<"+ Staff Name : Dr. Syamsiah Mashohor +"<<endl;
cout<<"+ Staff No : A3130 +"<<endl;
cout<<"+ Faculty : Engineering +"<<endl;
cout<<"+ Department : Computer And Communication System Engineering +"<<endl;
cout<<"+ E-mail : syamsiah@eng.upm.edu.my +"<<endl;
cout<<"++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++"<<endl<<endl;
cout<<"++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++"<<endl;
cout<<"+ +"<<endl;
cout<<"+ STUDENT LIST +"<<endl;
cout<<"+ +"<<endl;
cout<<"++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++"<<endl;
cout<<"+"<<setiosflags(ios::left)<<setw(3)<<" No"
<<setiosflags(ios::left)<<setw(11)<<" + Matric"
<<setiosflags(ios::left)<<setw(50)<<"+ Name"
<<setiosflags(ios::left)<<setw(10)<<"+ Program"<<" +"<<endl;
cout<<"++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++"<<endl;
// Shows that whether it is an empty list or not
if(head == NULL)
cout<<" There are no students in the list! "<<endl;
else
print_student_list();
// Menu
cout<<"++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++"<<endl;
cout<<endl<<"++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++"<<endl;
cout<<"+ +"<<endl;
cout<<"+ ACADEMIC ADVISOR MENU +"<<endl;
cout<<"+ +"<<endl;
cout<<"++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++"<<endl;
cout<<" [1] Add a student"<<endl;
cout<<" [2] Delete a student"<<endl;
cout<<" [3] View a student's profile"<<endl;
cout<<" [4] Exit"<<endl<<endl;
cout<<"Please enter your choice: ";
choice = GetValidSelection(1,4);
cout<<endl<<"++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++"<<endl;
if(choice == 1)
{ system("cls");
input_data(mat, nam, cou, gen, rel, place);
std = new student(mat, nam, cou, gen, rel, place);
add_student(std);
return main();
}
else if(choice == 2)
{ if(head == NULL)
empty();
else
delete_student(std);
return main();
}
else if(choice == 3)
{ if(head == NULL)
empty();
else
{ std = get_student();
if(std != NULL)
std -> print_student();
system("pause");
}
return main();
}
else
{ // Clear file
ofstream clear("Student List.dat");
clear<<"";
clear.close();
// Save data before exit
student *std = head;
save.open("Student List.dat");
while(std != NULL)
{ if(std != head)
save<<endl;
save<<std -> matric<<endl;
save<<std -> name<<endl;
save<<std -> course<<endl;
save<<std -> gender<<endl;
save<<std -> religious<<endl;
save<<std -> pob;
std = std -> next;
}
save.close();
// Exit the program
cout<<endl<<"Thank you for using this program!"<<endl<<endl;
system("pause");
}
}
Thank you
Page 1 of 2 • 1, 2 






