46. Code an application program that keeps track of student information at your
ID: 3694034 • Letter: 4
Question
46. Code an application program that keeps track of student information at your college: their names, identification numbers (the key field), and grade point averages in a fully encapsulated, Linear Quotient Hashed data structure. When launched, the user will be asked to input the maximum size of the data set, the initial number of students, and the initial data set. Once this is complete, the user will be presented with the following menu:
Enter: 1 to insert a new student's information,
2 to fetch and output a student's information,
3 to delete a student's information,
4 to update a student's information,
5 to output all the student information,
and 6 to exit the program.
The program should perform an unlimited number of operations until the user enters a 6 to exit the program. Assume the identification numbers will be in the range 1000 to 50,000.
Need this done in Java please
Explanation / Answer
Solution: please follow these coding as shown in below..
#include<iostream>
#include<fstream>
#include<cstdio>
using namespace std;
class Student
{
int admno;
char name[50];
public:
void setData()
{
cout << " Enter admission no. ";
cin >> admno;
cout << "Enter name of student ";
cin.getline(name,50);
}
void showData()
{
cout << " Admission no. : " << admno;
cout << " Student Name : " << name;
}
int retAdmno()
{
return admno;
}
};
/*
* function to write in a file.
*/
void write_record()
{
ofstream outFile;
outFile.open("student.dat", ios::binary | ios::app);
Student obj;
obj.setData();
outFile.write((char*)&obj, sizeof(obj));
outFile.close();
}
/*
* function to display records of file
*/
void display()
{
ifstream inFile;
inFile.open("student.dat", ios::binary);
Student obj;
while(inFile.read((char*)&obj, sizeof(obj)))
{
obj.showData();
}
inFile.close();
}
/*
* function to search and display from file
*/
void search(int n)
{
ifstream inFile;
inFile.open("student.dat", ios::binary);
Student obj;
while(inFile.read((char*)&obj, sizeof(obj)))
{
if(obj.retAdmno() == n)
{
obj.showData();
}
}
inFile.close();
}
/*
* function to delete a record
*/
void delete_record(int n)
{
Student obj;
ifstream inFile;
inFile.open("student.dat", ios::binary);
ofstream outFile;
outFile.open("temp.dat", ios::out | ios::binary);
while(inFile.read((char*)&obj, sizeof(obj)))
{
if(obj.retAdmno() != n)
{
outFile.write((char*)&obj, sizeof(obj));
}
}
inFile.close();
outFile.close();
remove("student.dat");
rename("temp.dat", "student.dat");
}
/*
* function to modify a record
*/
void modify_record(int n)
{
fstream file;
file.open("student.dat",ios::in | ios::out);
Student obj;
while(file.read((char*)&obj, sizeof(obj)))
{
if(obj.retAdmno() == n)
{
cout << " Enter the new details of student";
obj.setData();
int pos = -1 * sizeof(obj);
file.seekp(pos, ios::cur);
file.write((char*)&obj, sizeof(obj));
}
}
file.close();
}
int main()
{
//Store 5 records in file
for(int i = 1; i <= 5; i++)
write_record();
//Display all records
cout << " List of records";
display();
//Search record
cout << " Search result";
search(100);
//Delete record
delete_record(100);
cout << " Record Deleted";
//Modify record
cout << " Modify Record 101 ";
modify_record(101);
return 0;
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.