Academia.eduAcademia.edu

COMPUTER SCIENCE PROJECT STUDENT DATA MANAGEMENT SYSTEM

project

COMPUTER SCIENCE PROJECT STUDENT DATA MANAGEMENT SYSTEM KENDRIYA VIDYALAYA, TAWANG Manya & Chandan CERTIFICATE This is to certified to be the bonafide work of the student Manya & Chandan of class XII in computer science in the academic Year 2016-2017 External examiner Internal examiner Acknowledgement TABLE OF CONTENTS DESCRIPTION This project is based on the concept of text files.The project shop management deals with the simple quries of a shopkeeper. It includes four menu options, which are Adding products details Searching and displaying details of a particular product Displaying the details of the products Exit 1) The first menu function allows the user to input the details of the products. 2) The second menu function performs the searching operation and displays the result. 3) The third menu function displays the details of the products. 4) The fourth menu function allows the user to exit from the program. SOURCE CODE #include <iostream> #include <fstream> #include <cstring> using namespace std; class student { private: int rollno; char name[30]; float percent; public: void getdata() { cout << "Enter roll number : " ; cin >> rollno; cout << "Enter name : " ; cin.sync(); cin.clear(); cin.getline(name,30); cout << "Enter percent : " ; cin >> percent; } void putdata() { cout << "Roll Number " << rollno << " Name : " << name << " Percent : " << percent << endl; } int getrollno() { return rollno;} }; //Declare prototype void enter_data(); void display_data(); void edit_data(); void delete_data(); int main() { //clrscr(); int choice; do { cout << "\n1. Enter student data\n" << "2. Display student data\n" << "3. Edit student data\n" << "4. Delete student data\n" << "5. Exit\n" << "\nEnter Choice : " ; cin >> choice; switch (choice) { case 1: enter_data(); break; case 2: display_data(); break; case 3: edit_data(); break; case 4: delete_data(); break; } } while (choice != 5); //getch(); } void enter_data() { student stud1; ofstream outfile("STUDENT.DAT", ios::out | ios::app | ios::binary); char choice; do { stud1.getdata(); outfile.write( (char*)&stud1, sizeof(stud1)); cout << "\nEnter another (y/n) : "; cin >> choice; } while (choice == 'y'); outfile.close(); } void display_data() { student stud1; ifstream infile("STUDENT.DAT", ios::in | ios::binary ); if (! infile) { cout << "File read error\n"; return; } infile.read((char*)&stud1, sizeof(stud1)); while (!infile.eof()) { stud1.putdata(); infile.read((char*)&stud1, sizeof(stud1)); } infile.close(); } void edit_data() { student stud1; fstream file("STUDENT.DAT", ios::in | ios::out | ios::binary); int rollno, found = 0; cout << "Enter roll number of student to edit : "; cin >> rollno; int pos=0; file.read((char*)&stud1, sizeof(stud1)); while(!file.eof()) { if (stud1.getrollno() == rollno) { found = 1; cout << "Details of student are :\n"; stud1.putdata(); cout << "\nEnter new data for the student\n"; stud1.getdata(); file.seekp(pos); file.write((char*)&stud1, sizeof(stud1)); break; } pos = file.tellg(); file.read((char*)&stud1, sizeof(stud1)); } if (found == 0 ) cout << "Student not found\n"; file.close(); } void delete_data() { int rollno, found=0; cout << "Enter roll number whose data is to be deleted : "; cin >> rollno; ifstream infile("STUDENT.DAT", ios::binary); ofstream outfile("TEMP.DAT", ios::binary); student stud1; infile.read((char*)&stud1, sizeof(stud1)); while (!infile.eof()) { if (stud1.getrollno() == rollno) found = 1; else found = 0; if (found == 0) outfile.write((char*)&stud1, sizeof(stud1)); infile.read((char*)&stud1, sizeof(stud1)); } infile.close(); outfile.close(); remove("STUDENT.DAT"); rename("TEMP.DAT", "STUDENT.DAT"); } SCREEN SHOTS Adding a new Student Record Displaying the student records Deleting a student record Editing a student record