This repository has been archived by the owner on Oct 8, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 52
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #119 from LeViiAcKerMan01/levii
Added Hostel Accomodation System which helps college students to reserve a room in the college and written in CPP
- Loading branch information
Showing
4 changed files
with
162 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Gomukh Hostel : 16500 :2 |
160 changes: 160 additions & 0 deletions
160
Hostel_Accomodation_System/Hostel_Accomodation_System.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,160 @@ | ||
#include<iostream> | ||
#include<fstream> | ||
#include<windows.h> | ||
#include<sstream> | ||
using namespace std; | ||
|
||
class Hostel{ | ||
private: | ||
string Name; | ||
int Rent, Bed; | ||
public: | ||
Hostel(string name, int rent, int bed) | ||
{ | ||
Name = name; | ||
Rent = rent; | ||
Bed = bed; | ||
} | ||
|
||
string getName() | ||
{ | ||
return Name; | ||
} | ||
int getRent() | ||
{ | ||
return Rent; | ||
} | ||
int getBed() | ||
{ | ||
return Bed; | ||
} | ||
|
||
void reserve() | ||
{ | ||
ifstream in("C:/Users/priya/Documents/HAS/Hostel.txt"); | ||
ofstream out("C:/Users/priya/Documents/HAS/Hostel Temp.txt"); | ||
|
||
string line; | ||
while(getline(in, line)) | ||
{ | ||
int pos = line.find("Gomukh Hostel"); | ||
if(pos != string::npos) | ||
{ | ||
int bed = Bed -1; | ||
Bed = bed; | ||
|
||
stringstream ss; | ||
ss << bed; | ||
string strBed = ss.str(); | ||
|
||
int bedPos = line.find_last_of(':'); | ||
line.replace(bedPos+1, string::npos, strBed); | ||
} | ||
out<<line<<endl; | ||
} | ||
out.close(); | ||
in.close(); | ||
remove("C:/Users/priya/Documents/HAS/Hostel.txt"); | ||
rename("C:/Users/priya/Documents/HAS/Hostel Temp.txt", "C:/Users/priya/Documents/HAS/Hostel.txt"); | ||
cout<<"\tBed reserved successfully!"<<endl; | ||
} | ||
}; | ||
|
||
class Student{ | ||
|
||
private: | ||
string Name, RollNo, Address; | ||
|
||
public: | ||
Student():Name(""),RollNo(""),Address(""){} | ||
|
||
void setName(string name) | ||
{ | ||
Name = name; | ||
} | ||
void setRollNo(string rollNo) | ||
{ | ||
RollNo = rollNo; | ||
} | ||
void setAddress(string address) | ||
{ | ||
Address = address; | ||
} | ||
|
||
string getName() | ||
{ | ||
return Name; | ||
} | ||
string getRollNo() | ||
{ | ||
return RollNo; | ||
} | ||
string getAddress() | ||
{ | ||
return Address; | ||
} | ||
}; | ||
|
||
int main(){ | ||
|
||
Hostel h("Gomukh Hostel", 16500, 3); | ||
|
||
ofstream out("C:/Users/priya/Documents/HAS/Hostel.txt"); | ||
out<<"\t"<<h.getName()<<" : "<<h.getRent()<<" : "<<h.getBed()<<endl; | ||
cout<<"Hostel data saved successfully!"<<endl; | ||
out.close(); | ||
Student s; | ||
|
||
bool exit = false; | ||
|
||
while(!exit) | ||
{ | ||
system("cls"); | ||
int val; | ||
cout<<"\tWELCOME TO HOSTEL ACCOMODATION SYSTEM"<<endl; | ||
cout<<"\t*************************************"<<endl; | ||
cout<<"\t1) Reserve a Bed."<<endl; | ||
cout<<"\t2) Exit"<<endl; | ||
cout<<"\tEnter Choice : "<<endl; | ||
cin >> val; | ||
|
||
if(val == 1) | ||
{ | ||
system("cls"); | ||
string name, rollNo, address; | ||
|
||
cout<<"\tEnter name of Student : "; | ||
cin >> name; | ||
s.setName(name); | ||
|
||
cout<<"\tEnter RollNo of the Student : "; | ||
cin >> rollNo; | ||
s.setRollNo(rollNo); | ||
|
||
cout<<"\tEnter Address of the Student : "; | ||
cin >> address; | ||
s.setRollNo(address); | ||
|
||
if(h.getBed() > 0){ | ||
|
||
h.reserve(); | ||
} | ||
else if(h.getBed() == 0){ | ||
|
||
cout<<"\tSorry, Bed not available"<<endl; | ||
} | ||
|
||
ofstream outFile("C:/Users/priya/Documents/HAS/Student.txt", ios::app); | ||
outFile<<"\t"<<s.getName()<<" : "<<s.getRollNo()<<" : "<<s.getAddress()<<endl; | ||
Sleep(5000); | ||
} | ||
|
||
else if(val == 2){ | ||
|
||
system("cls"); | ||
exit = true; | ||
cout<<"Good Luck!"<<endl; | ||
Sleep(3000); | ||
} | ||
} | ||
} |
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
|