#include <iostream>
#include <string.h>
#include <string>
#include <iomanip>
#include <cctype>
#include <ctype.h>
#include <fstream>
#include <cstdlib>
#include <windows.h>
using namespace std;
struct student{
string studentid,yearlevel,fullname,birthday,address,gender,course;
student *next;
};
void mainmenu(){
cout << " [I] Student Information System [I]" << endl;
cout << " | What do you want to do? |" << endl;
cout << " | |" << endl;
cout << " | 1. Add New Record |" << endl;
cout << " | 2. Search Record |" << endl;
cout << " | 3. Display All Records |" << endl;
cout << " | 4. Display Specific Record |" << endl;
cout << " | 5. Delete Record |" << endl;
cout << " | 6. Exit |" << endl;
cout << " ********************************" << endl;
cout << "\t\t\t\t\t Please type your selection:";
}
void border(){
cout <<"////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////"<< endl;
}
void gotoxy(short x,short y){
COORD pos={x,y};
SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE),pos);
}
void printrecords(student *head){
bool x;
cout <<"\n\n";
system("CLS");
gotoxy(0,1);
cout<<"Student ID";
gotoxy(12,1);
cout<<"Full Name";
gotoxy(30,1);
cout<<"Gender";
gotoxy(39,1);
cout<<"Year Level";
gotoxy(51,1);
cout<<"Course";
gotoxy(61,1);
cout<<"Birthday";
gotoxy(71,1);
cout<<"Address\n\n";
while(head!=NULL){
for(int i=2;x != false;){
gotoxy(0,i);
cout<<head->studentid;
gotoxy(12,i);
cout<<head->fullname;
gotoxy(30,i);
cout<<head->gender;
gotoxy(39,i);
cout<<head->yearlevel;
gotoxy(51,i);
cout<<head->course;
gotoxy(61,i);
cout<<head->birthday;
gotoxy(71,i);
cout<<head->address;
i++;
head = head->next;
if (head->NULL){
x=false;
}
}
x = true;
cout <<"\n\n";
}
}
void addrecord(student **head){
student *newnode = new student;
cout <<"Enter Student ID: ";
cin >> newnode->studentid;
cout <<"\nEnter Fullname: ";
cin.ignore();
getline(cin,newnode->fullname);
cout <<"\nEnter Gender (M/F): ";
getline(cin,newnode->gender);
cout <<"\nEnter Yearlevel(1/2/3/4/5): ";
cin >> newnode->yearlevel;
cout <<"\nEnter Course (BS______): ";
cin.ignore();
getline(cin,newnode->course);
cout <<"\nEnter Birthday (MM/DD/YYYY): ";
getline(cin,newnode->birthday);
cout <<"\nEnter Address: ";
getline(cin,newnode->address);
newnode->next = NULL;
if(*head==NULL)
{
*head = newnode;
return;
}
student *temp = *head;
while(temp->next!=NULL)
{
temp = temp->next;
}
temp->next = newnode;
}
void searchrecord(string searchValue,student *head){
student* temp=head;
int found = 0;
int i=0;
if(temp != NULL) {
while(temp != NULL) {
i++;
if(temp->studentid == searchValue) {
found++;
break;
}
temp = temp->next;
}
if (found == 1) {
cout<<"\n "<<searchValue<<" Details:\n";
cout<<searchValue<<" is numbered "<<i<<"on the database.\n";
cout <<"Student-ID Fullname Gender Yearlevel Course Birthday Address \n";
while(temp!=NULL){
cout<<left<<setw(9)<<temp->studentid;
cout<<left<<setw(10)<<temp->fullname;
cout<<left<<setw(10)<<temp->gender;
cout<<left<<setw(10)<<temp->yearlevel;
cout<<left<<setw(10)<<temp->course;
cout<<left<<setw(10)<<temp->birthday;
cout<<left<<setw(10)<<temp->address<<endl;
temp = NULL;
cout<<"\n\n";
}
}
else {
cout<<searchValue<<" is not in the database.\n";
}
} else {
cout<<"Their is no data in the database yet...\n";
}
}
int main(){
int select;
string u,searchValue;
bool system=false;
student *head=NULL;
do{
border();
mainmenu();
cin >> select;
switch (select){
case 1: {
cout<<"Adding New Record\n\n";
addrecord(&head);
break;
}
case 2: {
cout<<"Accessesing Database Records....\n";
cout<<"Input the Student-ID that you would want to search:\n";
cout<<"Student-ID: ";
cin>>searchValue;
searchrecord(searchValue,head);
break;
}
case 3: {
cout<<"Displaying All Records.....\n\n";
cout<<"Database Record(s)\n";
printrecords(head);
break;
}
case 4: {
cout<<"Ran case 4\n";
break;
}
case 5: {
cout<<"Ran case 5\n";
break;
}
case 6:{
cout<<"Ran case 6\n";
cout<<"Exiting Program Have a Good Day!";
system = true;
break;
}
default:{
cout <<"\nInvalid Input... \n Try Again...\n";
break;
}
}
}while(!system);
return 0;
}
In void print records how
What I have tried:
I have tried making other conditions with my for loop
for(int i=2;x != false;i++){ ... x=false;}
but it goes it a loop or it doesn't record the 1st input only the latest
EDIT NEW TRY
I tried this code entering 1,1,1,1,1 and then 2,2,2,2,2
when i search for record i can find both but when I go display it goes blank for this one there is a problem with my code in printrecord I am confused....
while(head!=NULL){
for(int i=2;x != false;){
gotoxy(0,i);
cout<<head->studentid;
gotoxy(12,i);
cout<<head->fullname;
gotoxy(30,i);
cout<<head->gender;
gotoxy(39,i);
cout<<head->yearlevel;
gotoxy(51,i);
cout<<head->course;
gotoxy(61,i);
cout<<head->birthday;
gotoxy(71,i);
cout<<head->address;
i++;
head = head->next;
if (head->next = NULL){
head = NULL;
x=false;
}
}
cout <<"\n\n";
}