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:
- Define a class for student (roll no, name, marks).
- Create a binary file and store multiple student
records.
- Accept a roll number from the user.
- Open file using fstream in read/write mode.
- Search for the record using roll number.
- Use seekg() / seekp() to move to correct position.
- Update the marks.
- Write the modified record back to file.
- Display updated record.
🔷 2. Bank Account Management ( RN : 6 TO 10)
Problem: Update balance after withdrawal using account number.
Steps:
- Define account
class(account no, name, balance). - Store multiple records in binary file.
- Accept account number and withdrawal amount.
- Search for matching account.
- Check sufficient balance.
- Move file pointer using seekp().
- Deduct amount and update balance.
- Write updated record back.
- Display updated balance.
🔷 3. Employee Record Modification ( RN : 11 TO 15)
Problem: Modify salary using employee ID.
Steps:
- Define employee
class(ID, name, salary). - Write employee records into file.
- Accept employee ID from user.
- Search record using file pointer movement.
- Locate position using tellg().
- Modify salary.
- Move pointer back using seekp().
- Update record in file.
- Display updated details.
🔷 4. Library Book Issue/Return System ( RN : 16 TO 20)
Problem: Update book status (issued/available).
Steps:
- Define book
class(book ID, title, status). - Store records in binary file.
- Accept book ID and operation (issue/return).
- Search for book record.
- Use seekp() to move pointer.
- Update status field.
- Write updated record back.
- Display updated status.
🔷 5. Railway Reservation System ( RN : 21 TO 25)
Problem: Update seat status.
Steps:
- Define passenger
class(ID, name, seat no, status). - Store passenger records.
- Accept passenger ID or seat number.
- Search corresponding record.
- Move pointer using seekg()/seekp().
- Update seat status (booked/cancelled).
- Rewrite record at same position.
- Display updated reservation.
🔷 6. Hotel Room Booking System ( RN : 26 TO 30)
Problem: Update room availability.
Steps:
- Define room
class(room no, type, availability). - Store room records in file.
- Accept room number.
- Search for room record.
- Use file pointer functions to locate position.
- Update availability (booked/free).
- Write updated record.
- Display room status.
🔷 7. Inventory Price Update ( RN : 31 TO 40)
Problem: Modify product price.
Steps:
- Define product
class(product ID, name, price). - Store product records.
- Accept product ID.
- Search record in file.
- Move pointer to record position.
- Update price.
- Rewrite record using seekp().
- Display updated product details.
🔷 8. Cinema Ticket Booking ( RN : 41 TO 45)
Problem: Update seat booking status.
Steps:
- Define seat
class(seat number, status). - Initialize seats in file.
- Accept seat number from user.
- Search for that seat record.
- Move pointer using seekp().
- Update status (booked/available).
- Write updated record back.
- Display seat status.
🔷 9. Student
Attendance Update System ( RN : 46 TO 55)
Problem:
Update attendance of a student using roll number.
Steps:
- Define a
classfor student (roll no, name, attendance %). - Create a
binary file and store multiple student records.
- Accept roll
number from the user.
- Open file using
fstreamin read/write mode. - Search for the student
record using roll number.
- Use
tellg()to get current position. - Move pointer back using
seekp(). - Update attendance value
(increase/decrease).
- Write updated record back
into the file.
- Display updated student
details.
🔷
10. File-Based Login System ( RN : 56 TO 61)
Problem:
Validate and update user password using random access.
Steps:
- Define a
class(user ID, username, password). - Store
multiple user records in a binary file.
- Accept
username and password from user.
- Search for
matching username in file.
- If found,
verify password.
- If login
successful, ask for new password.
- Use
seekp()to move pointer to exact record. - Update password
field.
- Write
modified record back to file.
- Display
success message.
Comments
Post a Comment