/***************************************** = 0, j = 0; mainEntrance();

/***************************************** Title: Student Record System          ** Author: Ammar Ahmed                   ** IDE: Dev C++ 5.11                     ** Dated: March 07,2017                  ** Website: www.cppbeginner.com          ******************************************/#include #include #include                   // For gotoxy() and Sleep function#include             // For Displaying time#include #include #include #include #include                   // For isalpha() functionusing namespace std;COORD coord = {0,0};              void gotoxy(int x, int y)         //For Setting the position of Cursor{ coord.X = x; coord.Y = y; SetConsoleCursorPosition( GetStdHandle (STD_OUTPUT_HANDLE), coord ); }void time(){ //  FOR current time and date gotoxy(1,10); time_t now; time (&now); cout << " Current Date & Time is: "< 0 )  { username.erase(username.begin() + username.size() -1); cout << " "; j--; } ch2 = getch(); } else{ if(j<10) { cout << ch2; username.push_back(ch2); ch2 = getch(); j++; } else{ ch2 = getch(); } } } gotoxy(36,16); ch=getch(); while(ch != 13){                  // gets input until 'Enter' key is pressed if(ch == ''){ if(password.size() > 0){ password.erase(password.begin() + password.size() -1); cout << " "; i--; } ch = getch(); } else{ if(i<10) { password.push_back(ch); cout << "*";   // For showing stars instead of actual alphabets ch = getch(); i++; } else{ ch = getch(); } } } if (username == "ammar" && password == "12345") { gotoxy(15,16); cout << " Username & Password Matched !! "; cout << " Access Granted... "; cout << " Now Loading: "; loading(); return; } else  { system("cls"); cout << " You entered Wrong UserName/Password "; cout << " Press 'R' or 'r' to Enter Again OR any other key to exit ... "; cin >> retry; if(retry == ‘r’ || retry == ‘R’) { system(“cls”); login(); } else { exit(0); } }}///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// STUDENT CLASS             ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////static int height = 0;class records{ private: struct student { int roll; char name30; char fname30; float cgpa; student *left; student *right; }; public: student *root; records(); void insert(); void display(int); void show1 (student *&); void show4 (student *&); void search(); void deleteRecords(); int remove(int rn, student *&,int &found); void del (student *&nodeptr); void totalNodes(); int findHeight(student *&); void findDepthOfNode(); void studentMenu();};records r;records :: records() { root = NULL; } void records :: insert(){ system(“cls”); label: student *newnode, *nodeptr; char ch; cout << " _________________________RECORDS INSERTION_________________________"; do  { system ("cls"); newnode = new student; cout << " Enter Roll Number of Student: "; while(1) { cin >> newnode->roll; if (cin.fail() || newnode->roll < 1 ) { cin.clear(); cin.ignore(numeric_limits :: max(),’
‘); cout << " Invalid Input... Please Enter a Roll No. greater than or equal to 1: "; } else  break; } student *temp = new student; temp = root; while (temp != NULL) { if(newnode->roll == temp->roll) { cout << " This Roll No. has already been used"; cout << " Please Enter a unique Roll NO. "; system("pause"); goto label; break; } else if(newnode->roll > temp->roll) { temp = temp->right; } else if(newnode->roll < temp->roll) { temp = temp->left; } } label1: cout << " Enter Name of Student: "; cin.ignore(); cin.getline (newnode->name,30); int check1 = 0;for(int i = 0; i < strlen(newnode->name); i++){        if(isalpha(newnode->namei) == 0){        if (newnode->namei == ‘ ‘)        {        check1 = 0; } else {            cout << " Invalid Input... Please Enter alphabets only:";            check1 = 1;            break;        }        }    }    if (check1 == 1)    {    goto label1; } label2: cout << " Enter Father Name of Student: "; cin.getline(newnode->fname,30); int check2 = 0;for(int j = 0; j < strlen(newnode->fname); j++){        if(isalpha(newnode->fnamej) == 0 ){        if (newnode->fnamej == ‘ ‘)        {        check2 = 0; } else {            cout << " Invalid Input... Please Enter alphabets only:";            check2 = 1;            break;        }        }    }    if (check2 == 1)    {    goto label2; } cout << " Enter CGPA of Student (out of 4.0): "; while(1) { cin >> newnode->cgpa; if (cin.fail() || (newnode->cgpa < 0.0) || (newnode->cgpa > 4.0) ) { cin.clear(); cin.ignore(numeric_limits :: max(),’
‘); cout << " Invalid Input... Please Enter CGPA ranging from 0.0 to 4.0: "; } else  break; } newnode->left = NULL; newnode->right = NULL; if (root == NULL) { root = newnode; height++; } else { nodeptr = root; while (nodeptr != NULL) { if (newnode->roll < nodeptr->roll) { if (nodeptr->left != NULL) { nodeptr = nodeptr->left; } else { nodeptr->left = newnode; height++; break; } } else if (newnode->roll > nodeptr->roll) { if(nodeptr->right != NULL) { nodeptr = nodeptr->right; } else { nodeptr->right = newnode; height++; break; } } } } cout << " Do you want to enter more Records ? "; cin >> ch; } while(ch == ‘y’ || ch == ‘Y’); } void records :: show1(student *&temp){ if(temp != NULL) { show1(temp->left); cout << " Roll-No: " << temp->roll; cout << " Name: " << temp->name; cout << " Father's Name: " << temp->fname; cout << " CGPA: " << temp->cgpa; show1(temp->right); }}void records :: show4(student *&temp){ if(temp != NULL) { show4(temp->right); cout << " Roll-No: " << temp->roll; cout << " Name: " << temp->name; cout << " Father's Name: " << temp->fname; cout << " CGPA: " << temp->cgpa; show4(temp->left); }}void records :: display(int choice){ system(“cls”); if(root == NULL) { cout << " Please Enter some Record First... "; return; } cout << " _________________________RECORDS DISPLAY_________________________"; if (choice == 1) { records :: show1(root); } else if (choice == 2) { records :: show4(root); } } void records :: search(){ system("cls"); if (root == NULL) { cout << " Please Enter Some Record First... "; return; } int rn,check = 0; student *temp; cout << " _________________________RECORDS SEARCH_________________________"; cout << " Please Enter Roll No. of Student to Search: "; while(1) { cin >> rn; if (cin.fail() || rn < 1 ) { cin.clear(); cin.ignore(numeric_limits :: max(),’
‘); cout << " Invalid Input... Please Enter a Roll No. greater than or equal to 1: "; } else  break; } temp = root; while(temp != NULL) { if (temp->roll == rn) { cout << " Roll-No: " << temp->roll; cout << " Name: " << temp->name; cout << " Father's Name: " << temp->fname; cout << " CGPA: " << temp->cgpa; check = 1; break; } else if(rn < temp->roll) { temp = temp->left; } else if(rn > temp->roll) { temp = temp->right; } } if (check == 0) { cout << " Record of Student with Roll NO. " << rn << " not Found...! "; return; }}int records :: remove (int rn, student *&nodeptr,int &found){ if (nodeptr == NULL) { return found; } else if(rn < nodeptr->roll) { records :: remove(rn,nodeptr->left,found); } else if (rn > nodeptr->roll) { records :: remove (rn,nodeptr->right,found); } else if (rn == nodeptr->roll) { found = 1; records :: del(nodeptr); } return found;}void records :: del (student *&nodeptr){ student *temp; // if no Child if(nodeptr->left == NULL && nodeptr->right == NULL) { delete nodeptr; nodeptr = NULL; } // if only Left Child else if (nodeptr->right == NULL) { temp = nodeptr; nodeptr = nodeptr->left; delete temp; height–; cout << " RECORD DELETED SUCCESSFULLY... "; } // if only Right Child else if (nodeptr->left == NULL) { temp = nodeptr; nodeptr = nodeptr->right; delete temp; height–; cout << " RECORD DELETED SUCCESSFULLY... "; } else if (nodeptr->right != NULL && nodeptr->left != NULL) { temp = nodeptr->right; while (temp->left != NULL)   // Traversing to find Min { temp = temp->left; } temp->left = nodeptr->left; temp = nodeptr; nodeptr = nodeptr->right; delete temp; height–; cout << " RECORD DELETED SUCCESSFULLY... "; } return; }void records :: deleteRecords(){ system("cls"); int rn,f=0,found=0; if(r.root == NULL) { cout << "Please Enter some Record First...."; return; } cout << " _________________________RECORDS DELETION_________________________"; cout << " Please Enter Roll No. of student to Delete: "; while(1) { cin >> rn; if (cin.fail() || rn < 1 ) { cin.clear(); cin.ignore(numeric_limits :: max(),’
‘); cout << " Invalid Input... Please Enter a Roll No. greater than or equal to 1: "; } else  break; } f=r.remove(rn,r.root,found); if( f== 0) { cout << " Record of Student with Roll NO. " << rn << " not Found...! "; return; } }void records :: totalNodes(){ system("cls"); if (height == 0) { cout << " Please Insert Some Records First..."; return; } else { cout << " Total Number of Students are: " << height; }}void records :: findDepthOfNode(){ system("cls"); int rn; int count = 0; int check = 0; student *temp; if (height == 0) { cout << "Please Enter some Record First...."; return; } else { cout << " _________________________DEPTH OF NODE_________________________"; cout << " Enter Roll No. of Student to Find the Depth of Node: "; while(1) { cin >> rn; if (cin.fail() || rn < 1 ) { cin.clear(); cin.ignore(numeric_limits :: max(),’
‘); cout << " Invalid Input... Please Enter a Roll No. greater than or equal to 1: "; } else  break; } temp = root; while (temp != NULL) { if (temp->roll == rn) { cout << " Depth of Node you Entered starting From Zero is: " << count; check = 1; break; } else if (rn < temp->roll) { temp = temp->left; count++; } else if (rn > temp->roll) { temp = temp->right; count++; } } if(check == 0) { cout << " The Student with Roll No. " << rn << " was not FOUND... "; } }}void records :: studentMenu(){ system("cls"); int choice; while(true) { system("cls"); cout << "   _________________________STUDENT RECORD DATABASE_________________________"; cout << " 1: Enter Record "; cout << " 2: Display Records in Ascending Order"; cout << " 3: Display Records in Descending Order"; cout << " 4: Search Record "; cout << " 5: Delete Record "; cout << " 6: Check Total No. of Students"; cout << " 7: Depth of Specific Node "; cout << " 8: Exit "; cout << " Enter your Choice: "; label1: choice = getch(); if (choice >= ‘1’ && choice <= '9') { goto label2; } goto label1; label2: cout << choice-48; system("cls"); switch(choice) { case '1': r.insert(); cout << " "; system("pause"); break; case '2': r.display(1); cout << " "; system("pause"); break; case '3': r.display(2); cout << " "; system("pause"); break; case '4': r.search(); cout << " "; system("pause"); break; case '5': r.deleteRecords(); cout << " "; system("pause"); break; case '6': r.totalNodes(); cout << " "; system("pause"); break; case '7': r.findDepthOfNode(); cout << " "; system("pause"); break; case '8': exit(0); break; default: cout << " Please Enter a valid Choice: "; system ("pause"); break; } }} int main(){ system("color 0D"); login(); while(true) { system("cls"); r.studentMenu(); } return 0;}