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

Complete the following tasks using your Student Management System Database. Depe

ID: 3807193 • Letter: C

Question

Complete the following tasks using your Student Management System Database. Depending on your original design, you might have to alter it to accommodate this assignment or because you notice that these inserts, updates, or deletes are difficult with your design. Please submit 1 .sql file of your SQL statements AND 1 .doc file of your database design diagram copied from SQL Server Management Studio. You should have SQL Statements for the following scenarios. 1. 2 students. (Insert Statements) 2. 3 classes. (Insert Statements) 3. Both students are taking the same class. One of the students is taking another class. (Insert Statements) 4. A student changes his or her major. (Update Statement) 5. A class from the fall semester has no enrollment so it is deleted. (Delete Statement)

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<<" ======================";

cout << " 1. Add Records";

cout << " 2. List Records";

cout << " 3. Modify Records";

cout << " 4. Delete Records";

cout << " 5. Exit Program";

cout<<" ======================";

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 First 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 <<" Name :: " <<e.first_name <<" "<<e.last_name;

//cout << " ";

cout <<" Course :: " <<e.course ;

cout <<" Section :: "<<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);

}

}

em("pause");

return 0;

}