Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

The goal of this exercise is for your to create your own database. Create a stru

ID: 3824012 • Letter: T

Question

The goal of this exercise is for your to create your own database.

Create a struct of your choosing that has at least two different data types (ie string, int, etc). This struct will represent one "record" in your database.

Create a menu loop that gives the following options:

Print the contents of the database. Make the formatting look decent (you can use <iomanip>).

Append a new record. This will prompt the user to enter the data, then append the struct values to the end of the file.

Search for a record by variable 1. Print out the contents of the record if found. Notify if not found.

Search for a record by variable 2. Print out the contents of the record if found. Notify if not found.

Sort the records by variable 1 and write the contents to the file.

Sort the records by variable 2 and write the contents to the file.

Exit.

Be sure that any changes to the database, ie sorting and/or appending, are written to the database file so they persist after the program is closed. I will be testing this.

A few things to remember:

It may be a simpler design to open the file for a specific purpose, ie in, out, or append, depending on the operation, and then close the file when the operation is complete.

You won't be able to use binary search if the data is not sorted.

If you want to keep the file constantly open, which will be harder to code, you can:

Open an fstream for both reading and writing if you use ios::in | ios::out.

If the file does not already exist, the open will fail with ios::in|ios::out

If the file open fails, you should open with just ios::out so it creates a new file

You can seek to a different byte location in the file using seekg for an ifstream, seekf for an ofstream, and either one for an fstream.

If you use ios::app, every write will go to the end of the file, regardless of whether or not you use seek.

Explanation / Answer

#include struct student { char name[50]; int roll; float marks; } s[10]; int main() { int i; printf("Enter information of students: "); // storing information for(i=0; i
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote