#include<stdio.h>
#include<conio.h>
#include<string.h>
#include<dos.h>
#include<stdlib.h>
#include<ctype.h>
FILE *fp;
struct student
{
char snum[13];
char fname[20];
char sname[20];
char mi;
char ccode;
}record;
void Temp1(void);
void twolinebox(int x1,int y1,int x2,int y2)
{
int x,y;
gotoxy(x1,y1); printf("É");
gotoxy(x2,y1); printf("»");
for(y=y1+1;y<y2;y++)
{
gotoxy(x1,y); printf("º");
gotoxy(x2,y); printf("º");
}
gotoxy(x1,y2); printf("È");
gotoxy(x2,y2); printf("¼");
for(x=x1+1;x<x2;x++)
{
gotoxy(x,y1); printf("Í");
gotoxy(x,y2); printf("Í");
}
//gotoxy(x1+1,y1+1);
}
void printxy(int x,int y,char string[])
{
gotoxy(x,y); printf("%s",string);
}
void center(int y,char string[])
{
int x=(80-strlen(string)+1)/2;
gotoxy(x,y);printf("%s",string);
}
void Create(void)
{
char opt;
center(21,"WARNING!!!");
center(22,"You are about to create a new file");
center(23,"This will erase all records in the file...");
center(24,"Are you sure you want to proceed?[Y/N] ");
opt=getche(); opt=toupper(opt);
if(opt=='Y')
{
fp=fopen("Group4.txt","w");
center(24," ");
center(24,"File successfully created!");
}
getch();
fclose(fp);
}
void Add(void)
{
char opt;
fp=fopen("Group4.txt","a");
clrscr();
Temp1();
gotoxy(19,8); gets(record.snum);
gotoxy(19,10); gets(record.fname);
gotoxy(19,12); gets(record.sname);
gotoxy(19,14); record.mi=getche(); record.mi=toupper(record.mi);
gotoxy(19,16); record.ccode=getche();record.ccode=toupper(record.ccode);
gotoxy(5,22); clreol(); printxy(79,22,"º");
fprintf(fp,"%s %s %s %c %c",record.snum,record.fname,record.sname,record.mi,record.ccode);
gotoxy(5,21); clreol(); center(21,"Record successfully added!");printxy(79,21,"º");
gotoxy(53,22);
delay(1000);
center(22,"Press any key to go to main menu...");
getch();
fclose(fp);
}
void Temp1(void)
{
// lines(box) for B choice
twolinebox(2,6,79,20);
twolinebox(2,20,79,24);
twolinebox(2,2,79,24);
center(4,"ADD RECORD");
printxy(6,8,"Student no: ");
printxy(6,10,"First Name: ");
printxy(6,12,"Last Name: ");
printxy(6,14,"Middle init:");
printxy(6,16,"Course code: ");
center(22,"Course code: [A]-B.C.A, [B]-B.B.A, [anykey]-B.TECH");
gotoxy(19,7);
}
void List(void)
{
int count=0,i,x=0,page=1,BCA=0,BBA=0,BTECH=0;
fp=fopen("Group4.txt","r");
clrscr();
center(2,"DR.VIRENDRA SWARUP GROUP OF INSTITUTIONS");
center(3,"AJAD MARG,UNNAO");
center(5,"COMPUTER SCIENCE DEPARTMENT");
printxy(10,7,"Record Student # Name Course");
for(i=1;i<80;i++)
{
gotoxy(i,8); puts("Í");
}
while(fscanf(fp,"%s %s %s %c %c",&record.snum,&record.fname,&record.sname,&record.mi,&record.ccode)!=EOF) //it will work without & sign
{
if(count!=0&&count%5==0)
{
printxy(5,23, "Press any key to continue..."); getch(); x=0;
for(i=10;i<=24;i++)
{
gotoxy(1,i); clreol();
}
page++;
}
gotoxy(70,4); printf("Page %d",page);
gotoxy(13,10+x); printf("%d",count+1);
gotoxy(19,10+x); printf("%s",record.snum);
gotoxy(37,10+x); printf("%s %c %s",record.fname,record.mi,record.sname);
gotoxy(62,10+x);
switch(record.ccode)
{
case 'A': printf("BCA"); BCA++; break;
case 'B': printf("BBA"); BBA++; break;
default : printf("B.TECH"); BTECH++; break;
}
x++;
count++;
}
printxy(25,17,"TOTAL");
gotoxy(15,18); printf("BCA : %d",BCA);
gotoxy(15,19); printf("BBA : %d",BBA);
gotoxy(15,20); printf("B.TECH: %d",BTECH);
printxy(5,23,"Press any key to go to main menu...");
getch();
fclose(fp);
}
void Quit(void)
{
clrscr();
twolinebox(2,2,79,24);
center(8,"PROGRAMMED");
center(9,"BY");
center(11," PRITAM BANIK");
center(13,"Microsoft Certified Professional");
delay(1000);
exit(1);
fclose(fp);
}
void Err_mess(void)
{
sound(1000);
center(22,"Invalid Input!");
delay(1000);
nosound();
}
void main()
{
char choice;
do
{
clrscr();
twolinebox(29,6,51,8);
twolinebox(20,5,60,18);
twolinebox(2,20,79,25);
twolinebox(2,2,79,25);
center(7,"MAIN MENU");
printxy(30,9,"Press:");
printxy(30,11,"[A]-Create File");
printxy(30,12,"[B]-Add Record");
printxy(30,13,"[C]-List Record");
printxy(30,14,"[D]-Quit Program");
printxy(30,16,"Enter your choice..."); gotoxy(50,16);
choice=getch(); choice=toupper(choice);
switch(choice)
{
case 'A': Create(); break;
case 'B': Add(); break;
case 'C': List(); break;
case 'D': Quit(); break;
default: Err_mess(); break;
}
}
while(choice!='D');
}
#include<conio.h>
#include<string.h>
#include<dos.h>
#include<stdlib.h>
#include<ctype.h>
FILE *fp;
struct student
{
char snum[13];
char fname[20];
char sname[20];
char mi;
char ccode;
}record;
void Temp1(void);
void twolinebox(int x1,int y1,int x2,int y2)
{
int x,y;
gotoxy(x1,y1); printf("É");
gotoxy(x2,y1); printf("»");
for(y=y1+1;y<y2;y++)
{
gotoxy(x1,y); printf("º");
gotoxy(x2,y); printf("º");
}
gotoxy(x1,y2); printf("È");
gotoxy(x2,y2); printf("¼");
for(x=x1+1;x<x2;x++)
{
gotoxy(x,y1); printf("Í");
gotoxy(x,y2); printf("Í");
}
//gotoxy(x1+1,y1+1);
}
void printxy(int x,int y,char string[])
{
gotoxy(x,y); printf("%s",string);
}
void center(int y,char string[])
{
int x=(80-strlen(string)+1)/2;
gotoxy(x,y);printf("%s",string);
}
void Create(void)
{
char opt;
center(21,"WARNING!!!");
center(22,"You are about to create a new file");
center(23,"This will erase all records in the file...");
center(24,"Are you sure you want to proceed?[Y/N] ");
opt=getche(); opt=toupper(opt);
if(opt=='Y')
{
fp=fopen("Group4.txt","w");
center(24," ");
center(24,"File successfully created!");
}
getch();
fclose(fp);
}
void Add(void)
{
char opt;
fp=fopen("Group4.txt","a");
clrscr();
Temp1();
gotoxy(19,8); gets(record.snum);
gotoxy(19,10); gets(record.fname);
gotoxy(19,12); gets(record.sname);
gotoxy(19,14); record.mi=getche(); record.mi=toupper(record.mi);
gotoxy(19,16); record.ccode=getche();record.ccode=toupper(record.ccode);
gotoxy(5,22); clreol(); printxy(79,22,"º");
fprintf(fp,"%s %s %s %c %c",record.snum,record.fname,record.sname,record.mi,record.ccode);
gotoxy(5,21); clreol(); center(21,"Record successfully added!");printxy(79,21,"º");
gotoxy(53,22);
delay(1000);
center(22,"Press any key to go to main menu...");
getch();
fclose(fp);
}
void Temp1(void)
{
// lines(box) for B choice
twolinebox(2,6,79,20);
twolinebox(2,20,79,24);
twolinebox(2,2,79,24);
center(4,"ADD RECORD");
printxy(6,8,"Student no: ");
printxy(6,10,"First Name: ");
printxy(6,12,"Last Name: ");
printxy(6,14,"Middle init:");
printxy(6,16,"Course code: ");
center(22,"Course code: [A]-B.C.A, [B]-B.B.A, [anykey]-B.TECH");
gotoxy(19,7);
}
void List(void)
{
int count=0,i,x=0,page=1,BCA=0,BBA=0,BTECH=0;
fp=fopen("Group4.txt","r");
clrscr();
center(2,"DR.VIRENDRA SWARUP GROUP OF INSTITUTIONS");
center(3,"AJAD MARG,UNNAO");
center(5,"COMPUTER SCIENCE DEPARTMENT");
printxy(10,7,"Record Student # Name Course");
for(i=1;i<80;i++)
{
gotoxy(i,8); puts("Í");
}
while(fscanf(fp,"%s %s %s %c %c",&record.snum,&record.fname,&record.sname,&record.mi,&record.ccode)!=EOF) //it will work without & sign
{
if(count!=0&&count%5==0)
{
printxy(5,23, "Press any key to continue..."); getch(); x=0;
for(i=10;i<=24;i++)
{
gotoxy(1,i); clreol();
}
page++;
}
gotoxy(70,4); printf("Page %d",page);
gotoxy(13,10+x); printf("%d",count+1);
gotoxy(19,10+x); printf("%s",record.snum);
gotoxy(37,10+x); printf("%s %c %s",record.fname,record.mi,record.sname);
gotoxy(62,10+x);
switch(record.ccode)
{
case 'A': printf("BCA"); BCA++; break;
case 'B': printf("BBA"); BBA++; break;
default : printf("B.TECH"); BTECH++; break;
}
x++;
count++;
}
printxy(25,17,"TOTAL");
gotoxy(15,18); printf("BCA : %d",BCA);
gotoxy(15,19); printf("BBA : %d",BBA);
gotoxy(15,20); printf("B.TECH: %d",BTECH);
printxy(5,23,"Press any key to go to main menu...");
getch();
fclose(fp);
}
void Quit(void)
{
clrscr();
twolinebox(2,2,79,24);
center(8,"PROGRAMMED");
center(9,"BY");
center(11," PRITAM BANIK");
center(13,"Microsoft Certified Professional");
delay(1000);
exit(1);
fclose(fp);
}
void Err_mess(void)
{
sound(1000);
center(22,"Invalid Input!");
delay(1000);
nosound();
}
void main()
{
char choice;
do
{
clrscr();
twolinebox(29,6,51,8);
twolinebox(20,5,60,18);
twolinebox(2,20,79,25);
twolinebox(2,2,79,25);
center(7,"MAIN MENU");
printxy(30,9,"Press:");
printxy(30,11,"[A]-Create File");
printxy(30,12,"[B]-Add Record");
printxy(30,13,"[C]-List Record");
printxy(30,14,"[D]-Quit Program");
printxy(30,16,"Enter your choice..."); gotoxy(50,16);
choice=getch(); choice=toupper(choice);
switch(choice)
{
case 'A': Create(); break;
case 'B': Add(); break;
case 'C': List(); break;
case 'D': Quit(); break;
default: Err_mess(); break;
}
}
while(choice!='D');
}
No comments:
Post a Comment