check image for better quality. Create a students\' Database (name of the class)
ID: 3534986 • Letter: C
Question
check image for better quality.
Create a students' Database (name of the class) for two courses, PM1 and PM2. Each record in the database, should have data members for first_name(string), last_name(string), student_ID(int), age(int), major(string), grade(int). Each record in the database is an class object of the class Record. The Database should be a linklist, records should be connected by pointer. The database should have following operations: InsertRecord - This method should add a record into the Database. This insertion should be in order according to Student ID (Increasing order of Student ID's). This operation is insertion in Linked List You should be inserting in order only. DeleteRecord : This method should delete a record from the database, you should ask the user for the number to be deleted. Let the record be identified by Student_ID. FindRecord : By entering the Student_ID, one should be able to find the record and display the corresponding details for that particular Student_ID; Overload "Explanation / Answer
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <conio.h>
#include <iomanip>
using namespace std;
int main() {
FILE *fp, *ft;
char another, choice;
struct student {
char first_name[50], last_name[50];
char course[100];
int section;
};
struct student e;
char xfirst_name[50], xlast_name[50];
long int recsize;
fp=fopen("users.txt","rb+");
if (fp == NULL) {
fp = fopen("users.txt","wb+");
if (fp==NULL)
{
puts("Cannot open file");
return 0;
}
}
recsize = sizeof(e);
while(1) {
system("cls");
cout << " ====== STUDENT INFORMATION SYSTEM ======";
cout <<" ";
cout << " ";
cout << " 1. Add Records";
cout << " 2. List Records";
cout << " 3. Modify Records";
cout << " 4. Delete Records";
cout << " 5. Exit Program";
cout << " ";
cout << " Select Your Choice :=> ";
fflush(stdin);
choice = getche();
switch(choice)
{
case '1' :
fseek(fp,0,SEEK_END);
another ='Y';
while(another == 'Y' || another == 'y')
{
system("cls");
cout << "Enter the Firt Name : ";
cin >> e.first_name;
cout << "Enter the Last Name : ";
cin >> e.last_name;
cout << "Enter the Course : ";
cin >> e.course;
cout << "Enter the Section : ";
cin >> e.section;
fwrite(&e,recsize,1,fp);
cout << " Add Another Record (Y/N) ";
fflush(stdin);
another = getchar();
}
break;
case '2':
system("cls");
rewind(fp);
cout << "=== View the Records in the Database ===";
cout << " ";
while (fread(&e,recsize,1,fp) == 1){
cout << " ";
cout <<" " << e.first_name << setw(10) << e.last_name;
cout << " ";
cout <<" " <<e.course << setw(8) << e.section;
}
cout << " ";
system("pause");
break;
case '3' :
system("cls");
another = 'Y';
while (another == 'Y'|| another == 'y')
{
cout << " Enter the last name of the student : ";
cin >> xlast_name;
rewind(fp);
while (fread(&e,recsize,1,fp) == 1)
{
if (strcmp(e.last_name,xlast_name) == 0)
{
cout << "Enter new the Firt Name : ";
cin >> e.first_name;
cout << "Enter new the Last Name : ";
cin >> e.last_name;
cout << "Enter new the Course : ";
cin >> e.course;
cout << "Enter new the Section : ";
cin >> e.section;
fseek(fp, - recsize, SEEK_CUR);
fwrite(&e,recsize,1,fp);
break;
}
else
cout<<"record not found";
}
cout << " Modify Another Record (Y/N) ";
fflush(stdin);
another = getchar();
}
break;
case '4':
system("cls");
another = 'Y';
while (another == 'Y'|| another == 'y')
{
cout << " Enter the last name of the student to delete : ";
cin >> xlast_name;
ft = fopen("temp.dat", "wb");
rewind(fp);
while (fread (&e, recsize,1,fp) == 1)
if (strcmp(e.last_name,xlast_name) != 0)
{
fwrite(&e,recsize,1,ft);
}
fclose(fp);
fclose(ft);
remove("users.txt");
rename("temp.dat","users.txt");
fp=fopen("users.txt","rb+");
cout << " Delete Another Record (Y/N) ";
fflush(stdin);
another = getchar();
}
break;
case '5':
fclose(fp);
cout << " ";
cout << " THANK YOU FOR USING THIS SOFTWARE";
cout << " ";
exit(0);
}
}
system("pause");
return 0;
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.