In
this post I'll show you a code of a C++ project which I was involved in
a couple of days ago. This C++ project is about a member management
system to a Gymnasium. In this application, first you have to login to
the application using a user name and password. The user name and
password is "admin" and "password" in simple letters.
after you logged in you can add a member to the system and see all members and find a member by the members ID and you can delete a member. those are the main functions of this application. here are few screen shots of this application
I was tested this application on Code Blocks. and here is the code
after you logged in you can add a member to the system and see all members and find a member by the members ID and you can delete a member. those are the main functions of this application. here are few screen shots of this application
I was tested this application on Code Blocks. and here is the code
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 | /* ==================================================== |**************************************************| |**** Atlas Gymnasium Member Management System ****| |**************************************************| |****** C++ code explanations and comments ******| |**************************************************| |****** By Yuhanthika rasangani de silva *********| |**************************************************| ==================================================== */ // All the header files that needed to this console program #include <iostream> #include <fstream> #include <iomanip> #include <stdlib.h> #include <conio.h> #include <string> using namespace std; // Member class that all the variable are included class member { int idnum; char fname[50]; char sname[50]; char address[100]; int cnumber; int age; public: void getdata(); // Get inputs from the user void showdata() const; // Show previously inputed data int getIDNum() const; // Get ID number }; // Method that takes inputs from the user void member::getdata() { cout << "\t\t ====================================" << endl; cout << "\t\t |---- ATLAS GYMNASIUM (PVT)LTD ----|" << endl; cout << "\t\t ====================================" << endl << endl << endl; cout<<"\nENTER THE MEMBER ID: "; cin>>idnum; cout<<"\n\nENTER FIRST NAME: "; cin.ignore(); cin.getline(fname,50); cout<<"\n\nENTER SURNAME: "; //cin.ignore(); cin.getline(sname,50); cout<<"\n\nENTER ADDRESS: "; //cin.ignore(); cin.getline(address,100); cout<<"\n\nENTER CONTACT NUMBER: "; cin >> cnumber; cout<<"\n\nENTER AGE: "; cin>>age; } // show data according to the structure void member::showdata() const { cout<<"\nID NUMBER: "<<idnum; cout<<"\nFIRST NAME: "<<fname; cout<<"\nSURNAME: "<<sname; cout<<"\nADDRESS: "<<address; cout<<"\nCONTACT NUMBER: "<<cnumber; cout<<"\nAGE: "<<age; } // get id number and stored it in idnum variable. int member::getIDNum() const { return idnum; } // Member registering file handling methods // In this method the inputs which takes from user are stored in a data file called member.dat void add_member() { member st; ofstream outFile; outFile.open("member.dat",ios::binary|ios::app); st.getdata(); outFile.write(reinterpret_cast<char *> (&st), sizeof(member)); outFile.close(); cout<<"\n\nMEMBER DATA HAS BEEN CREATED!"; cin.ignore(); cin.get(); } // methods that output all the data stored in the member.dat file void display_all() { member st; ifstream inFile; inFile.open("member.dat",ios::binary); if(!inFile) { cout<<"FILE COULD NOT BE OPEN !! PRESS ANY KEY..."; cin.ignore(); cin.get(); return; } cout<<"\n\n\n\t\tDISPLAY ALL RECORD !!!\n\n"; while(inFile.read(reinterpret_cast<char *> (&st), sizeof(member))) { st.showdata(); cout<<"\n\n====================================\n"; } inFile.close(); cin.ignore(); cin.get(); } // Display the relevant data according to the id number that user provides void display_sp(int n) { member st; ifstream inFile; inFile.open("member.dat",ios::binary); if(!inFile) { cout<<"FILE COULD NOT BE OPEN!! PRESS ANY KEY .."; cin.ignore(); cin.get(); return; } bool flag=false; while(inFile.read(reinterpret_cast<char *> (&st), sizeof(member))) { if(st.getIDNum()==n) { st.showdata(); flag=true; } } inFile.close(); if(flag==false) cout<<"\n\nRECORD NOT EXIST!"; cin.ignore(); cin.get(); } // Gets id number from the user and output the relevant data. // Edit data relevant to the user ID provided void edit_member(int n) { bool found=false; member st; fstream File; File.open("member.dat",ios::binary|ios::in|ios::out); if(!File) { cout<<"FILE COULD NOT BE OPEN !! PRESS ANY KEY..."; cin.ignore(); cin.get(); return; } while(!File.eof() && found==false) { File.read(reinterpret_cast<char *> (&st), sizeof(member)); if(st.getIDNum()==n) { st.showdata(); cout<<"\n\nPLEASE ENTER THE NEW DETAILS OF THE MEMBER "<<endl; st.getdata(); int pos=(-1)*static_cast<int>(sizeof(st)); File.seekp(pos,ios::cur); File.write(reinterpret_cast<char *> (&st), sizeof(member)); cout<<"\n\n\t RECORD UPDATED!"; found=true; } } File.close(); if(found==false) cout<<"\n\n RECORD NOT FOUND "; cin.ignore(); cin.get(); } // Delete the member relevant to the user inputed ID void delete_member(int n) { member st; ifstream inFile; inFile.open("member.dat",ios::binary); if(!inFile) { cout<<"FILE COULD NOT BE OPEN !! PRESS ANY KEY..."; cin.ignore(); cin.get(); return; } ofstream outFile; outFile.open("Temp.dat",ios::out); inFile.seekg(0,ios::beg); while(inFile.read(reinterpret_cast<char *> (&st), sizeof(member))) { if(st.getIDNum()!=n) { outFile.write(reinterpret_cast<char *> (&st), sizeof(member)); } } outFile.close(); inFile.close(); remove("member.dat"); rename("Temp.dat","member.dat"); cout<<"\n\n\tRECORD DELETED .."; cin.ignore(); cin.get(); } // Exit the console application void exit() { system("cls"); cout << "\t\t ====================================" << endl; cout << "\t\t |---- ATLAS GYMNASIUM (PVT)LTD ----|" << endl; cout << "\t\t ====================================" << endl << endl << endl; cout << "\t\t\t THANK YOU!!!" << endl; exit(0); } // The main menu that the user interact with // Main outputs that user sees void main_menu() { char ch; int num; cout.setf(ios::fixed|ios::showpoint); cout<<setprecision(2); do { system("cls"); cout << "\t\t ====================================" << endl; cout << "\t\t |---- ATLAS GYMNASIUM (PVT)LTD ----|" << endl; cout << "\t\t ====================================" << endl << endl << endl; cout<<"\t\t@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@"; cout<<"\n\n\t\t1. ADD NEW MEMBER"; cout<<"\n\n\t\t2. DISPLAY ALL MEMBERS"; cout<<"\n\n\t\t3. SEARCH MEMBER"; cout<<"\n\n\t\t4. EDIT MEMBER"; cout<<"\n\n\t\t5. DELETE MEMBER"; cout<<"\n\n\t\t6. EXIT"; cout<<"\n\n\t\t@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@"; cout<<"\n\n\t\tPLEASE ENTER YOUR CHOICE (1-6): "; cin>>ch; system("cls"); switch(ch) { case '1': add_member(); break; case '2': display_all(); break; case '3': cout<<"\n\n\tPLEASE ENTER MEMBER ID: "; cin>>num; display_sp(num); break; case '4': cout<<"\n\n\tPLEASE ENTER MEMBER ID: "; cin>>num; edit_member(num);break; case '5': cout<<"\n\n\tPLEASE ENTER MEMBER ID: "; cin>>num; delete_member(num);break; case '6': exit();break; default: cout<<"\a"; } }while(ch!='6'); } // user login window // Enter the application providing the exact username and password int main(){ string UserName; string Password =""; char ch; system("cls"); cout << "\t\t ====================================" << endl; cout << "\t\t |---- ATLAS GYMNASIUM (PVT)LTD ----|" << endl; cout << "\t\t ====================================" << endl << endl << endl; cout << "\t_______________________________________________________" << endl; cout << "\tPLEASE ENTER USERNAME AND PASSWORD TO ENTER THE SYSTEM!" << endl; cout << "\t_______________________________________________________" << endl << endl; cout << "\tENTER USERNAME: "; cin >> UserName; cout << endl; cout << "\tENTER PASSWORD: "; ch = _getch(); while(ch != 13){//character 13 is enter Password.push_back(ch); cout << '*'; ch = _getch(); } if(UserName == "admin" && Password == "password"){ system("cls"); cout << "\t\t ====================================" << endl; cout << "\t\t |---- ATLAS GYMNASIUM (PVT)LTD ----|" << endl; cout << "\t\t ====================================" << endl << endl << endl; cout << "\t\t\tACCESS GRANTED!" << endl; system("Pause"); main_menu(); }else{ cout << "\t\t ====================================" << endl; cout << "\t\t |---- ATLAS GYMNASIUM (PVT)LTD ----|" << endl; cout << "\t\t ====================================" << endl << endl << endl; cout << "\t\t\tACCESS ABORTED!...\n"; main(); } } |
If you have any questions feel free to ask by commenting. And if you have any idea of developing this application please do share them with us!
0 Comments