// Matt Kaliszewski
// Dormitory Assignment Program
// dorm.h
#ifndef DORM_H
#define DORM_H
//===================== CLASSES =====================
//********* Student Class ********
class student {
public:
char first_name[40]; // student's first name
char last_name[40]; // student's last name
};
//********* Room Class *********
class room {
public:
room();
int open[3]; // open room specifier
student students[3]; // 3 students per room
};
//******** Dormitory Class ********
class dormitory {
public:
room rooms[75]; // 75 rooms per dormitory
};
//===================== CLASS MEMBER FUNCTIONS =====================
//******** Room Class Function Definitions ********
// room constructor
room::room()
{
for(int i=0;i<3;i++)
open[i]=1;
}
//===================== FUNCTIONS =====================
// Sets the current dorm and room
void
set_dorm_n_room(int *c_d, int *c_r)
{
// Set the current dorm
cout << "===============================================" << endl
<< "Assign a student to a room:" << endl << endl
<< "Which Dorm would you like to place a student into?" << endl
<< "Enter a number (1-7): ";
cin >> *c_d;
cout << endl;
// Make sure the entry is between the range, invalid entries set to 1
*c_d=(*c_d>=1 && *c_d<=7) ? *c_d : 1;
// Set the current room
cout << "Which room in Dorm " << *c_d
<< " would you to place a student into?" << endl
<< "Enter a number (1-75): ";
cin >> *c_r;
// Make sure the entry is between the range, invalid entries set to 1
*c_r=(*c_r>=1 && *c_r<=75) ? *c_r : 1;
}
//=======================================================
// Displays the occupants of a specific room
void
display_room(dormitory d[7], int c_d, int c_r)
{
int i;
// Display the occupants of the room
cout << endl << "Contents of Dorm: " << c_d << " Room: " << c_r << endl
<< "-------------------------------------" << endl;
for(i=0;i<3;i++)
{
if(d[c_d-1].rooms[c_r-1].open[i]==0)
{
cout << "Occupant " << i+1 << ": "
<< d[c_d-1].rooms[c_r-1].students[i].first_name << " "
<< d[c_d-1].rooms[c_r-1].students[i].last_name << endl;
}
else
cout << "Occupant " << i+1 << ": Empty" <<endl;
}
cout << endl;
}
//=======================================================
// Searches through the dorms for a specific person
void
search_dorms(dormitory d[7], char name[40], char type)
{
int c_d, c_r, occ;
cout << endl
<< "=====================================" << endl
<< "Search matches:" << endl
<< "=====================================" << endl << endl;
if(type=='f') // Search through by first name
{
for(c_d=0;c_d<7;c_d++){
for(c_r=0;c_r<75;c_r++){
for(occ=0;occ<3;occ++){
if(strcmp(d[c_d].rooms[c_r].students[occ].first_name, name)==0)
cout << "Dorm: " << c_d+1 << " Room: " << c_r+1 << " Occupant: " << occ+1
<< endl << d[c_d].rooms[c_r].students[occ].first_name << " "
<< d[c_d].rooms[c_r].students[occ].last_name << endl << endl;
}
}
}
}
else // Search through by last name
{
for(c_d=0;c_d<7;c_d++){
for(c_r=0;c_r<75;c_r++){
for(occ=0;occ<3;occ++){
if(strcmp(d[c_d].rooms[c_r].students[occ].last_name, name)==0)
cout << "Dorm: " << c_d+1 << " Room: " << c_r+1 << " Occupant: " << occ+1
<< endl << d[c_d].rooms[c_r].students[occ].first_name << " "
<< d[c_d].rooms[c_r].students[occ].last_name << endl << endl;
}
}
}
}
}
//=======================================================
#endif