Ex No - 10 - Random File Access in C++

 Random File Access - (Files must be read and written randomly)


🔷  1. Student Record Update System     ( RN : 1 TO 5)

Problem: Update student marks using roll number.

Steps:

  1. Define a class for student (roll no, name, marks).
  2. Create a binary file and store multiple student records.
  3. Accept a roll number from the user.
  4. Open file using fstream in read/write mode.
  5. Search for the record using roll number.
  6. Use seekg() / seekp() to move to correct position.
  7. Update the marks.
  8. Write the modified record back to file.
  9. Display updated record.

🔷 2. Bank Account Management      ( RN : 6 TO 10)

Problem: Update balance after withdrawal using account number.

Steps:

  1. Define account class (account no, name, balance).
  2. Store multiple records in binary file.
  3. Accept account number and withdrawal amount.
  4. Search for matching account.
  5. Check sufficient balance.
  6. Move file pointer using seekp().
  7. Deduct amount and update balance.
  8. Write updated record back.
  9. Display updated balance.

🔷 3. Employee Record Modification   ( RN : 11 TO 15)

Problem: Modify salary using employee ID.

Steps:

  1. Define employee class (ID, name, salary).
  2. Write employee records into file.
  3. Accept employee ID from user.
  4. Search record using file pointer movement.
  5. Locate position using tellg().
  6. Modify salary.
  7. Move pointer back using seekp().
  8. Update record in file.
  9. Display updated details.

🔷  4. Library Book Issue/Return System   ( RN : 16 TO 20)

Problem: Update book status (issued/available).

Steps:

  1. Define book class (book ID, title, status).
  2. Store records in binary file.
  3. Accept book ID and operation (issue/return).
  4. Search for book record.
  5. Use seekp() to move pointer.
  6. Update status field.
  7. Write updated record back.
  8. Display updated status.

🔷 5. Railway Reservation System   ( RN : 21 TO 25)

Problem: Update seat status.

Steps:

  1. Define passenger class (ID, name, seat no, status).
  2. Store passenger records.
  3. Accept passenger ID or seat number.
  4. Search corresponding record.
  5. Move pointer using seekg()/seekp().
  6. Update seat status (booked/cancelled).
  7. Rewrite record at same position.
  8. Display updated reservation.

🔷 6. Hotel Room Booking System   ( RN : 26 TO 30)

Problem: Update room availability.

Steps:

  1. Define room class (room no, type, availability).
  2. Store room records in file.
  3. Accept room number.
  4. Search for room record.
  5. Use file pointer functions to locate position.
  6. Update availability (booked/free).
  7. Write updated record.
  8. Display room status.

🔷 7. Inventory Price Update   ( RN : 31 TO 40)

Problem: Modify product price.

Steps:

  1. Define product class (product ID, name, price).
  2. Store product records.
  3. Accept product ID.
  4. Search record in file.
  5. Move pointer to record position.
  6. Update price.
  7. Rewrite record using seekp().
  8. Display updated product details.

🔷 8. Cinema Ticket Booking  ( RN : 41 TO 45)

Problem: Update seat booking status.

Steps:

  1. Define seat class (seat number, status).
  2. Initialize seats in file.
  3. Accept seat number from user.
  4. Search for that seat record.
  5. Move pointer using seekp().
  6. Update status (booked/available).
  7. Write updated record back.
  8. Display seat status.

🔷 9. Student Attendance Update System  ( RN : 46 TO 55)

Problem: Update attendance of a student using roll number.

Steps:

  1. Define a class for student (roll no, name, attendance %).
  2. Create a binary file and store multiple student records.
  3. Accept roll number from the user.
  4. Open file using fstream in read/write mode.
  5. Search for the student record using roll number.
  6. Use tellg() to get current position.
  7. Move pointer back using seekp().
  8. Update attendance value (increase/decrease).
  9. Write updated record back into the file.
  10. Display updated student details.

🔷 10. File-Based Login System  ( RN : 56 TO 61)

Problem: Validate and update user password using random access.

Steps:

  1. Define a class (user ID, username, password).
  2. Store multiple user records in a binary file.
  3. Accept username and password from user.
  4. Search for matching username in file.
  5. If found, verify password.
  6. If login successful, ask for new password.
  7. Use seekp() to move pointer to exact record.
  8. Update password field.
  9. Write modified record back to file.
  10. Display success message.

Comments