Академический Документы
Профессиональный Документы
Культура Документы
#include<string>
#include<fstream>
#include<cstring>
#include<cctype>
#include<new>
#include<windows.h>
#include<conio.h>
//FUNCTIONS>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
void initial(void);
void menu(void);
void inpstd(void);
void dispstd(void);
void inputstaff(void);
void filecheck(void);
void outputstaff(void);
void inputhall(void);
void displayhall(void);
void merinhall(void);
//>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
//FILE OBJECTS>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
ifstream ofile;
ofstream ifile;
ofstream inph;
ifstream outh;
ofstream istaff;
ifstream ostaff;
//..............................................................
//>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
//STRUCTURES>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
//>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
//ANSWERSHEETS.................
struct answersheet_no{
char code[15]="00000000";
void insheets();
void outsheets();
};
//STAFF........................
struct staff{
int id;
char teacher[30];
void inpst();
void outst();
};
//EXAM.........................
struct exam{
char exam_name[20]="Undefined";
};
//STUDENT......................
struct student{
char name[30];
double cms;
answersheet_no answersheetno;
exam paper;
bool p_a;
void indatastd();
void dispdatastd();
int alloted_hall;
};
//HALL..........................
struct hall{
double id;
char hall_name[30];
double cap;
staff staff;
student students[100];
void inp_hall();
void disp_hdata();
void disp_allhall();
};
//END OF STRUCTURES>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
//>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
//...........................................................................
..
//STRUCTURE ARRAYS>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
student s[100];
hall h[10];
staff st[50];
answersheet_no inpanswerno[100];
exam subjects[5];
//.............................................................
//>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
>>>>>>>>>>
//SHEETS DATA>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
void answersheet_no::insheets(){
cin>>code;
}
void answersheet_no::outsheets(){
cout<<code<<endl;
}
//STAFF INPUT>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
void staff::inpst(){
redo:
cout<<"Enter id: ";
while(!(cin>>id))
{
system("cls");
cout<<"\n\n\n";
system("color 7C");
cout<<"Invalid number "<<endl;
cin.clear();
cin.ignore();
goto redo;
}
system("color 70");
cin.ignore();
char tempa[30];
b:
void staff::outst(){
cout<<id<<"\t\t"<<teacher<<endl;
}
//>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
//STUDENT DATA>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
void student::indatastd(){
redo:
cout<<"Enter cms: ";
while(!(cin>>cms))
{
system("cls");
cout<<"\n\n\n";
system("color 7C");
cout<<"Invalid number "<<endl;
cin.clear();
cin.ignore();
goto redo;
}
system("color 70");
cin.ignore();
char tempa[30];
b:
void student::dispdatastd(){
cout << cms << "\t" << name << "\t\t"
<<answersheetno.code<<"\t\t\t" <<paper.exam_name;
//>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
//HALL DATA>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
void hall::inp_hall(){
redo:
cout<<"Enter hall ID: ";
while(!(cin>>id))
{
system("cls");
cout<<"\n\n\n";
system("color 7C");
cout<<"Invalid number "<<endl;
cin.clear();
cin.ignore();
goto redo;
}
system("color 70");
cin.ignore();
cout<<"Enter hall name: ";
cin.getline(hall_name , 30);
r:
cout<<"Enter capacity: ";
while(!(cin>>cap))
{
system("cls");
cout<<"\n\n\n";
system("color 7C");
cout<<"Invalid number "<<endl;
cin.clear();
cin.ignore();
goto r;
}
system("color 70");
}
void hall::disp_hdata(){
cout<<id<<"\t\t"<<hall_name<<"\t\t"<<cap<<endl;
}
void hall::disp_allhall(){
cout<<"Hall ID: "<<id<<endl
<<"Hall Name: " <<hall_name<<endl
<<"Hall Capacity: "<<cap<<endl
<<"Students"<<endl;
for(int a=0;a<=cap;a++){
cout<<students[a].cms<<"\t\t"<<students[a].name;
cout<<endl;
}
}
//>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
//MAIN FUNCTION>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
//................................................................
int main()
{
system ("color 70");
menu();
return 0;
}
//................................................................
//>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
//FUNCTIONS DEFINITION>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
//>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
//INNITIALIZATION FUNCTION>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
void initial(void){
int size_std,size_sta,no_h,size_pap;
rstd:
cout<<"Input number of students: ";
while(!(cin>>size_std) || size_std<=0 || size_std>=800 )
{
system("cls");
cout<<"\n\n\n";
system("color 7C");
cout<<"Invalid number of students, enter correctly"<<endl;
cin.clear();
cin.ignore();
goto rstd;
}
system("color 70");
cin.ignore();
rsta:
cout<<"Input number of staff: ";
while(!(cin>>size_sta) || size_sta<=0 || size_sta>400)
{
system("cls");
cout<<"\n\n\n";
system("color 7C");
cout<<"Invalid number of staff, enter correctly"<<endl;
cin.clear();
cin.ignore();
goto rsta;
}
system("color 70");
rh:
cout<<"Input no of halls: ";
while(!(cin>>no_h) || no_h<=0 || no_h>=40)
{
system("cls");
cout<<"\n\n\n";
system("color 7C");
cout<<"Invalid number of halls entered, enter
correctly"<<endl;
cin.clear();
cin.ignore();
goto rh;
}
system("color 70");
rsub:
cout<<"Enter number of Subjects involved: ";
while(!(cin>>size_pap) || size_pap<=0 || size_pap>=15 )
{
system("cls");
cout<<"\n\n\n";
system("color 7C");
cout<<"Invalid number ofsubjects, enter correctly"<<endl;
cin.clear();
cin.ignore();
goto rsub;
}
system("color 70");
float t;
rt:
cout<<"Enter time alloted ( in hours): ";
while(!(cin>>t) || t<=0 || t>6)
{
system("cls");
cout<<"\n\n\n";
system("color 7C");
cout<<"Invalid time entered, enter correct time"<<endl;
cin.clear();
cin.ignore();
goto rt;
}
system("color 70");
time=t*60*60;
size_stdg=size_std;
size_stag=size_sta;
no_hg=no_h;
size_papg=size_pap;
//.............................................................
//MENU FUNCTION>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
void menu(void)
{
cout<<"\n\n";
if(f==0){
cout<<"Would you like to initialize? y/n"<<endl;
char ch;
cin>>ch;
if(ch=='y' || ch=='Y'){
initial();
f++;
z++;
}
}
if(z==0){
time=7200;
cout<<"The initial data is:\n"<<size_stdg<<" Students"<<endl
<<size_stag<<" Staff"<<endl
<<no_hg<<" Halls"<<endl
<<time/3600<<" Hours Time"<<endl;
z++;
}
f++;
redo:
while(true){
system("cls");
cout<<"\n\n\n";
system("color 7C");
cout<<"Invalid choise"<<endl;
cin.clear();
cin.ignore();
goto redo;
}
system("color 70");
switch(choice)
{
case 1:{
inpstd();
break;
}
case 2:{
dispstd();
break;
}
case 3:{
inputhall();
break;
}
case 4:{
displayhall();
break;
}
case 5:{
inputstaff();
break;
}
case 6:{
outputstaff();
break;
}
case 7:{
merinhall();
break;
}
case 8:{
initial();
break;
}
case 0:{
exit(0);
break;
}
default:{
cout<<"Invalid Input"<<endl;
break;
}
}goto redo;
}
}
//.................................................................
void inpstd(void)
{
cout<<"\n\n";
int std_n=0;
ofile.open("student data.bat",ios::in);
for(int i=0;i<=size_stdg;i++){
ofile.read((char *)&s[i],sizeof(s[i]));
if(strcmp(s[i].name,"")==0){
break;
}
std_n++;
}
ofile.close();
ifile.open("student data.bat",ios::app);
for(int i=std_n;i<=size_stdg;i++)
{
s[i].indatastd();
ifile.write((char *)&s[i],sizeof(s[i]));
char c;
cout<<"Do you want to add more students? y/n ";
cin>>c;
cout<<"\n";
if(c=='n'||c=='N'){
menu();
}
}
ifile.close();
system("cls");
filecheck();
}
//...................................................................
void dispstd(void)
{
system("cls");
int std_n=0;
cout<<"\n\n";
ofile.open("student data.bat",ios::in);
for(int i=0;i<=size_stdg;i++){
ofile.read((char *)&s[i],sizeof(s[i]));
if(strcmp(s[i].name,"")==0){
break;
}
std_n++;
}
ofile.open("student data.bat",ios::in);
cout<<"Cms\tName\t\tAnswersheet no\t\tExam"<<endl;
for (int i=0;i<=std_n;i++)
{
ofile.read((char *)&s[i],sizeof(s[i]));
s[i].dispdatastd();
cout<<endl;
}
ofile.close();
filecheck();
}
//................................................................
void filecheck(void){
int std_n;
ofile.open("student data.bat",ios::in);
for(int i=0;i<size_stdg;i++){
ofile.read((char *)&s[i],sizeof(s[i]));
if(strcmp(s[i].name,"")==0){
break;
}
std_n++;
}
int sta_n=0;
ostaff.open("staff data.bat",ios::in);
for(int i=0;i<=size_stag;i++){
ostaff.read((char *)&st[i],sizeof(st[i]));
if(strcmp(st[i].teacher,"")==0){
break;
}
sta_n++;
}
ostaff.close();
studentsinpresent=std_n;
staffinpresent=sta_n;
//.............................................................
//..............................................................
void outputstaff(){
system("cls");
int sta_n=0;
ostaff.open("staff data.bat",ios::in);
for(int i=0;i<=size_stag;i++){
ostaff.read((char *)&st[i],sizeof(st[i]));
if(strcmp(st[i].teacher,"")==0){
break;
}
sta_n++;
}
cout<<"Id\t\tName"<<endl;
ostaff.open("staff data.bat",ios::in);
for(int i=0;i<=sta_n;i++){
ostaff.read((char *)&st[i],sizeof(st[i]));
st[i].outst();
}
ostaff.close();
filecheck();
}
//.............................................................
void inputhall(void){
system("cls");
cout<<"\n\n";
int halls=0;
outh.open("hall data.bat",ios::in);
for(int i=0;i<=no_hg;i++){
outh.read((char *)&h[i],sizeof(h[i]));
if(strcmp(h[i].hall_name,"")==0){
break;
}
halls++;
}
outh.close();
inph.open("hall data.bat",ios::app);
for(int i=halls;i<=no_hg;i++){
h[i].inp_hall();
inph.write((char *)&h[i],sizeof(h[i]));
char c;
cout<<"Do you want to add more halls? y/n ";
cin>>c;
if(c=='n'||c=='N'){
menu();
}
}
inph.close();
system("cls");
cout<<"\n\n";
}
//............................................................
void displayhall(void){
system("cls");
cout<<"\n\n";
int halls=0;
outh.open("hall data.bat",ios::in);
for(int i=0;i<=no_hg;i++){
outh.read((char *)&h[i],sizeof(h[i]));
if(strcmp(h[i].hall_name,"")==0){
break;
}
halls++;
}
outh.close();
outh.open("hall data.bat",ios::in);
cout<<"ID\t\tHall Name\t\t\tCapacity"<<endl;
for(int i=0;i<=halls;i++){
outh.read((char *)&h[i],sizeof(h[i]));
h[i].disp_hdata();
}
outh.close();
}
//.........................................................................
void merinhall(void){
int std_n=0;
int sta_n=0;
ofile.open("student data.bat",ios::in);
ostaff.open("staff data.bat",ios::in);
for(int i=0;i<size_stdg;i++){
ofile.read((char *)&s[i],sizeof(s[i]));
if(strcmp(s[i].name,"")==0){
break;
}
std_n++;
ostaff.read((char *)&st[i],sizeof(st[i]));
if(strcmp(st[i].teacher,"")==0){
break;
}
sta_n++;
}
ofile.close();
ostaff.close();
int std_count_during_loop=0;
int student_count=0;
inph.open("hall data.bat",ios::out);
ofile.open("student data.bat",ios::in);
for(int hall_count=0;hall_count<=no_hg;hall_count++){
for(
student_count=std_count_during_loop;student_count<=std_n;student_count++){
cout<<"Student count"<<student_count<<endl;
h[hall_count].students[student_count]=s[student_count];
inph.write((char*)&h[hall_count],sizeof(h[hall_count]));
std_count_during_loop++;
if(student_count==h[hall_count].cap){
break;
}
}
if(std_count_during_loop==std_n){
break;
}
}
cout<<"Loop "<<std_count_during_loop<<endl;
ofile.close();
inph.close();
int halls=0;
outh.open("hall data.bat",ios::in);
for(int i=0;i<=no_hg;i++){
outh.read((char *)&h[i],sizeof(h[i]));
if(h[i].id==0){
break;
}
halls++;
}
outh.close();
for(int j=0;j<=halls;j++){
h[j].disp_allhall();
cout<<endl;
}
//...........................................................................
..........