/* Written by: D_S (Alex Cottner) Date Finished: 2/6/2006 Description: Program controles database of students */ #include #include #include #include #include struct student { char f_name[25]; char l_name[25]; long int id; char gender; float gpa; }; void intro (); void open_file(int &, student []); void view (int, student []); void add (int &, student []); void del (int &, student []); void sort (int, student []); void swap (int, student []); void alpha (char []); void search (int&, student []); void find (int, student []); int compare (char [], int, char []); void update (int, student []); void write (int, student []); void main () { student list[100]; int menu=0, num_students; intro (); open_file (num_students, list); while (menu<6) { clrscr (); cout << "\n\t1) View Students"; cout << "\n\t2) Add A Student"; cout << "\n\t3) Delete A Student"; cout << "\n\t4) Search For A Student"; cout << "\n\t5) Update Student Information"; cout << "\n\t6) Exit Program"; cout << "\n\n\tWhat would you like to do?"; cin >> menu; switch (menu) { case 1: clrscr (); view (num_students, list); break; case 2: clrscr (); add (num_students, list); break; case 3: clrscr (); del (num_students, list); break; case 4: clrscr (); find (num_students, list); break; case 5: clrscr (); update (num_students, list); break; } } // menu loop write (num_students, list); } // end main // simple introduction void intro () { // sets screan colors textcolor(WHITE); clrscr(); gotoxy (0,10); cout << "\n\tStudent Editor\n"; cout << "\n\n\tVersion .10\n"; delay(2000); cout << "\n\n\n\tProgram stores meaningless infromation on students.\n"; cout << "\n\n\tPress any key to continue."; getch (); clrscr(); } // end of intro void open_file (int &num, student list[]) { ifstream file; file.open("c:\\student.x",ios::in); // gets number of students file >> num; // gets student information for (int i=0; i> list[i].l_name; file >> list[i].f_name; file >> list[i].id; file >> list[i].gender; file >> list[i].gpa; } file.close(); } void view (int num, student list[]) { cout << "Listing student names and information.\n"; // lists students line by line for (int i=0; i> list[num].l_name; alpha(list[num].l_name); cout << "\n\tStudent's first name:\n\t"; cin >> list[num].f_name; alpha (list[num].f_name); cout << "\n\tStudent's ID number:\n\t"; cin >> list[num].id; cout << "\n\tStudent's gender:\n\t"; cin >> list[num].gender; if (list[num].gender>90) list[num].gender-=32; cout << "\n\tStudent's current GPA:\n\t"; cin >> list[num].gpa; num++; sort (num, list); cout << "\n\n\n\tStudent information collected."; cout << "\n\tPress any key to return to the main menu."; getch (); } void del (int &num, student list[]) { char name[25]; int array_num; cout << "\n\n\tEnter the last name of the student you wish to delete:\n\t"; cin >> name; alpha (name); // finds student to delete for (int i=0; i0) { swap (i, list); // switches students change=1; // flag for bubble sort } }// end for loop num--; }while (change>0); } // end sort function // very long and tedious but very simple swap functions void swap (int num, student list[]) { student temp; strcpy (temp.f_name, list[num].f_name); strcpy (temp.l_name, list[num].l_name); temp.id=list[num].id; temp.gender=list[num].gender; temp.gpa=list[num].gpa; strcpy (list[num].f_name, list[num+1].f_name); strcpy (list[num].l_name, list[num+1].l_name); list[num].id=list[num+1].id; list[num].gender=list[num+1].gender; list[num].gpa=list[num+1].gpa; strcpy (list[num+1].f_name, temp.f_name); strcpy (list[num+1].l_name, temp.l_name); list[num+1].id=temp.id; list[num+1].gender=temp.gender; list[num+1].gpa=temp.gpa; } // end swap function // makes all characters uppercase by moving them down the ascii table void alpha (char word[]) { for (int i=0; word[i]!='\0'; i++) { if (word[i]>=95) word[i]-=32; } } // end alpha function // search function used by the other functions void search (int &i, student list[]) { char name[25]; int flag=0; cout << "\n\tEnter the last name of the student.\n\t"; cin >> name; alpha (name); for (i=0; flag<1; i++) { if (strcmp(name, list[i].l_name)==0) flag=1; } } // end search function // fancy ass find function used by the user void find (int num, student list []) { char ltz[25]; int let=0; do{ cout << "\n\tEnter the start of the persons first or last name.\n\t"; for (int x=0; x1)) let-=2; for (int i=0; i0)||(compare (ltz, let, list[i].f_name)>0))&&let>0) { cout << "\n\t"; cout << list[i].l_name << ", "; cout << list[i].f_name << "\t"; cout << list[i].id << "\t"; cout << list[i].gender << "\t"; cout << list[i].gpa; } // end cout if statement } // end for loop to run through student list cout << "\n\n\tEnter a 6 to return to the main menu."; } while (ltz[let-1]!='6'); } // end fancy ass find function int compare (char word[], int size, char temp[]) { // compares the words one letter at a time until something is uneven for (int i=0; temp[i]==word[i]; i++) { } if (i>=size) return 1; else return 0; } // end compare function // updates previous student information void update (int num, student list []) { unsigned int choice; search (num, list); num--; do{ clrscr (); // displays student info for user cout << "\n\t"; cout << list[num].l_name << ", "; cout << list[num].f_name << "\t"; cout << list[num].id << "\t"; cout << list[num].gender << "\t"; cout << list[num].gpa << "\n"; cout << "\n\t1. Last name"; cout << "\n\t2. First name"; cout << "\n\t3. ID Number"; cout << "\n\t4. Gender"; cout << "\n\t5. GPA"; cout << "\n\t6. Exit"; cout << "\n\n\tWhat would you like to change?\t"; cin >> choice; switch (choice) { case 1: cout << "\n\n\tEnter the new last name.\n\t"; cin >> list[num].l_name; alpha (list[num].l_name); break; case 2: cout<< "\n\n\tEnter the new first name.\n\t"; cin >> list[num].f_name; alpha (list[num].f_name); break; case 3: cout << "\n\n\tEnter the new ID number.\n\t"; cin >> list[num].id; break; case 4: cout << "\n\n\tEnter the new Gender.\n\t"; cin >> list[num].gender; if (list[num].gender<95) list[num].gender-=32; break; case 5: cout << "\n\n\tEnter the new GPA.\n\t"; cin >> list[num].gpa; break; }// end switch statement }while(choice<6); } // end update function // writes data to file once user is done void write (int num, student list []) { ofstream file; file.open("c:\\student.x",ios::out); file << num <<'\n'; for (int i=0; i