/* This the main menu program file which display the main
menu screen with a graphics mode */
#include<iostream.h>
#include<fstream.h>
#include <conio.h>
#include <string.h>
#include <iomanip.h>
# include "graphics.h"
# include "math.h"
# include "dos.h"
# include "process.h"
# include "alloc.h"
# include "stdlib.h"
# include "ctype.h"
# include "stdio.h"
# include "fcntl.h"
/* The student.cpp file is treated as library file which is included
in this main menu.cpp program. So, to utilize the files functions include
this file in your C++ directory as TURBOC3 or TC or TC++ etc.. */
//#include "c:\turboc3\student.cpp"
//#include"d:\c__pro~1\student.cpp"
struct s_date // Structure to declare a date type data
{
int dd;
int mm;
int yy;
};
// Class contains the student mameber function and data memebers of student
class student
{
public:
void enter_student();
void add_student(int, char s_name[30], char s_address[30], char s_fname[30],s_date s_dob ,char s_class[3]); // For students information
void display_student(void); // Displaying students register
void delete_student(); // Deleting students registration
void modify_student(int, char s_name[30], char s_address[30], char s_fname[30]); // To modify the students infomation
void mod_new(void); // For modifying the student
int found_student(int); // Finding any student
private:
int redgno; // Registration number
char name[30]; // Name of the student
char address[30]; // Address of the student
char f_name[30]; // Father's name
s_date dob; // Date of birth
char clas[3]; // Registration class
};
// Class contains the marks and division of the student
class marks
{
int redgno; // Registration number
int sub1; // Marks for subject1
int sub2; // Marks for subject2
int sub3; // Marks for subject3
int sub4; // Marks for subject4
int sub5; // Marks for subject5
int total; // Total marks
float aggregate; // Percentage of marks
char division[10]; // Division of student
char st_code[3]; // Stream code (ar-Arts, sc-Science, co-Commerce)
public:
void read_marks(); // Read students data
void show_marks(); // Shows individual students result
void display_marks(); // Displays all the students marksheet
void delete_marks(); // Deletes students marks
void modify_marks(int t_redg, int m1, int m2, int m3,int m4,int m5,int tot,char div[10]);
void mod_marks(); // Modification of marks
int found_marks(int); // search the record in file
};
// Function to add record in student file
void student::add_student(int t_redg, char s_name[30], char s_address[30], char s_fname[30], s_date s_dob,char s_class[3])
{
redgno = t_redg;
strcpy(name, s_name);
strcpy(address, s_address);
strcpy(f_name, s_fname);
strcpy(clas,s_class);
dob = s_dob;
fstream sfile;
// append the record in SUDE.dat data file
sfile.open("STUD.dat", ios::out|ios::app);
sfile.write((char *)this, sizeof(student));
sfile.close();
}
// Function for returning the record no. for updating student details
int student::found_student(int t_redg)
{
fstream sfile;
sfile.open("STUD.dat", ios::in);
sfile.seekg(0, ios::beg);
int count = 0; // Will be count total number of records in STUD.dat data file
while (sfile.read((char *)this, sizeof(student)))
{
count++;
if (t_redg == redgno)
break;
}
sfile.close();
return count;
}
// Function Modify the data of the student
void student::mod_new(void)
{
int t_redg,flag=0;
char t_name[30];
char t_address[30];
char t_fname[30];
gotoxy(20, 10);
cout << "Enter student registration no. ";
cin >> t_redg;
fstream sfile;
// Opens the file on reading mode
sfile.open("STUD.dat", ios::in);
// Sets the file pointer at the beginning of the file
sfile.seekg(0, ios::beg);
while (sfile.read((char *)this, sizeof(student)))
{
if (t_redg == redgno)
{
gotoxy(22, 12);
cout << "Name is " << name;
gotoxy(22, 14);
cout << "Address is " << address;
flag = 1;
gotoxy(22, 16);
cout << "Enter name : ";
gets(t_name);
strupr(t_name);
gotoxy(22, 18);
cout << "Enter address : ";
gets(t_address);
strupr(t_address);
break;
}
}
sfile.close();
if (flag == 1)
{
gotoxy(22, 20);
// Passes parameter values into modify_student function for rewrite the student information
modify_student(t_redg, t_name, t_address, t_fname);
cout << "Record modified";
}
else
{
gotoxy(22, 20);
cout << "Record not modified";
}
gotoxy(20, 22);
cout << "Press any key to continue...";
getch();
}
// Function for updating the modified students information into STUD.dat file
// after receiving the information from mod_new() function.
void student::modify_student(int t_redg, char t_name[30], char t_address[30], char t_fname[30])
{
int find_rec;
find_rec = found_student(t_redg);
fstream sfile;
// Opens the file for rewrite mode
sfile.open("STUD.dat", ios::out|ios::ate);
strcpy(name, t_name);
strcpy(address, t_address);
strcpy(f_name, t_fname);
int location;
location = (find_rec-1) * sizeof(student);
// Positioned the pointer at location place
sfile.seekp(location);
// Rewrite the modified record at its location place
sfile.write((char *)this, sizeof(student));
sfile.close();
return;
}
/* Function for deleting a student from STUD.dat file */
void student::delete_student()
{
int t_redg;
int flag = 0; // To validate the student record deleted or not
fstream sfile;
sfile.open("STUD.dat", ios::in);
fstream temp;
temp.open("TEMP.dat", ios::out);
sfile.seekg(0, ios::beg);
gotoxy(20, 10);
cout << "Enter the registration number to be deleted : ";
cin >> t_redg;
while (!sfile.eof())
{
sfile.read((char *)this, sizeof(student));
if (sfile.eof())
break;
if (redgno != t_redg)
temp.write((char *)this, sizeof(student));
// Initialize the flag 1 if record found
if (redgno == t_redg)
flag = 1;
}
sfile.close();
temp.close();
sfile.open("STUD.dat", ios::out);
temp.open("TEMP.dat", ios::in);
temp.seekg(0, ios::beg);
while (!temp.eof())
{
temp.read((char *)this, sizeof(student));
if (temp.eof())
break;
if (redgno != t_redg)
sfile.write((char *)this, sizeof(student));
}
sfile.close();
temp.close();
if (flag == 1)
{
gotoxy(20, 16);
cout << "Record Deleted ";
gotoxy(20, 16);
cout << "Press any key to continue...";
getch();
}
else
{
gotoxy(20, 16);
cout << "Record not found !!! ";
getch();
}
}
// Function for displaying all the registered students information
void student::display_student(void)
{
int flag;
gotoxy(25, 2);
cout << "Students Registration List";
gotoxy(25, 3);
cout << "==========================";
int d1, m1, y1;
struct date d; // For extracting system date
getdate(&d);
d1 = d.da_day;
m1 = d.da_mon;
y1 = d.da_year;
gotoxy(62, 3);
cout << "Date: " << d1 << "/" << m1 << "/" << y1;
gotoxy(2, 4);
for (int j = 2; j <= 78; j++)
cout << "=";
gotoxy(2, 5);
cout << "Redg#";
gotoxy(10, 5);
cout << "Name";
gotoxy(20, 5);
cout << "Address";
gotoxy(40, 5);
cout << "Father Name";
gotoxy(60, 5);
cout << "D_O_B";
gotoxy(70, 5);
cout << "Class";
gotoxy(2, 6);
for (j = 2; j <= 78; j++)
cout << "=";
fstream sfile;
sfile.open("STUD.dat", ios::in);
sfile.seekg(0,ios::beg);
int row = 7;
while (sfile)
{
sfile.read((char *)this, sizeof(student));
if (!sfile)
break;
flag = 0;
delay(2);
gotoxy(3, row);
cout << redgno;
gotoxy(10, row);
puts(name);
gotoxy(20, row);
puts(address);
gotoxy(40, row);
cout << f_name;
gotoxy(60, row);
cout << dob.dd << "-" << dob.mm << "-" << dob.yy;
gotoxy(70, row);
cout << clas;
if (row == 23)
{
flag = 1;
row = 6;
gotoxy(4, 24);
cout << "Press any key to continue.... ";
getch();
clrscr();
}
row++;
}
gotoxy(2, row);
for (j = 2; j <= 78; j++)
cout << "=";
sfile.close();
if (!flag)
{
gotoxy(4, 24);
cout << "Press any key to continue...";
getch();
}
getch();
}
//Function to add record in marks.dat
void marks::read_marks()
{
float per;
char ch = 'Y';
fstream file;
file.open("Mark.dat", ios::out|ios::app);
do
{
// Sets the current viewport for graphics output
setviewport(7, 24, getmaxx()-50, getmaxy()-50,1);
// Clears the current viewport
clearviewport();
gotoxy(20, 6);
cout << "Marks Data Entry Form";
gotoxy(20, 7);
cout << "=======================";
gotoxy(10, 8);
cout << "Registration number ";
gotoxy(10, 10);
cout << "Subject 1 : ";
gotoxy(10, 12);
cout << "subject 2 : ";
gotoxy(10, 14);
cout << "Subject 3 : ";
gotoxy(10, 16);
cout << "subject 4 : ";
gotoxy(10, 18);
cout << "Subject 5 : ";
gotoxy(10, 20);
cout << "Stream code: ";
gotoxy(30, 8);
cin >> redgno;
gotoxy(30, 10);
cin >> sub1;
gotoxy(30, 12);
cin >> sub2;
gotoxy(30, 14);
cin >> sub3;
gotoxy(30, 16);
cin >> sub4;
gotoxy(30, 18);
cin >> sub5;
gotoxy(30, 20);
cin >> st_code;
// Calculates the total marks
total = sub1 + sub2 + sub3 + sub4 + sub5;
// Calculates the percentage marks for division
per = total / 5;
if (per >= 60)
strcpy(division, "first");
else
if ((per<60) && (per >= 50))
strcpy(division, "second");
else
if ((per<50) && (per>=33))
strcpy(division, "third");
else
strcpy(division, "fail");
file.write((char *)this, sizeof(marks));
gotoxy(10, 22);
cout << "Want More Record ? : ";
cin >> ch;
} while (ch == 'Y' || ch == 'y');
file.close();
}
// Function to display the marks of all the student from marks.dat data file
void marks::display_marks()
{
int flag;
fstream file;
gotoxy(35, 2);
cout << "Marks List";
gotoxy(25, 3);
cout << "==========================";
int d1, m1, y1;
struct date d; // For extracting system date
getdate(&d);
d1 = d.da_day;
m1 = d.da_mon;
y1 = d.da_year;
gotoxy(62, 3);
cout << "Date: " << d1 << "/" << m1 << "/" << y1;
gotoxy(2, 4);
for (int j = 2; j <= 78; j++)
cout << "=";
gotoxy(2, 5);
cout << "Regis.no.";
gotoxy(15, 5);
cout << "Sub1";
gotoxy(25, 5);
cout << "Sub2";
gotoxy(35, 5);
cout << "Sub3";
gotoxy(45, 5);
cout << "Sub4";
gotoxy(53, 5);
cout << "Sub5";
gotoxy(60, 5);
cout << "Total";
gotoxy(70, 5);
cout << "Division";
gotoxy(2, 6);
for (j = 2; j <= 78; j++)
cout << "=";
// Opens the file for reading mode
file.open("mark.dat", ios::in);
file.seekg(0,ios::beg);
int row = 7;
while (file.read((char *)this, sizeof(marks)))
{
flag = 0;
delay(2);
gotoxy(3, row);
cout << redgno;
gotoxy(15, row);
cout << sub1;
gotoxy(25, row);
cout << sub2;
gotoxy(35, row);
cout << sub3;
gotoxy(45, row);
cout << sub4;
gotoxy(53, row);
cout << sub5;
gotoxy(60, row);
cout << total;
gotoxy(70, row);
cout << division;
if (row == 23)
{
flag = 1;
row = 6;
gotoxy(4, 24);
cout << "Press any key to continue.... ";
getch();
clrscr();
}
row++;
}
gotoxy(2, row);
for (j = 2; j <= 78; j++)
cout << "=";
file.close();
if (!flag)
{
gotoxy(4, 24);
cout << "Press any key to continue...";
getch();
}
}
// Function to display the marks of single student.
void marks :: show_marks()
{
int t_reg;
fstream file;
// Opens the file for reading mode
file.open("mark.dat", ios::in);
int maxx;
int maxy;
maxx = getmaxx();
maxy = getmaxy();
gotoxy(20, 10);
cout << "Enter the student registration number : ";
cin >> t_reg;
while (file)
{
file.read((char *)this, sizeof(marks));
if (t_reg == redgno)
{
setviewport(0, 0, maxx, maxy, 1);
clearviewport();
gotoxy(26, 3);
cout << "N.G.F.Public School";
gotoxy(28, 4);
cout << "Examination 2000";
gotoxy(18, 6);
cout << "Registration No : " << redgno;
gotoxy(18, 9);
cout << "Stream: ";
if (strcmp(st_code, "sc") == 0)
{
gotoxy(26, 9);
cout << "Science stream";
}
if (strcmp(st_code, "co") == 0)
{
gotoxy(28, 9);
cout << "Commerce stream";
}
if (strcmp(st_code, "ar") == 0)
{
gotoxy(28, 9);
cout << "Arts stream";
}
int d1, m1, y1;
struct date d; // For extracting system date
getdate(&d);
d1 = d.da_day;
m1 = d.da_mon;
y1 = d.da_year;
gotoxy(48, 9);
cout << "Date: " << d1 << "/" << m1 << "/" << y1;
gotoxy(18, 10);
cout << "-----------------------------------------------";
gotoxy(18, 12);
cout << "Subject";
gotoxy(38, 12);
cout << "Max Marks";
gotoxy(48, 12);
cout << "Marks obtained";
gotoxy(18, 13);
cout << "-----------------------------------------------";
if (strcmp(st_code, "sc") == 0)
{
gotoxy(18, 16);
cout << "English";
gotoxy(18, 17);
cout << "Mathematics";
gotoxy(18, 18);
cout << "physics";
gotoxy(18, 19);
cout << "Chemistry";
gotoxy(18, 20);
cout << "Biology";
}
if (strcmp(st_code, "co") == 0)
{
gotoxy(18, 16);
cout << "Accounts";
gotoxy(18, 17);
cout << "Business Studies";
gotoxy(18, 18);
cout << "English";
gotoxy(18, 19);
cout << "Economics";
gotoxy(18, 20);
cout << "Computers";
}
if (strcmp(st_code, "ar") == 0)
{
gotoxy(18, 16);
cout << "History";
gotoxy(18, 17);
cout << "Political science";
gotoxy(18, 18);
cout << "Hindi";
gotoxy(18, 19);
cout << "English";
gotoxy(18, 20);
cout << "Economics";
}
gotoxy(52, 16);
cout << sub1;
gotoxy(52, 17);
cout << sub2;
gotoxy(52, 18);
cout << sub3;
gotoxy(52, 19);
cout << sub4;
gotoxy(52, 20);
cout << sub5;
int col, row, i, j;
col = 40;
row = 16;
for (i = 0; i < 5; i++)
{
gotoxy(col, row);
cout << "100";
row++;
}
gotoxy(18, 21);
cout <<"----------------------------------------------";
gotoxy(18, 22);
cout << "Total : ";
gotoxy(40, 22);
cout << "500";
gotoxy(52, 22);
cout << total;
gotoxy(18, 23);
cout << "Division : " << division;
}
}
fstream afile;
// Opens the file for reading mode
afile.open("stud.dat", ios::in);
student stud;
file.close();
getch();
}
// Function to delete the marks from marks.dat
// The marks of student deleted accourding the registration number only with a
// copy method through TEMP.dat data file
void marks::delete_marks()
{
int t_redg;
int flag = 0;
fstream file;
file.open("mark.dat", ios::in);
fstream temp;
temp.open("TEMP.dat", ios::out);
file.seekg(0, ios::beg);
gotoxy(20, 10);
cout << "Enter the registration number of the student : ";
cin >> t_redg;
while (!file.eof())
{
file.read((char *)this, sizeof(marks));
if (file.eof())
break;
if (redgno != t_redg)
temp.write((char *)this, sizeof(marks));
// Sets the flat 1 if record found
if (redgno == t_redg)
flag = 1;
}
file.close();
temp.close();
file.open("mark.dat", ios::out);
temp.open("TEMP.dat", ios::in);
temp.seekg(0, ios::beg);
while (!temp.eof())
{
temp.read((char *)this, sizeof(marks));
if (temp.eof())
break;
if (redgno != t_redg)
file.write((char *)this, sizeof(marks));
}
file.close();
temp.close();
if (flag == 1)
{
gotoxy(20, 16);
cout << "Record Deleted ";
gotoxy(20, 17);
cout << "Press any key to continue...";
getch();
}
else
{
gotoxy(20, 16);
cout << "Record not found !!! ";
getch();
}
}
// Function for returning the record no. for updating marks details
int marks::found_marks(int t_redg)
{
fstream file;
file.open("mark.dat", ios::in);
file.seekg(0, ios::beg);
int count = 0;
while (file.read((char *)this, sizeof(marks)))
{
count++;
if (t_redg == redgno)
break;
}
file.close();
return count;
}
/* This function is used to modify the marks of an existing student. */
void marks:: mod_marks(void)
{
int t_redg, flag = 0;
int m1, m2, m3, m4, m5;
int tot;
char div[10];
float p;
gotoxy(20, 10);
cout << "Enter student registration no. ";
cin >> t_redg;
fstream sfile;
sfile.open("mark.dat", ios::in);
sfile.seekg(0, ios::beg);
while (sfile.read((char *)this, sizeof(marks)))
{
if (t_redg == redgno)
{
gotoxy(20, 12);
cout << "Total is " << total;
gotoxy(20, 14);
cout << "Division is " << division;
flag = 1;
gotoxy(20, 16);
cout << "Enter sub1 : ";
cin>> m1;
gotoxy(20, 17);
cout << "Enter sub2 : ";
cin>> m2;
gotoxy(20, 18);
cout << "Enter sub3 :";
cin >> m3;
gotoxy(20, 19);
cout << "Enter sub4 : ";
cin >> m4;
gotoxy(20, 20);
cout <<"Enter sub5 : ";
cin >> m5;
// Calculates the total marks after modification
tot = m1 + m2 + m3 + m4 + m5;
// Calculates the percentage after modification
p = tot / 5;
// Calculates the division from percentage
if ( p >= 60)
strcpy(div, "first");
else
if ((p<60) && (p>=50))
strcpy(div, "second");
else
if ((p<50) && (p>=33))
strcpy(div, "third");
else
strcpy(div, "fail");
break;
}
}
sfile.close();
if (flag == 1)
{
gotoxy(20, 22);
// Function passes marks details for rewriting into MARK.dat data file
modify_marks(t_redg, m1, m2, m3, m4, m5, tot, div);
cout << "Record modified";
}
else
{
gotoxy(20, 22);
cout << "Record not modified";
}
gotoxy(20, 24);
cout << "Press any key to continue...";
getch();
}
// Function for updating the modified marks information into marks.dat file
void marks::modify_marks(int t_redg, int m1, int m2, int m3, int m4, int m5, int tot, char div[10])
{
int find_rec;
find_rec = found_marks(t_redg);
fstream sfile;
// Opens the file for rewrite mode
sfile.open("mark.dat", ios::out|ios::ate);
sub1 = m1;
sub2 = m2;
sub3 = m3;
sub4 = m4;
sub5 = m5;
total = tot;
strcpy(division, div);
int location;
location = (find_rec-1) * sizeof(marks);
sfile.seekp(location);
// Rewrites the record at location place
sfile.write((char *)this, sizeof(marks));
sfile.close();
return;
}
/* Function to display the student data entry form */
void student::enter_student()
{
int ch1;
int tredg;
char ch2 = 'Y';
student stud;
char t_name[30];
char t_address[30];
char t_fname[30];
char t_class[3];
s_date t_dob;
do
{
// Sets the current viewport for graphics output
setviewport(5, 24, getmaxx()-50, getmaxy()-50, 1);
// Clears the current viewport
clearviewport();
gotoxy(20, 6);
cout << "Student Data Entry Form";
gotoxy(20, 7);
cout << "=======================";
gotoxy(10, 9);
cout << "Registration no. : ";
gotoxy(10, 11);
cout << "Name : ";
gotoxy(10, 13);
cout << "Address : ";
gotoxy(10, 15);
cout << "Father's Name : ";
gotoxy(10, 17);
cout << "Class : ";
gotoxy(10, 19);
cout << "Date Of Birth : ";
gotoxy(30, 9);
cin >> tredg;
gotoxy(30, 11);
gets(t_name);
strupr(t_name);
gotoxy(30, 13);
gets(t_address);
strupr(t_address);
gotoxy(30, 15);
gets(t_fname);
strupr(t_fname);
gotoxy(30, 17);
cin >> t_class;
gotoxy(30, 19);
cin >> t_dob.dd;
gotoxy(34, 19);
cin >> t_dob.mm;
gotoxy(38, 19);
cin >> t_dob.yy;
// Passes the field values into add_student for appending as new record
stud.add_student(tredg, t_name, t_address, t_fname, t_dob, t_class);
gotoxy(10, 22);
cout << "Want More Record ? : ";
cin >> ch2;
} while (ch2 == 'Y' || ch2 == 'y');
}
/* macro definitions for various keys and their scan/ascii codes */
# define ESC 27
# define ENTER 13
# define DOWN 80
# define LEFT 75
# define RIGHT 77
# define UP 72
# define HOME 71
# define END 79
# define PGUP 73
# define PGDN 81
# define TAB 9
# define SH_TAB 15
# define CTRL_RIGHT 116
# define CTRL_LEFT 115
# define CTRL_PGDN 118
# define CTRL_PGUP 132
# define CTRL_HOME 119
# define CTRL_END 117
/* various menu definitions */
// Main menu screen heading
char *mainmenu[ ] =
{
"^Student",
"^Marks",
"^Report",
"^Exit"
};
// Menu for student data (name and address) add, delete, and modify
char *studmenu[ ] =
{
"^Add",
"^Delete",
"^Modify",
};
// Menu for student data (marks ) add, modify and delete
char *markmenu[ ] =
{
"Add",
"Modify",
"Delete",
};
// Reporting menu about for student list, marksheet etc.
char *reportmenu[] =
{
"Student List",
"Marks of all student",
"Report of single student"
};
void *l, *m, *n ;
int x = 10, y = 10, ascii, scan ;
mainscreen();
studfun();
markfun();
report();
displaymenu (char **menu, int count);
getresponse (char *hotkeys, int count);
cleartext (int n);
getkey();
main()
{
int choice, gm = CGAHI, gd = CGA;
size_t area, cursorarea;
// initialise the graphics system for using graphics
initgraph (&gd, &gm, "../bgi");
// Opening screen display
mainscreen();
// clearing the screen contents
clearviewport();
// define the drawing area
rectangle(0, 10, 639, 189);
// Sets the current viewport for graphics output
setviewport(1, 11, 638, 188, 1);
while (1)
{
// displays the main menu in topmost row
displaymenu (mainmenu, 4);
// receive user's response
choice = getresponse("SMRE", 4);
// calling appropriate function for standard operation
switch (choice)
{
case 1 :
studfun();
break;
case 2 :
markfun();
break;
case 3 :
report();
break;
case 4 :
// Shuts down the graphics system
closegraph(); // Closes the graphics system
// Restores screen mode to pre-initgraph setting
restorecrtmode(); // restore original VDU mode
exit(0);
}
}
}
/* The main function body of main screen which displays the main screen
creating the opening screen display */
mainscreen()
{
int maxx, maxy, in, area;
// get maximum x, y coordinates of the screen
maxx = getmaxx();
maxy = getmaxy();
// setbkcolor sets the current background color using the palette
setbkcolor(RED);
// Draws a rectangle (graphics mode)
rectangle(0, 0, maxx, maxy);
// finds area to fix the image in memory screen
area = imagesize(0, 0, 637, 177);
// display the contents of allocated memory on the screen
putimage(1, 11, l, COPY_PUT);
// sets the line style and text justification in screen
settextstyle(1, HORIZ_DIR, 0);
// displaying the output text on main screen
outtextxy(220, 20, "Student");
outtextxy(200,60," Information ");
outtextxy(220,100,"System");
settextstyle(7, HORIZ_DIR, 3);
outtextxy(110, 150, "Press any key to continue...");
// Flushes the standard input device
fflush(stdin);
getch();
// clear the viewport area
clearviewport();
}
/* displays stud menu, receives choice and branches
control to appropriate function */
studfun()
{
int dchoice;
int choice;
int tredg;
char t_name[30];
char t_address[30];
char ch2 = 'y';
student stud;
int maxx, maxy;
maxx = getmaxx();
maxy = getmaxy();
while(1)
{
rectangle(0, 10, 639, 189);
setviewport(1, 11, 638, 188, 1);
displaymenu(studmenu, 3);
setbkcolor(5);
gotoxy(1, 25);
printf("Press Esc to return to previous menu");
dchoice = getresponse("ADM", 3);
switch (dchoice)
{
case 1 :
cleartext(2);
student stud;
stud.enter_student();
setviewport(0, 0, maxx, maxy, 1);
clearviewport();
break;
case 2 :
cleartext(2);
stud.delete_student();
setviewport(0, 0, maxx, maxy, 1);
clearviewport();
break;
case 3 :
cleartext(2);
stud.mod_new();
setviewport(0, 0, maxx, maxy, 1);
clearviewport();
break;
case ESC :
return 0;
}
}
}
/* Displays marks menu, receives choice and branches
control to appropriate function */
markfun()
{
int echoice;
marks mark;
int maxx, maxy;
maxx = getmaxx();
maxy = getmaxy();
while (1)
{
// define the drawing area
rectangle(0, 10, 639, 189);
setviewport(1, 11, 638, 188, 1);
displaymenu(markmenu, 3);
setbkcolor(5);
gotoxy(1, 25);
printf("Press Esc to return to previous menu");
echoice = getresponse("ADM", 3);
switch (echoice)
{
case 1 :
cleartext(2);
mark.read_marks();
setviewport(0, 0, maxx, maxy, 1);
clearviewport();
break;
case 2 :
cleartext(2);
mark.mod_marks();
setviewport(0, 0, maxx, maxy, 1);
clearviewport();
break;
case 3 :
cleartext(2);
mark.delete_marks();
setviewport(0, 0, maxx, maxy, 1);
clearviewport();
break;
case ESC :
return 0;
}
}
}
/* Display Report menu,, receives choice and branches
control to appropriate function */
report()
{
int rchoice;
int maxx, maxy;
student stud;
marks mark;
while (1)
{
// define the drawing area
rectangle(0, 10, 639, 189);
setviewport(1, 11, 638, 188, 1);
displaymenu(reportmenu, 3);
setbkcolor(5);
gotoxy(1, 25);
printf("Press Esc to return to previous menu");
rchoice = getresponse("SMI", 3);
switch (rchoice)
{
case 1 :
setviewport(0, 0, maxx, maxy, 1);
clearviewport();
cleartext(2);
stud.display_student();
maxx = getmaxx();
maxy = getmaxy();
setviewport(0, 0, maxx, maxy, 1);
clearviewport();
break;
case 2:
setviewport(0, 0, maxx, maxy, 1);
clearviewport();
cleartext(2);
mark.display_marks();
maxx = getmaxx();
maxy = getmaxy();
setviewport(0, 0, maxx, maxy, 1);
clearviewport();
break;
case 3 :
setviewport(0, 0, maxx, maxy, 1);
clearviewport();
cleartext(2);
mark.show_marks();
maxx = getmaxx();
maxy = getmaxy();
setviewport(0, 0, maxx, maxy, 1);
clearviewport();
break;
case ESC :
return 0;
}
}
}
/* displays the given menu in topmost row*/
displaymenu(char **menu, int count)
{
int col = 2, i;
cleartext(2); // erases the top and bottom row contents
setbkcolor(2);
for (i = 0; i < count; i++)
{
gotoxy(col, 1);
printf("%s\r", menu[i]);
col = col + 79 / count;
}
}
/* receives user's choice */
getresponse(char *hotkeys, int count)
{
int col, choice = 1, hotkeychoice, len;
while (1)
{
// calculate the column where the triangle is to be placed
col = (choice - 1) * (79 / count) + 1;
// displays triangle to show the current menu item
gotoxy(col, 1);
putchar(16);
// receive any key from keyboard
getkey();
// if you press any special key
if (ascii == 0)
{
// erase triangle from screen
gotoxy(col, 1);
putchar(' ');
// test if hit the left or right arrow key
switch (scan)
{
case RIGHT :
choice++;
break;
case LEFT :
choice--;
}
// if triangle is on last item and right arrow key is hit
if (choice > count)
choice = 1;
// if triangle is on first item and left arrow key is hit
if (choice == 0)
choice = count;
}
else
{
if (ascii == ENTER)
return (choice);
if (ascii == ESC)
return (ESC);
// check whether a hot key has been pressed or not
len = strlen(hotkeys);
hotkeychoice = 1;
ascii = toupper(ascii);
while (*hotkeys)
{
if (*hotkeys == ascii)
return (hotkeychoice);
else
{
hotkeys++;
hotkeychoice++;
}
}
// reset hotkeys pointer
hotkeys = hotkeys - len;
// beep to indicate invalid choice when you pressed a key
printf("\a");
}
}
}
/* gets ascii and scan codes of the key pressed */
getkey()
{
union REGS i, o;
// wait the screen till a key is pressed
while (!kbhit())
;
i.h.ah = 0; // service number
// issue interrupt at the time key press
int86(22, &i, &o);
ascii = o.h.al;
scan = o.h.ah;
}
/* clears top and/or bottom row on the screen*/
cleartext (int n)
{
int i;
switch (n)
{
case 0 : // erases top row only
for (i = 1; i <= 80; i++)
{
gotoxy(i, 1);
putchar(' ');
}
break;
case 1 : // erases the bottom row only
for (i = 1; i <= 67; i++)
{
gotoxy(i, 25);
putchar(' ');
}
break;
case 2 : // erases top and bottom row
cleartext(0);
cleartext(1);
break;
}
}
/* tests which key has been hit*/
testkeys()
{
/* if cursor movement key is hit, update values of x, y*/
if (ascii == 0)
{
switch (scan)
{
case DOWN :
y++;
break;
case UP :
y--;
break;
case LEFT :
x--;
break;
case RIGHT :
x++;
break;
case HOME :
y--;
x--;
break;
case END :
x--;
y++;
break;
case PGUP :
x++;
y--;
break;
case PGDN :
x++;
y++;
break;
case SH_TAB :
x -= 10;
break;
case CTRL_RIGHT :
x = 636;
break;
case CTRL_LEFT :
x = 2;
break;
case CTRL_PGDN :
y += 5;
break;
case CTRL_PGUP :
y -= 5;
break;
case CTRL_HOME :
x = 2;
y = 2;
break;
case CTRL_END :
x = 636;
y = 176;
}
}
else
{
if (ascii == ENTER)
return (ENTER);
if (ascii == ESC)
{
putimage(0, 0, l, OR_PUT); // restore screen contents
return (ESC);
}
if (ascii == TAB)
x += 10;
}
// if a key other than Enter or Esc is pressed
return (100);
}