Click here to Skip to main content
15,867,686 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
#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";
//cout <<"Student-ID  Fullname			Gender  Yearlevel  Course    Birthday  Address            \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){
//NEW NODE

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;

// CHECK IF LIST IS EMPTY
if(*head==NULL)
{
*head = newnode;
return;
}

//TRANSVERSING LIST
student *temp = *head;
while(temp->next!=NULL)
{
temp = temp->next;
}
//add the newnode at the end of the list
temp->next = newnode;
}

void searchrecord(string searchValue,student *head){
	//TEMP NODE POINT TO HEAD
	student* temp=head;
	
	//DECLARE 2 VAR to: TRACK | SEARCH
	int found = 0;
	int i=0;
	
	/*CHECK temp node if NULL else check node DATA with searchValue, 
	if found update and break; 
	else continue searching till temp node is not null */
	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: { //Add New Record 
		cout<<"Adding New Record\n\n";
		addrecord(&head);
		break;
	}
	
	case 2: { //Search Record 
		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: { //Display All Records 
		cout<<"Displaying All Records.....\n\n";
		cout<<"Database Record(s)\n";
		printrecords(head);
		break;
	}
	
	case 4: { //Display Specific Record
		cout<<"Ran case 4\n";
		break;
	}
	
	case 5: { //Delete Record
		cout<<"Ran case 5\n";
		break;
	}
	
	case 6:{ //EXIT
		cout<<"Ran case 6\n";
		cout<<"Exiting Program Have a Good Day!";
		system = true;
		break;
	}
	default:{
		cout <<"\nInvalid Input... \n Try Again...\n";
		break;
	}
	} //end switch
}while(!system);

return 0;
}	// end main


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";
}
Posted
Updated 25-Nov-22 20:55pm
v2
Comments
BernardIE5317 26-Nov-22 4:21am    
As for myself I find it very helpful to design C++ code in a manner which suits "ease of use" and "ease of understanding" and then figure out the language details to make it so. It is all merely a matter of providing all necessary information to compiler and to one's own code to perform requested task whether it be to compile or to execute. I am sorry but can not offer more specific advice as I have not succeeded in understanding the purpose of your code or question. So in summary I recommend ask yourself for each task you wish to execute what information is needed from whence does that information come how it should be processed/calculated with/utilized where it should be stored/passed and its types. -Best

PS If you wish more specific sage advice I perhaps may attempt if I understood the problem/question so provide further explanation if you wish. -Best Again

PPS I do not understand code: if (head->NULL) Kindly advise Thank You

Unless you know the number of elements - which you clearly don't from that code - then the easiest solution is to dump x and when you get to the end of the collection add a break to exit the loop:
C++
if (head->next = NULL){
    head = NULL;
    break;
}
But I'd probably use a while loop instead.

Quote:
The for loop is for the increment of the outputs to go down for it to form a tabular form.
i starts on 5 because as you can see above the code the coordinate of y for the titles are 3 meaning 5 would put the output 2 lines after it.


Ok, the five is justified, but why a for loop? Particularly since you don't use it as a for loop - there is no increment after the body.

What does it give you that this code doesn't, but more obviously?
int lineNo = 5;
while (head != null)
   {
   ...
   lineNo++;
   head = head->next;
   }

Yes, you could use a for loop here instead, but it's harder to read:
for (int lineNo = 5; head != null; lineNo++, head = head-.next)
   {
   ...
   }
And if it's harder to read, it's more prone to mistakes.
Your version tries to nest the two loops and produces something really silly!
Does that make sense now?

Always sit down and think before you dive into code, it will save you hours of head scratching!
 
Share this answer
 
v2
Comments
MrMonsieur 25-Nov-22 9:16am    
wdym? is it that I should incorporate your code with the existing while loop or replace the if statement with while loop.
OriginalGriff 25-Nov-22 10:00am    
You have a for loop inside a while loop: I'd just use a while on it's own, that is all you need.
MrMonsieur 25-Nov-22 10:03am    
how would that look like can you show it to me in code. ty.
OriginalGriff 25-Nov-22 10:10am    
You are kidding, right?
You really can't work that out on your own having written the other code? :omg:
MrMonsieur 25-Nov-22 10:17am    
nope seriously I get confused by it ... tysm
If this was my code, I would write an output function that looks something like this :
C++
template< typename T >
void outputxy( std::ostream & os, int x, int y, const T & v )
{
	gotoxy( x, y );
	os << v;
}
Then, code that looks like this :
C++
gotoxy(0,i);
cout<<head->studentid;
gotoxy(12,i);
cout<<head->fullname;
gotoxy(30,i);
cout<<head->gender;
can look like this :
C++
outputxy(  0, i, head->studentid );
outputxy( 12, i, head->fullname );
outputxy( 30, i, head->gender );
This kind of thing can simplify your code quite a bit.
 
Share this answer
 
void printrecords(student *head){
//cout <<"Student-ID  Fullname			Gender  Yearlevel  Course    Birthday  Address            \n";
system("CLS");

cout<<"Displaying All Records.....\n";
cout<<"Database Record(s)\n";

gotoxy(0,3);
cout<<"Student ID";
gotoxy(12,3);
cout<<"Full Name";
gotoxy(30,3);
cout<<"Gender";
gotoxy(39,3);
cout<<"Year Level";
gotoxy(51,3);
cout<<"Course";
gotoxy(61,3);
cout<<"Birthday";
gotoxy(71,3);
cout<<"Address\n\n";

while(head!=NULL){
	for(int i=5;i<=100 && head!= NULL;i++){
	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;
	
	head = head->next;
	}
cout <<"\n\n";
}
}
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900