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

USE C++ Create a students\' Database (name of the class) for two courses, PM1 an

ID: 3534985 • Letter: U

Question

USE C++

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:


1. 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.


2. 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.


3. FindRecord : By entering the Student_ID, one should be able to find the record and display the corresponding details for that particular Student_ID;


4. Overload “<<†operator for both the Database and Record Class.

The output when you overload “<<†in Record Class

Record record1; // an object of class Record

Cout<<record1; // should display the information of the student like below:


Student_ID : 12345

First_Name : John

Last_Name : Smith Age : 20

Major: ECE

Grade: A

Output when you overload “<<†in Database Class.

Database PM1;

Cout<<PM1 ; // should display results as shown below:


ID First_Name Last_Name Age Major Grade

12345 John Smith 20 ECE A

12347 Alice Bob 19 Biology B

13456 Cathy Morgan 21 CS C


:

:

://for students in the Database PM1.


5. Overload Equality Operator (==). This operation checks whether two Databases are equal or not. Suppose PM1, PM2 are the objects of the class Database, then IsEqual should return true when the number of records in both Databases are same and all the records also should match, otherwise they are not equal.


6. Create a new object as a copy of the existing object i.e. define a Copy Constructor. Suppose you have two Databases PM1 and PM2, then if you have a new object PM3,

Database PM3 = PM1; // should assign whatever is in Database PM1 to PM3.


7. Created a derived class Grade (This class should inherit from class Record), which will ask user for Grades in 5 assignments, 2 quiz, 2 homeworks and 1 projects and calculates the grade according to the following criteria:

Total = 40% Assigments + 10% Quiz + 25% Homeworks + 25% Project = 100%

Total > 90% ; Grades = A;

Total >80 && Total < 90; Grade = B;

Total >70 && Total < 80 ; Grade = C;

Total > 60 && Total < 70; Grade = D;

Total > 50 && Total < 60; Grade = E;

Total < 50; Grade = F;

The variable ‘grade’ in base class should be set based on this total score.

Hint: Here we give you possbile code structure for Record and Database

class Record

{ private: Record* next;

int student_ID;

string first_name;

string last_name;

int age;

string major;

char grade;

}

class Database

{ public:

/*functions*/

private:

Record * root; // starting record;

}

Explanation / Answer

#include <stdio.h>

#include <string.h>

#include <conio.h>

#include <stdlib.h>

#include <windows.h>


struct student{

char ID[15];

char name[20];

char add[20];

char parname[20];

int Class;

long unsigned int phone_no;

};


struct student stu;


///This will set the forground color for printing in a console window.

void SetColor(int ForgC)

{

WORD wColor;

///We will need this handle to get the current background attribute

HANDLE hStdOut = GetStdHandle(STD_OUTPUT_HANDLE);

CONSOLE_SCREEN_BUFFER_INFO csbi;


///We use csbi for the wAttributes word.

if(GetConsoleScreenBufferInfo(hStdOut, &csbi))

{

///Mask out all but the background attribute, and add in the forgournd color

wColor = (csbi.wAttributes & 0xF0) + (ForgC & 0x0F);

SetConsoleTextAttribute(hStdOut, wColor);

}

return;

}


void ClearConsoleToColors(int ForgC, int BackC)

{

WORD wColor = ((BackC & 0x0F) << 4) + (ForgC & 0x0F);

///Get the handle to the current output buffer...

HANDLE hStdOut = GetStdHandle(STD_OUTPUT_HANDLE);

///This is used to reset the carat/cursor to the top left.

COORD coord = {0, 0};

///A return value... indicating how many chars were written

/// not used but we need to capture this since it will be

/// written anyway (passing NULL causes an access violation).

DWORD count;

///This is a structure containing all of the console info

/// it is used here to find the size of the console.

CONSOLE_SCREEN_BUFFER_INFO csbi;

///Here we will set the current color

SetConsoleTextAttribute(hStdOut, wColor);

if(GetConsoleScreenBufferInfo(hStdOut, &csbi))

{

///This fills the buffer with a given character (in this case 32=space).

FillConsoleOutputCharacter(hStdOut, (TCHAR) 32, csbi.dwSize.X * csbi.dwSize.Y, coord, &count);

FillConsoleOutputAttribute(hStdOut, csbi.wAttributes, csbi.dwSize.X * csbi.dwSize.Y, coord, &count );

///This will set our cursor position for the next print statement.

SetConsoleCursorPosition(hStdOut, coord);

}

return;

}


void SetColorAndBackground(int ForgC, int BackC)

{

WORD wColor = ((BackC & 0x0F) << 4) + (ForgC & 0x0F);;

SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), wColor);

return;

}


COORD coord = {0,0}; ///set the cordinate to 0, 0 (top-left corner of window);

void gotoxy(int x, int y){

coord.X = x; coord.Y = y; /// X and Y coordinates

SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE), coord);

}


void drawRectangle(){

int i, j;

gotoxy(0,0);

printf("%c",201);

for(i = 1; i < 78; i++){

gotoxy(i, 0);

printf("%c",205);

}

gotoxy(78,0);

printf("%c",187);

for(i = 1; i < 25; i++){

gotoxy(78, i);

if(i == 6){

printf("%c",185);

}else{

printf("%c",186);

}

}

gotoxy(78, 25);

printf("%c",188);

for(i = 77; i > 0; i--){

gotoxy(i,25);

if(i == 35){

printf("%c",202);

}else{

printf("%c",205);

}

}

gotoxy(0,25);

printf("%c",200);

for(i = 24; i > 0; i--){

gotoxy(0,i);

if(i == 6){

printf("%c",204);

}else{

printf("%c",186);

}

}


for(i = 1; i < 78; i++){

gotoxy(i,6);

if(i == 35){

printf("%c",203);

}else{

printf("%c",205);

}

}


for(i = 7; i < 25; i++){

gotoxy(35,i);

printf("%c",186);

}


}


void clearWindow(){

int i,j;

for(i = 37; i < 78; i++){

for(j = 7; j < 25; j++){

gotoxy(i,j);printf(" ");

}

}

return;

}


void window(){

drawRectangle();

gotoxy(28,2);

SetColor(35);

printf("STUDENT RECORD SYSTEM");

gotoxy(20,3);

printf("Tribhuvan University, Kathmandu, Nepal");

gotoxy(31,4);

printf("Estd.: 2016 B.S.");

gotoxy(25,24);

SetColor(17);


}


void get_password(char* pass)

{

char temp_passP[25];

int i=0;

while(1)

{

temp_passP[i]=getch();

if(temp_passP[i]==13){break;}

else if(temp_passP[i]==8)

{

if(i!=0) {

printf(" ");

i--;

} else {printf("");}

}

else

{

printf("*");

*(pass+i) = temp_passP[i];

i++;

}

*(pass+i)='';

}

}


void use_pass_field(){

int x = 15, y = 16;

int use;

char pass[10];

SetColor(10);

gotoxy(15,12);printf("The database is password protected.");

gotoxy(15,13);printf(" Enter Valid username and password");

SetColor(17);

gotoxy(20,x);printf("USERNAME:- ");

gotoxy(20,y);printf("PASSWORD:- ");

gotoxy(34,x);scanf("%d",use);

gotoxy(34,y);get_password(pass);

}


void print_heading(const char st[]){

SetColorAndBackground(31,28);

gotoxy(45,8);printf("SRS : %s",st);

SetColorAndBackground(17,15);

}


int conf_record(char id[]){

// left for you

//it checks whether the entered id for

//new record is already in the database.

}


void add_student(){

clearWindow();

print_heading("Add Record");

int print = 37;

FILE *fp;

fp = fopen("record.txt","ab+");

SetColor(45);

if(fp == NULL){

MessageBox(0,"Error in Opening file Make sure your file is not write protected","Warning",0);


}else{

fflush(stdin);

gotoxy(print,10);printf("ID: ");gets(stu.ID);

//here you can confirms the ID

gotoxy(print,12);printf("Name: ");gets(stu.name);

gotoxy(print,14);printf("Address: ");gets(stu.add);

gotoxy(print,16);printf("Parent's name: ");gets(stu.parname);

gotoxy(print,18);printf("Class: ");scanf("%d",&stu.Class);

gotoxy(print,20);printf("Phone Number: ");scanf("%ld",&stu.phone_no);

fwrite(&stu, sizeof(stu), 1, fp);

gotoxy(40,22); printf("The record is sucessfully added");

}

SetColor(28);

fclose(fp);

return;

}


void search_student(){

clearWindow();

print_heading("Search Record");

SetColor(45);

char s_id[15];

int isFound = 0;

gotoxy(37,10);printf("Enter ID to Search: ");fflush(stdin);

gets(s_id);

FILE *fp;

fp = fopen("record.txt","rb");

while(fread(&stu,sizeof(stu),1,fp) == 1){

if(strcmp(s_id,stu.ID) == 0){

isFound = 1;

break;

}

}

if(isFound == 1){

gotoxy(37,12);printf("The record is Found");

gotoxy(37,14);printf("ID: %s",stu.ID);

gotoxy(37,15);printf("Name: %s",stu.name);

gotoxy(37,16);printf("Address: %s",stu.add);

gotoxy(37,17);printf("Parent's Name: %s",stu.parname);

gotoxy(37,18);printf("Class: %d",stu.Class);

gotoxy(37,19);printf("Phone No: %ld",stu.phone_no);

}else{

gotoxy(37,12);printf("Sory, No record found in the database");

}

SetColor(28);

fclose(fp);

return;

}


void mod_student(){

clearWindow();

print_heading("Modify Record");

SetColor(45);

char s_id[15];

int isFound = 0, print = 37;

gotoxy(37,10);printf("Enter ID to Modify: ");fflush(stdin);

gets(s_id);

FILE *fp;

fp = fopen("record.txt","rb+");

while(fread(&stu, sizeof(stu),1,fp) == 1){

if(strcmp(s_id, stu.ID) == 0){

fflush(stdin);

gotoxy(print,12);printf("ID: ");gets(stu.ID);

gotoxy(print,13);printf("Name: ");gets(stu.name);

gotoxy(print,14);printf("Address: ");gets(stu.add);

gotoxy(print,15);printf("Parent's name: ");gets(stu.parname);

gotoxy(print,16);printf("Class: ");scanf("%d",&stu.Class);

gotoxy(print,17);printf("Phone Number: ");scanf("%ld",&stu.phone_no);

fseek(fp,-sizeof(stu), SEEK_CUR);

fwrite(&stu,sizeof(stu), 1, fp);

isFound = 1;

break;

}

}

if(!isFound){

gotoxy(print, 12);printf("No Record Found");

}

fclose(fp);

SetColor(28);

return;

}


void gen_marksheet(){

//left for further enhancement

}


void delete_student(){

clearWindow();

print_heading("Delete Record");

SetColor(45);

char s_id[15];

int isFound = 0, print = 37;

gotoxy(37,10);printf("Enter ID to Modify: ");fflush(stdin);

gets(s_id);

FILE *fp, *temp;

fp = fopen("record.txt","rb");

temp = fopen("temp.txt", "wb");

while(fread(&stu, sizeof(stu),1,fp) == 1){

if(strcmp(s_id, stu.ID) == 0){

fwrite(&stu,sizeof(stu),1,temp);

}

}

fclose(fp);

fclose(temp);

remove("record.txt");

rename("temp.txt","record.txt");

gotoxy(37,12);printf("The record is sucessfully deleted");

SetColor(28);

return;

}


void main_window(){

int choice;

SetColor(28);

int x = 2;

while(1){

gotoxy(x,8);printf("1. Add Student");

gotoxy(x,10);printf("2. Search Student");

gotoxy(x,12);printf("3. Modify Student Record");

gotoxy(x,14);printf("4. Generate Marksheet");

gotoxy(x,16);printf("5. Delete Student Record");

gotoxy(x,18);printf("6. Change password");

gotoxy(x,20);printf("7. Exit");

gotoxy(x,22);printf("Enter your choice: ");

scanf("%d",&choice);

switch(choice){

case 1:

add_student();

break;

case 2:

search_student();

break;

case 3:

mod_student();

break;

case 4:

break;

case 5:

delete_student();

break;

case 6:

break;

case 7:

exit(0);

break;

default:

break;

}


}


}


int main(){

ClearConsoleToColors(17,15);

SetConsoleTitle("hlhk");

window();

//use_pass_field();

main_window();

return 0;

}