This project is on seat plan.
There are some rules to sit the students
These are: 1. No one from same batch will sit together
2.No one from same subject code will sit together
These are: 1. No one from same batch will sit together
2.No one from same subject code will sit together
In this program I used the following oocpp features:
- Function overloading
- Inheritance
- Friend function
Cpp file system is added to improve the project
///////////////* Declaration of header files *//////////////////
#include<fstream.h>
#include<conio.h>
#include<stdio.h>
#include<string.h>
#include<graphics.h>
#include<dos.h>
////////////////////* base class *//////////////////
class seat_plan{
protected:
char project[100][100];
int i,j;
int row,column;
public:
void seat_arrangement(float without_file_id); //function overloading
void seat_arrangement(int file_id); //function overloading
friend void show(seat_plan ob); //call of friend function
};
void seat_plan::seat_arrangement(float without_file_id){
if(without_file_id==1.0){
clrscr();
int num=-1;
int num_21=0,num_31=0,num_41=0,num_32=0,num_42=0,num_43=0;
cout<<"Number of rows: ";
cin>>row;
cout<<"Number of columns: ";
cin>>column;
if(row!=0&&column!=0){
for(i=0;i<row+1;i++){ //sets NULL to all the seats
for(j=0;j<column+1;j++){
project[i][j]='\0';
}
}
cout<<"Number of total backlock students shouldn't be more than 10."<<endl;
while(num==-1){
cout<<"Number of 2...1: ";
cin>>num_21;
cout<<"Number of 3...1: ";
cin>>num_31;
cout<<"Number of 4...1: ";
cin>>num_41;
cout<<"Number of 3...2: ";
cin>>num_32;
cout<<"Number of 4...2: ";
cin>>num_42;
cout<<"Number of 4...3: ";
cin>>num_43;
num=num_21+num_31+num_41+num_32+num_42+num_43;
if(num>10)
num=-1;
}
//backlock students are alloted with seats
//symbols used here for showing backlock students
// '*' for backlock students of 2nd year giving exam with 1st year students
// '-' for backlock students of 3rd year giving exam with 1st year students
// '+' for backlock students of 4th year giving exam with 1st year students
// 'a' for backlock students of 3rd year giving exam with 2nd year students
// 'b' for backlock students of 4th year giving exam with 2nd year students
// 'c' for backlock students of 4th year giving exam with 3rd year students
if(num_21>0)
{
for(i=0;i<row;i++){
for(j=0;j<column;j++){
if(project[i-1][j]!='*'&&project[i+1][j]!='*'&&project[i][j-1]!='*'&&project[i][j-1]!='*'){
project[i][j]='*';
num_21--;
if(num_21==0){
j=column-1;
i=row-1;
}
}
}
}
}
if(num_31>0){
for(i=0;i<row;i++){
for(j=0;j<column;j++){
if(project[i][j]!='*'&&project[i-1][j]!='-'&&project[i+1][j]!='-'&&project[i][j-1]!='-'&&project[i][j+1]!='-'&&project[i-1][j]!='*'&&project[i+1][j]!='*'&&project[i][j-1]!='*'&&project[i][j+1]!='*'){
project[i][j]='-';
num_31--;}
if(num_31==0){
j=column-1;
i=row-1;
}
}
}
}
if(num_41>0){
for(i=0;i<row;i++){
for(j=0;j<column;j++){
if(project[i][j]!='*'&&project[i][j]!='-'&&project[i-1][j]!='+'&&project[i+1][j]!='+'&&project[i][j-1]!='+'&&project[i][j+1]!='+'&&project[i-1][j]!='*'&&project[i+1][j]!='*'&&project[i][j-1]!='*'&&project[i][j+1]!='*'){
project[i][j]='+';
num_41--;}
if(num_41==0){
j=column-1;
i=row-1;
}
}
}
}
if(num_32>0){
for(i=0;i<row;i++){
for(j=0;j<column;j++){
if(project[i][j]!='*'&&project[i][j]!='-'&&project[i][j]!='+'&&project[i-1][j]!='a'&&project[i+1][j]!='a'&&project[i][j-1]!='a'&&project[i][j+1]!='a'&&project[i-1][j]!='-'&&project[i+1][j]!='-'&&project[i][j-1]!='-'&&project[i][j+1]!='-'){
project[i][j]='a';
num_32--;}
if(num_32==0){
j=column-1;
i=row-1;
}
}
}
}
if(num_42>0){
for(i=0;i<row;i++){
for(j=0;j<column;j++){
if(project[i][j]!='*'&&project[i][j]!='-'&&project[i][j]!='+'&&project[i][j]!='a'&&project[i-1][j]!='b'&&project[i+1][j]!='b'&&project[i][j-1]!='b'&&project[i][j+1]!='b'&&project[i-1][j]!='a'&&project[i+1][j]!='a'&&project[i][j-1]!='a'&&project[i][j+1]!='a'){
project[i][j]='b';
num_42--;}
if(num_42==0){
j=column-1;
i=row-1;
}
}
}
}
if(num_43>0){
for(i=0;i<row;i++){
for(j=0;j<column;j++){
if(project[i][j]!='*'&&project[i][j]!='-'&&project[i][j]!='+'&&project[i][j]!='a'&&project[i][j]!='b'&&project[i-1][j]!='b'&&project[i+1][j]!='b'&&project[i][j-1]!='b'&&project[i][j+1]!='b'&&project[i-1][j]!='+'&&project[i+1][j]!='+'&&project[i][j-1]!='+'&&project[i][j+1]!='+'&&project[i-1][j]!='c'&&project[i+1][j]!='c'&&project[i][j-1]!='c'&&project[i][j+1]!='c'){
project[i][j]='c';
num_43--;}
if(num_43==0){
j=column-1;
i=row-1;
}
}
}
}
int blank=0;;
for(i=0;i<row;i++){
for(j=0;j<column;j++){
if(project[i][j]=='\0'){
blank++;
}
}
}
int num_1=-1,num_2=-1,num_3=-1,num_4=-1;
cout<<endl<<"There are "<<blank<<" places.";
while(num_1==-1){
cout<<endl<<"Number of 1st year students: ";
cin>>num_1;
if(num_1>blank)
num_1=-1;
}
if(num_1==-1){
num_1=0;
}
if(num_1!=0){
for(i=0;i<row;i++){
for(j=0;j<column;j++){
if(project[i][j]=='\0'){
if(project[i-1][j]!='*'&&project[i+1][j]!='*'&&project[i][j-1]!='*'&&project[i][j+1]!='*'&&project[i-1][j]!='-'&&project[i+1][j]!='-'&&project[i][j-1]!='-'&&project[i][j+1]!='-'&&project[i-1][j]!='+'&&project[i+1][j]!='+'&&project[i][j-1]!='+'&&project[i][j+1]!='+'&&project[i-1][j]!='1'&&project[i+1][j]!='1'&&project[i][j-1]!='1'&&project[i][j+1]!='1'){
project[i][j]='1';
num_1--;
if(num_1==0){
j=column-1;
i=row-1;}
}
}
}
}
for(i=0;i<row;i++){
for(j=0;j<column;j++){
cout<<project[i][j]<<" ";
}
cout<<endl;
}
if(num_1!=0){
if(num_1!=1){
cout<<"There are "<<num_1<<" students who are not placed,because of the applied condition."<<endl;}
else{
cout<<"There is "<<num_1<<" students who is not placed,because of the applied condition."<<endl;}
}}
blank=0;;
for(i=0;i<row;i++){
for(j=0;j<column;j++){
if(project[i][j]=='\0'){
blank++;
}
}
}
cout<<endl<<"There are "<<blank<<" places.";
while(num_2==-1){
cout<<endl<<"Number of 2nd year students: ";
cin>>num_2;
if(num_2>blank)
num_2=-1;
}
if(num_2==-1){
num_2=0;
}
if(num!=2){
for(i=0;i<row;i++){
for(j=0;j<column;j++){
if(project[i][j]=='\0'){
if(project[i-1][j]!='*'&&project[i+1][j]!='*'&&project[i][j-1]!='*'&&project[i][j+1]!='*'&&project[i-1][j]!='a'&&project[i+1][j]!='a'&&project[i][j-1]!='a'&&project[i][j+1]!='a'&&project[i-1][j]!='b'&&project[i+1][j]!='b'&&project[i][j-1]!='b'&&project[i][j+1]!='2'&&project[i-1][j]!='2'&&project[i+1][j]!='2'&&project[i][j-1]!='2'&&project[i][j+1]!='2'){
project[i][j]='2';
num_2--;
if(num_2==0){
j=column-1;
i=row-1;}
}
}
}
}
for(i=0;i<row;i++){
for(j=0;j<column;j++){
cout<<project[i][j]<<" ";
}
cout<<endl;
}
if(num_2!=0){
if(num_2!=1){
cout<<"There are "<<num_2<<" students who are not placed,because of the applied condition."<<endl;}
else{
cout<<"There is "<<num_2<<" student who is not placed,because of the applied condition."<<endl;}
}
}
blank=0;;
for(i=0;i<row;i++){
for(j=0;j<column;j++){
if(project[i][j]=='\0'){
blank++;
}
}
}
cout<<endl<<"There are "<<blank<<" places.";
while(num_3==-1){
cout<<endl<<"Number of 3rd year students: ";
cin>>num_3;
if(num_3>blank)
num_3=0;
}
if(num_3==-1){
num_3=0;
}
for(i=0;i<row;i++){
for(j=0;j<column;j++){
if(project[i][j]=='\0'){
if(project[i-1][j]!='-'&&project[i+1][j]!='-'&&project[i][j-1]!='-'&&project[i][j+1]!='-'&&project[i-1][j]!='a'&&project[i+1][j]!='a'&&project[i][j-1]!='a'&&project[i][j+1]!='a'&&project[i-1][j]!='b'&&project[i+1][j]!='b'&&project[i][j-1]!='b'&&project[i][j+1]!='2'&&project[i-1][j]!='3'&&project[i+1][j]!='3'&&project[i][j-1]!='3'&&project[i][j+1]!='3'){
project[i][j]='3';
num_3--;
if(num_3==0){
j=column-1;
i=row-1;}
}
}
}
}
for(i=0;i<row;i++){
for(j=0;j<column;j++){
cout<<project[i][j]<<" ";
}
cout<<endl;
}
if(num_3!=0){
if(num_3!=1){
cout<<"There are "<<num_3<<" students who are not placed,because of the applied condition."<<endl;}
else{
cout<<"There is "<<num_3<<" student who is not placed,because of the applied condition."<<endl;}
}
blank=0;;
for(i=0;i<row;i++){
for(j=0;j<column;j++){
if(project[i][j]=='\0'){
blank++;
}
}
}
cout<<endl<<"There are "<<blank<<" places.";
while(num_4==-1){
cout<<endl<<"Number of 4th year students: ";
cin>>num_4;
if(num_4>blank)
num_4=-1;
}
if(num_4==-1){
num_4=0;
}
for(i=0;i<row;i++){
for(j=0;j<column;j++){
if(project[i][j]=='\0'){
if(project[i-1][j]!='+'&&project[i+1][j]!='+'&&project[i][j-1]!='+'&&project[i][j+1]!='+'&&project[i-1][j]!='b'&&project[i+1][j]!='b'&&project[i][j-1]!='b'&&project[i][j+1]!='b'&&project[i-1][j]!='c'&&project[i+1][j]!='c'&&project[i][j-1]!='c'&&project[i][j+1]!='c'&&project[i-1][j]!='4'&&project[i+1][j]!='4'&&project[i][j-1]!='4'&&project[i][j+1]!='4'){
project[i][j]='4';
num_4--;
if(num_4==0){
j=column-1;
i=row-1;}
}
}
}
}
for(i=0;i<row;i++){
for(j=0;j<column;j++){
cout<<project[i][j]<<" ";
}
cout<<endl;
}
if(num_4!=0){
if(num_4!=1){
cout<<"There are "<<num_4<<" students who are not placed,because of the applied condition."<<endl;}
else{
cout<<"There is "<<num_4<<" student who is not placed,because of the applied condition."<<endl;}
}
getch();
clrscr();
cout<<"So the seat graph takes the form like below: "<<endl;
for(i=0;i<row;i++){
for(j=0;j<column;j++){
if(project[i][j]=='*'){
cout<<"b21 "<<" ";
}
else if(project[i][j]=='-'){
cout<<"b31 "<<" ";
}
else if(project[i][j]=='+'){
cout<<"b41 "<<" ";
}
else if(project[i][j]=='a'){
cout<<"b32 "<<" ";
}
else if(project[i][j]=='b'){
cout<<"b42 "<<" ";
}
else if(project[i][j]=='c'){
cout<<"b43 "<<" ";
}
else if(project[i][j]=='1'){
cout<<"yr 1"<<" ";
}
else if(project[i][j]=='2'){
cout<<"yr 2"<<" ";
}
else if(project[i][j]=='3'){
cout<<"yr 3"<<" ";
}
else if(project[i][j]=='4'){
cout<<"yr 4"<<" ";
}
else if(project[i][j]=='\0')
cout<<" "<<" ";
}
cout<<endl<<endl;
}
getch();
}
}
}
void seat_plan::seat_arrangement(int file_id){
if(file_id==1){
clrscr();
int num1=0,num2=0,num3=0,num4=0,num21=0,num31=0,
num41=0,num32=0,num42=0,
num43=0;
char r1[200],r2[200],r3[200],r4[200],r21[200],r31[200],r41[200],r32[200],r42[200],r43[200];
int row,column;
char c;
char bat_name[10];
char project[100][100];
cout<<"Number of rows: ";
cin>>row;
cout<<"Number of columns: ";
cin>>column;
if(row!=0&&column!=0){
int i,j;
for(i=0;i<row+1;i++){
for(j=0;j<column+1;j++){
project[i][j]='\0';
}
}
i=0;
cout<<"File of 2...1: ";
cin>>bat_name;
strcat(bat_name,".txt");
ifstream file21(bat_name);
if(!file21){
cout<<"Number of 2...1: "<<num21;
}
else{
while(!file21.eof()){
file21.get(c);
if(c=='\n'){
num21++;
}
if((c>=48&&c<=57)||(c==' ')){
r21[i]=c;
i++;
}
}
cout<<"Number of 2...1: "<<num21;}
i=0;
cout<<endl<<"File of 3...1: ";
cin>>bat_name;
strcat(bat_name,".txt");
ifstream file31(bat_name);
if(!file31){
cout<<"Number of 3...1: "<<num31<<endl;
}
else{
while(!file31.eof()){
file31.get(c);
if(c=='\n'){
num31++;
}
if((c>=48&&c<=57)||(c==' ')){
r31[i]=c;
i++;
}
}
cout<<"Number of 3...1: "<<num31<<endl;}
i=0;
cout<<"File of 4...1: ";
cin>>bat_name;
strcat(bat_name,".txt");
ifstream file41(bat_name);
if(!file41){
cout<<"Number of 4...1: "<<num41<<endl;
}
else{
while(!file41.eof()){
file41.get(c);
if(c=='\n'){
num41++;
}
if((c>=48&&c<=57)||(c==' ')){
r41[i]=c;
i++;
}
}
cout<<"Number of 4...1: "<<num41<<endl; }
i=0;
cout<<"File of 3...2: ";
cin>>bat_name;
strcat(bat_name,".txt");
ifstream file32(bat_name);
if(!file32){
cout<<"Number of 3...2: "<<num32<<endl;
}
else{
while(!file32.eof()){
file32.get(c);
if(c=='\n'){
num32++;
}
if((c>=48&&c<=57)||(c==' ')){
r32[i]=c;
i++;
}
}
cout<<"Number of 3...2: "<<num32<<endl;}
i=0;
cout<<"File of 4...2: ";
cin>>bat_name;
strcat(bat_name,".txt");
ifstream file42(bat_name);
if(!file42){
cout<<"Number of 4...2: "<<num42<<endl;
}
else{
while(!file42.eof()){
file42.get(c);
if(c=='\n'){
num42++;
}
if((c>=48&&c<=57)||(c==' ')){
r42[i]=c;
i++;
}
}
cout<<"Number of 4...2: "<<num42<<endl;}
i=0;
cout<<"File of 4...3: ";
cin>>bat_name;
strcat(bat_name,".txt");
ifstream file43(bat_name);
if(!file43){
cout<<"Number of 4...3: "<<num43<<endl;
}
else{
while(!file43.eof()){
file43.get(c);
if(c=='\n'){
num43++;
}
if((c>=48&&c<=57)||(c==' ')){
r43[i]=c;
i++;
}
}
cout<<"Number of 4...3: "<<num43<<endl;}
if(num21>0)
{
for(i=0;i<row;i++){
for(j=0;j<column;j++){
if(project[i-1][j]!='*'&&project[i+1][j]!='*'&&project[i][j-1]!='*'&&project[i][j-1]!='*'){
project[i][j]='*';
num21--;
if(num21==0){
j=column-1;
i=row-1;
}
}
}
}
}
if(num31>0){
for(i=0;i<row;i++){
for(j=0;j<column;j++){
if(project[i][j]!='*'&&project[i-1][j]!='-'&&project[i+1][j]!='-'&&project[i][j-1]!='-'&&project[i][j+1]!='-'&&project[i-1][j]!='*'&&project[i+1][j]!='*'&&project[i][j-1]!='*'&&project[i][j+1]!='*'){
project[i][j]='-';
num31--;}
if(num31==0){
j=column-1;
i=row-1;
}
}
}
}
if(num41>0){
for(i=0;i<row;i++){
for(j=0;j<column;j++){
if(project[i][j]!='*'&&project[i][j]!='-'&&project[i-1][j]!='+'&&project[i+1][j]!='+'&&project[i][j-1]!='+'&&project[i][j+1]!='+'&&project[i-1][j]!='*'&&project[i+1][j]!='*'&&project[i][j-1]!='*'&&project[i][j+1]!='*'){
project[i][j]='+';
num41--;}
if(num41==0){
j=column-1;
i=row-1;
}
}
}
}
if(num32>0){
for(i=0;i<row;i++){
for(j=0;j<column;j++){
if(project[i][j]!='*'&&project[i][j]!='-'&&project[i][j]!='+'&&project[i-1][j]!='a'&&project[i+1][j]!='a'&&project[i][j-1]!='a'&&project[i][j+1]!='a'&&project[i-1][j]!='-'&&project[i+1][j]!='-'&&project[i][j-1]!='-'&&project[i][j+1]!='-'){
project[i][j]='a';
num32--;}
if(num32==0){
j=column-1;
i=row-1;
}
}
}
}
if(num42>0){
for(i=0;i<row;i++){
for(j=0;j<column;j++){
if(project[i][j]!='*'&&project[i][j]!='-'&&project[i][j]!='+'&&project[i][j]!='a'&&project[i-1][j]!='b'&&project[i+1][j]!='b'&&project[i][j-1]!='b'&&project[i][j+1]!='b'&&project[i-1][j]!='a'&&project[i+1][j]!='a'&&project[i][j-1]!='a'&&project[i][j+1]!='a'){
project[i][j]='b';
num42--;}
if(num42==0){
j=column-1;
i=row-1;
}
}
}
}
if(num43>0){
for(i=0;i<row;i++){
for(j=0;j<column;j++){
if(project[i][j]!='*'&&project[i][j]!='-'&&project[i][j]!='+'&&project[i][j]!='a'&&project[i][j]!='b'&&project[i-1][j]!='b'&&project[i+1][j]!='b'&&project[i][j-1]!='b'&&project[i][j+1]!='b'&&project[i-1][j]!='+'&&project[i+1][j]!='+'&&project[i][j-1]!='+'&&project[i][j+1]!='+'&&project[i-1][j]!='c'&&project[i+1][j]!='c'&&project[i][j-1]!='c'&&project[i][j+1]!='c'){
project[i][j]='c';
num43--;}
if(num43==0){
j=column-1;
i=row-1;
}
}
}
}
int blank=0;;
for(i=0;i<row;i++){
for(j=0;j<column;j++){
if(project[i][j]=='\0'){
blank++;
}
}
}
cout<<endl<<"There are "<<blank<<" places."<<endl;
i=0;
cout<<"File of 1st year: ";
cin>>bat_name;
strcat(bat_name,".txt");
ifstream file1(bat_name);
if(!file1){
cout<<"Number of 1st year students: "<<num1<<endl;
}
else{
while(!file1.eof()){
file1.get(c);
if(c=='\n'){
num1++;
}
if((c>=48&&c<=57)||(c==' ')){
r1[i]=c;
i++;
}
}
cout<<"Number of 1st year student: "<<num1<<endl;
for(i=0;i<row;i++){
for(j=0;j<column;j++){
if(project[i][j]=='\0'){
if(project[i-1][j]!='*'&&project[i+1][j]!='*'&&project[i][j-1]!='*'&&project[i][j+1]!='*'&&project[i-1][j]!='-'&&project[i+1][j]!='-'&&project[i][j-1]!='-'&&project[i][j+1]!='-'&&project[i-1][j]!='+'&&project[i+1][j]!='+'&&project[i][j-1]!='+'&&project[i][j+1]!='+'&&project[i-1][j]!='1'&&project[i+1][j]!='1'&&project[i][j-1]!='1'&&project[i][j+1]!='1'){
project[i][j]='1';
num1--;
if(num1==0){
j=column-1;
i=row-1;}
}
}
}
}
for(i=0;i<row;i++){
for(j=0;j<column;j++){
cout<<project[i][j]<<" ";
}
cout<<endl;
}
if(num1!=0){
if(num1!=1){
cout<<"There are "<<num1<<" students who are not placed,because of the applied condition."<<endl;}
else{
cout<<"There is "<<num1<<" students who is not placed,because of the applied condition."<<endl;}
}
}
blank=0;
for(i=0;i<row;i++){
for(j=0;j<column;j++){
if(project[i][j]=='\0'){
blank++;
}
}
}
cout<<endl<<"There are "<<blank<<" places.";
i=0;
cout<<"File of 2nd year: ";
cin>>bat_name;
strcat(bat_name,".txt");
ifstream file2(bat_name);
if(!file2){
cout<<"Number of 2nd year students: "<<num2<<endl;
}
else{
while(!file2.eof()){
file2.get(c);
if(c=='\n'){
num2++;
}
if((c>=48&&c<=57)||(c==' ')){
r2[i]=c;
i++;
}
}
cout<<endl<<"Number of 2nd year student: "<<num2<<endl;
for(i=0;i<row;i++){
for(j=0;j<column;j++){
if(project[i][j]=='\0'){
if(project[i-1][j]!='*'&&project[i+1][j]!='*'&&project[i][j-1]!='*'&&project[i][j+1]!='*'&&project[i-1][j]!='a'&&project[i+1][j]!='a'&&project[i][j-1]!='a'&&project[i][j+1]!='a'&&project[i-1][j]!='b'&&project[i+1][j]!='b'&&project[i][j-1]!='b'&&project[i][j+1]!='2'&&project[i-1][j]!='2'&&project[i+1][j]!='2'&&project[i][j-1]!='2'&&project[i][j+1]!='2'){
project[i][j]='2';
num2--;
if(num2==0){
j=column-1;
i=row-1;}
}
}
}
}
for(i=0;i<row;i++){
for(j=0;j<column;j++){
cout<<project[i][j]<<" ";
}
cout<<endl;
}
if(num2!=0){
if(num2!=1){
cout<<"There are "<<num2<<" students who are not placed,because of the applied condition."<<endl;}
else{
cout<<"There is "<<num2<<" student who is not placed,because of the applied condition."<<endl;}
}
}
blank=0;
for(i=0;i<row;i++){
for(j=0;j<column;j++){
if(project[i][j]=='\0'){
blank++;
}
}
}
cout<<endl<<"There are "<<blank<<" places.";
i=0;
cout<<"File of 3rd year: ";
cin>>bat_name;
strcat(bat_name,".txt");
ifstream file3(bat_name);
if(!file3){
cout<<"Number of 3rd year students: "<<num3<<endl;
}
else{
while(!file3.eof()){
file3.get(c);
if(c=='\n'){
num3++;
}
if((c>=48&&c<=57)||(c==' ')){
r3[i]=c;
i++;
}
}
cout<<endl<<"Number of 3rd year student: "<<num3<<endl;
for(i=0;i<row;i++){
for(j=0;j<column;j++){
if(project[i][j]=='\0'){
if(project[i-1][j]!='-'&&project[i+1][j]!='-'&&project[i][j-1]!='-'&&project[i][j+1]!='-'&&project[i-1][j]!='a'&&project[i+1][j]!='a'&&project[i][j-1]!='a'&&project[i][j+1]!='a'&&project[i-1][j]!='b'&&project[i+1][j]!='b'&&project[i][j-1]!='b'&&project[i][j+1]!='2'&&project[i-1][j]!='3'&&project[i+1][j]!='3'&&project[i][j-1]!='3'&&project[i][j+1]!='3'){
project[i][j]='3';
num3--;
if(num3==0){
j=column-1;
i=row-1;}
}
}
}
}
for(i=0;i<row;i++){
for(j=0;j<column;j++){
cout<<project[i][j]<<" ";
}
cout<<endl;
}
if(num3!=0){
if(num3!=1){
cout<<"There are "<<num3<<" students who are not placed,because of the applied condition."<<endl;}
else{
cout<<"There is "<<num3<<" student who is not placed,because of the applied condition."<<endl;}
}
}
blank=0;
for(i=0;i<row;i++){
for(j=0;j<column;j++){
if(project[i][j]=='\0'){
blank++;
}
}
}
cout<<endl<<"There are "<<blank<<" places.";
i=0;
cout<<"File of 4th year: ";
cin>>bat_name;
strcat(bat_name,".txt");
ifstream file4(bat_name);
if(!file4){
cout<<"Number of 4th year students: "<<num4<<endl;
}
else{
while(!file4.eof()){
file4.get(c);
if(c=='\n'){
num4++;
}
if((c>=48&&c<=57)||(c==' ')){
r4[i]=c;
i++;
}
}
cout<<endl<<"Number of 4th year student: "<<num4<<endl;
for(i=0;i<row;i++){
for(j=0;j<column;j++){
if(project[i][j]=='\0'){
if(project[i-1][j]!='+'&&project[i+1][j]!='+'&&project[i][j-1]!='+'&&project[i][j+1]!='+'&&project[i-1][j]!='b'&&project[i+1][j]!='b'&&project[i][j-1]!='b'&&project[i][j+1]!='b'&&project[i-1][j]!='c'&&project[i+1][j]!='c'&&project[i][j-1]!='c'&&project[i][j+1]!='c'&&project[i-1][j]!='4'&&project[i+1][j]!='4'&&project[i][j-1]!='4'&&project[i][j+1]!='4'){
project[i][j]='4';
num4--;
if(num4==0){
j=column-1;
i=row-1;}
}
}
}
}
for(i=0;i<row;i++){
for(j=0;j<column;j++){
cout<<project[i][j]<<" ";
}
cout<<endl;
}
if(num4!=0){
if(num4!=1){
cout<<"There are "<<num4<<" students who are not placed,because of the applied condition."<<endl;}
else{
cout<<"There is "<<num4<<" student who is not placed,because of the applied condition."<<endl;}
}
}
getch();
clrscr();
int a=0,b=0,p=0,d=0,e=0,f=0,g=0,h=0,l=0,n=0;
cout<<"So Plotting students we get: "<<endl<<endl;
for(i=0;i<row;i++){
for(j=0;j<column;j++){
if(project[i][j]=='*'){
do{
cout<<r21[a];
a++;}while(a%7!=0);
cout<<" ";
}
else if(project[i][j]=='-'){
do{
cout<<r31[b];
b++;}while(b%7!=0);
cout<<" ";
}
else if(project[i][j]=='+'){
do{
cout<<r41[p];
p++;}while(p%7!=0);
cout<<" ";
}
else if(project[i][j]=='a'){
do{
cout<<r32[d];
d++;}while(d%7!=0);
cout<<" ";
}
else if(project[i][j]=='b'){
do{
cout<<r42[e];
e++;}while(e%7!=0);
cout<<" ";
}
else if(project[i][j]=='c'){
do{
cout<<r43[f];
f++;}while(f%7!=0);
cout<<" ";
}
else if(project[i][j]=='1'){
do{
cout<<r1[g];
g++;}while(g%7!=0);
cout<<" ";
}
else if(project[i][j]=='2'){
do{
cout<<r2[h];
h++;}while(h%7!=0);
cout<<" ";
}
else if(project[i][j]=='3'){
do{
cout<<r3[l];
l++;}while(l%7!=0);
cout<<" ";
}
else if(project[i][j]=='4'){
do{
cout<<r4[n];
n++;}while(n%7!=0);
cout<<" ";
}
else if(project[i][j]=='\0')
cout<<" "<<" ";
}
cout<<endl<<endl;
}
getch();
}
}
}
///////////////* class inherits *///////////////////////
class with_file:public seat_plan{
protected:
char name[20];
char roll[7];
int k;
int file_id;
char c;
char bat_name[10];
int count;
int pos;
char choice;
public:
with_file(){ //call of constructor
k=0;
file_id=1;
choice='\0';
}
void sitting();
};
void with_file::sitting(){
count=1;
while(count){
clrscr();
cout<<"To write data press w"<<endl<<"To read file press r"<<endl<<"To remove previously edited file press c"<<endl<<"To set students on seat press s"<<endl<<"Otherwise e"<<endl<<"Choice: ";
cin>>choice;
switch(choice){
case 'w':
clrscr();
pos=1;
while(pos){
clrscr();
cout<<"To give info about regular students press 1"<<endl<<"To give info about backlock students press 2"<<endl<<"To do nothing press 0"<<endl<<"Choice: ";
cin>>pos;
if(pos==1){
clrscr();
cout<<"Give batch name: ";
cin>>bat_name;
strcat(bat_name,".txt");
ofstream file(bat_name,ios::ate);
int loop;
cout<<"How many students info will be given? ";
cin>>loop;
while(loop){
cout<<"Name: ";
gets(name);
cout<<"Roll no: ";
gets(roll);
int i=0;
file<<endl;
while(name[i]){
file<<name[i];
i++;
}
while(i<20){
file<<'\0';
i++;
}
i=0;
while(roll[i]){
file<<roll[i];
i++;
}
while(i<7){
file<<' ';
i++;
}
loop--;
}
file.close();
}
if(pos==2){
clrscr();
cout<<"Choose backlock type: ";
cin>>bat_name;
strcat(bat_name,".txt");
ofstream file(bat_name,ios::ate);
int loop;
cout<<"How many students info will be given? ";
cin>>loop;
while(loop){
cout<<"Name: ";
gets(name);
cout<<"Roll no: ";
gets(roll);
int i=0;
file<<endl;
while(name[i]){
file<<name[i];
i++;
}
while(i<20){
file<<'\0';
i++;
}
i=0;
while(roll[i]){
file<<roll[i];
i++;
}
while(i<7){
file<<' ';
i++;
}
loop--;
}
file.close();
}
}
break;
case 'r':
clrscr();
cout<<"Give Batch Name or backlock type: ";
cin>>bat_name;
strcat(bat_name,".txt");
ifstream open_file(bat_name);
if(!open_file){
cout<<"There is no information about this batch"<<endl;
}
else{
while(!open_file.eof()){
open_file.get(c);
if(c=='\0'){
cout<<" ";
}
else{
cout<<c;
}
}
}
open_file.close();
getch();
break;
case 'c':
clrscr();
char file[80];
printf("File to delete: ");
gets(file);
if (remove(file) == 0)
printf("Removed %s.\n",file);
else
perror("remove");
getch();
break;
case 's':
clrscr();
seat_arrangement(file_id);
break;
case 'e':
count=0;
break;
}
}
}
void show(seat_plan ob){ //definition of friend function
float without_file_id=1.0;
ob.seat_arrangement(without_file_id);
}
void opening(){ //initial with short graphics
int i;
int driver,mode;
driver=DETECT;
initgraph(&driver,&mode,"d:\\tc\\bgi");
i=1;
int j=0,k=0,l=0;
while(j<100){
setcolor(i);
if(j%10==0){
l++;
}
if(l==1){
circle(240,75,4-k);
delay(100);
i=i+4;
if(i==50)
i=3;
}
if(l==2){
circle(260,75,4-k);
delay(80);
i=i+4;
if(i==50)
i=3;
}
if(l==3){
circle(280,75,4-k);
delay(100);
i=i+4;
if(i==50)
i=3;
}
setcolor(9);
settextstyle(1,HORIZ_DIR,7);
outtextxy(0,0,"Loading");
j++;
}
j=0;
do
{
setcolor(i);
circle(310,220,135);
circle(310,220,130);
circle(310,220,133);
delay(100);
cleardevice();
i=i+4;
if(i==50)
i=3;
setcolor(9);
settextstyle(4,HORIZ_DIR,5);
outtextxy(184,190,"SEAT PLAN");
j++;
if(j==20)
break;
}while(!kbhit());
closegraph();
restorecrtmode();
}
void finish(){ //finishes with short graphics
int i,j;
int driver,mode;
driver=DETECT;
initgraph(&driver,&mode,"d:\\tc\\bgi");
i=1;
j=0;
do
{
delay(100);
cleardevice();
setcolor(i);
i=i+4;
if(i==50)
i=3;
settextstyle(4,HORIZ_DIR,10);
outtextxy(100,120,"Thanks");
j++;
if(j==30)
break;
}while(!kbhit());
closegraph();
restorecrtmode();
}
int main(){
opening();
seat_plan ob;
with_file ob2;
int choice=1;
textcolor(BLACK);
textbackground(WHITE);
while(choice){
clrscr();
cout<<"To arrange seat plotting students press 1"<<endl<<"To arrange seat not plotting students press 2"<<endl<<"To do nothing press 0"<<endl<<"Choice: ";
cin>>choice;
if(choice==1){
textcolor(BLACK);
textbackground(WHITE);
ob2.sitting();
}
else if(choice==2){
textcolor(BLACK);
textbackground(WHITE);
show(ob);
}
}
finish();
return 0;
}
No comments:
Post a Comment