Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <fstream>
- #include <string>
- #include <conio.h>
- #include <Windows.h>
- using namespace std;
- // Structure for students
- struct student
- {
- string fname;
- string lname;
- string Registration;
- string ClassMajor;
- string grade;
- int Gpa;
- string GPA;
- string accelarated;
- string studentData;
- string studentName;
- string newGrade;
- string Borrowing_Book;
- }studentData;
- //Classes
- struct classes
- {
- string S_C_math;
- int I_C_M_Math = 50;
- int I_C_math;
- }Class;
- struct teacher
- {
- string fst_name;
- string lst_name;
- string qualification;
- string exp;
- string pay;
- string subj;
- string lec;
- string serves;
- string cel_no;
- }tech[50];
- void getlastLine(string filename)
- {
- ifstream fin;
- fin.open(filename);
- if (fin.is_open()) {
- fin.seekg(-1, ios_base::end);
- bool keepLooping = true;
- while (keepLooping) {
- char ch;
- fin.get(ch);
- if ((int)fin.tellg() <= 1) {
- fin.seekg(0);
- keepLooping = false;
- }
- else if (ch == '\n') {
- keepLooping = false;
- }
- else {
- fin.seekg(-2, ios_base::cur);
- }
- }
- string lastLine;
- getline(fin, lastLine);
- Class.S_C_math = lastLine;
- Class.I_C_math = stoi(lastLine);
- fin.close();
- }
- }
- // Function to add a new student
- void addStudent() {
- ofstream f1("Students.txt", ios::app);
- char choice = 'Y';
- for (int i = 0; choice != 'n' && choice != 'N'; i++) {
- cout << "Enter First name: ";
- cin >> studentData.fname;
- cout << "Enter Last name: ";
- cin >> studentData.lname;
- cout << "Enter Registration number: ";
- cin >> studentData.Registration;
- cout << "Enter class: ";
- cin >> studentData.ClassMajor;
- cout << "Enter Students Gpa: ";
- cin >> studentData.GPA;
- cout << "Enter True if student is borrowing a book enter False if not: ";
- cin >> studentData.Borrowing_Book;
- int Gpa = stoi(studentData.GPA);
- if (Gpa >= 3.6) {
- studentData.accelarated = "True";
- }
- f1 << studentData.fname << endl << studentData.lname << endl << studentData.Registration << endl << studentData.ClassMajor << endl << studentData.GPA << endl << studentData.accelarated << endl << studentData.Borrowing_Book << endl;
- cout << "Do you want to continue Adding student? Y to continue N to stop";
- cin >> choice;
- }
- f1.close();
- }
- // Function to display a student
- void displayStudent() {
- ifstream f2("Students.txt");
- if (!f2.is_open()) {
- cout << "Error opening file 'Students.txt'.";
- return;
- }
- cout << "Enter the first name to be displayed: ";
- string find;
- cin >> find;
- cout << endl;
- int notFound = 0;
- while (getline(f2, studentData.fname)) {
- if (studentData.fname == find) {
- notFound = 1;
- cout << "First Name: " << studentData.fname << endl;
- getline(f2, studentData.lname);
- cout << "Last Name: " << studentData.lname << endl;
- getline(f2, studentData.Registration);
- cout << "Registration Number: " << studentData.Registration << endl;
- getline(f2, studentData.ClassMajor);
- cout << "Class: " << studentData.ClassMajor << endl;
- getline(f2, studentData.GPA);
- cout << "GPA: " << studentData.GPA << endl;
- getline(f2, studentData.accelarated);
- cout << "Accelerated: " << studentData.accelarated << endl << endl;
- }
- }
- f2.close();
- if (notFound == 0) {
- cout << "No Record Found" << endl;
- }
- cout << "Press any key twice to proceed" << endl << endl;
- _getch();
- _getch();
- }
- // Function to add a new teacher
- void addTeacher() {
- ofstream t1("Teachers.txt", ios::app);
- char choice = 'Y';
- for (int i = 0; choice != 'n' && choice != 'N'; i++) {
- cout << "Enter First name: ";
- cin >> tech[i].fst_name;
- cout << "Enter Last name: ";
- cin >> tech[i].lst_name;
- cout << "Enter qualification: ";
- cin >> tech[i].qualification;
- cout << "Enter experience(years): ";
- cin >> tech[i].exp;
- cout << "Enter number of year in this School: ";
- cin >> tech[i].serves;
- cout << "Enter Subject whos teach: ";
- cin >> tech[i].subj;
- cout << "Enter Lecture(per Week): ";
- cin >> tech[i].lec;
- cout << "Enter pay: ";
- cin >> tech[i].pay;
- cout << "Enter Phone Number: ";
- cin >> tech[i].cel_no;
- t1 << tech[i].fst_name << endl << tech[i].lst_name << endl << tech[i].qualification << endl << tech[i].exp << endl << tech[i].serves << endl << tech[i].subj << endl << tech[i].lec << endl << tech[i].pay << endl << tech[i].cel_no << endl;
- cout << "Do you want to enter any more data: ";
- cout << "Press Y to Continue and N to Finish: ";
- cin >> choice;
- }
- t1.close();
- }
- // Function to display a teacher
- void displayTeacher() {
- ifstream t2("Teachers.txt");
- cout << "Enter First name to be displayed: ";
- string find;
- cin >> find;
- cout << endl;
- int notFound = 0;
- int i = 0;
- while (!t2.eof()) {
- getline(t2, tech[i].fst_name);
- if (tech[i].fst_name == find) {
- notFound = 1;
- cout << "First name: " << tech[i].fst_name << endl;
- getline(t2, tech[i].lst_name);
- cout << "Last name: " << tech[i].lst_name << endl;
- getline(t2, tech[i].qualification);
- cout << "Qualification: " << tech[i].qualification << endl;
- getline(t2, tech[i].exp);
- cout << "Experience: " << tech[i].exp << endl;
- getline(t2, tech[i].serves);
- cout << "number of year in this School: " << tech[i].serves << endl;
- getline(t2, tech[i].subj);
- cout << "Subject whos teach: " << tech[i].subj << endl;
- getline(t2, tech[i].lec);
- cout << "Lectures (per Week): " << tech[i].lec << endl;
- getline(t2, tech[i].pay);
- cout << "pay: " << tech[i].pay << endl;
- getline(t2, tech[i].cel_no);
- cout << "Phone Number: " << tech[i].cel_no << endl;
- }
- i++;
- }
- t2.close();
- if (notFound == 0) {
- cout << "No Record Found" << endl;
- }
- cout << "Press any key two times to proceed";
- _getch();
- _getch();
- }
- // Main function
- int main() {
- char choice;
- while (true) {
- cout << "\n\n\t\t\tSCHOOL MANAGEMENT PROGRAM\n\n";
- cout << "Enter your choice: " << endl;
- cout << "1.Students information" << endl;
- cout << "2.Teacher information" << endl;
- cout << "3.Check amount of people in a class" << endl;
- cout << "4.Add or Look For Students Borrowing books" << endl;
- cout << "5.Manage grades" << endl;
- cout << "6.Exit program" << endl;
- cin >> choice;
- switch (choice) {
- case '1':
- addStudent();
- break;
- case '2':
- addTeacher();
- break;
- case '3':
- getlastLine("Class.txt");
- cout << "Math Class: " << Class.S_C_math << "/" << Class.I_C_M_Math << endl;
- cout << "Press any key two times to proceed" << endl;
- _getch();
- _getch();
- break;
- case '4':
- displayStudent();
- break;
- case '5':
- // Manage grades
- cout << "1. Update Math Grade\n";
- cout << "2. View Math Grade\n";
- cout << "Enter your choice: ";
- int choice;
- cin >> choice;
- switch (choice) {
- case 1:
- cout << "Enter student's name: ";
- cin >> studentData.studentName;
- cout << "Enter new grade: ";
- cin >> studentData.newGrade;
- updateMathGrade(studentData.studentName, studentData.newGrade);
- break;
- case 2:
- // View Math Grade
- break;
- default:
- cout << "Invalid choice\n";
- break;
- }
- break;
- case '6':
- exit(0);
- break;
- default:
- cout << "Invalid choice\n";
- break;
- }
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement