Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New Feature added-To Delete a member's record #2

Open
wants to merge 31 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
7c96ec3
Update README
dhruvhacks Jul 20, 2016
d61a043
To help create Database
dhruvhacks Jul 20, 2016
9f49ec3
Main cpp file
dhruvhacks Jul 20, 2016
4d2e350
Function's Definations
dhruvhacks Jul 20, 2016
85b8f90
Blank database
dhruvhacks Jul 22, 2016
aefd1ba
Issues Cleared
dhruvhacks Jul 22, 2016
ac596bb
Features Updated
dhruvhacks Jul 22, 2016
b641587
Update README
dhruvhacks Jul 22, 2016
7382f6e
Update README
dhruvhacks Jul 22, 2016
c35c924
Feature added
dhruvhacks Aug 9, 2016
4700286
Iteration extended
dhruvhacks Aug 9, 2016
a534c7d
Update README
dhruvhacks Aug 9, 2016
e757496
Debugged
dhruvhacks Aug 30, 2016
431f464
Iterations increased
dhruvhacks Aug 30, 2016
3e21e46
Bugs Fixed
dhruvhacks Sep 2, 2016
321ac73
Iterations Increased
dhruvhacks Sep 2, 2016
dee7d03
New Edit Feature Added
dhruvhacks Sep 21, 2016
b13c7aa
Iterations Added
dhruvhacks Sep 21, 2016
43bec3b
New Edit Feature Added
dhruvhacks Sep 21, 2016
9043165
Merge pull request #1 from ncs-jss/dhruv
dhruvhacks Sep 22, 2016
d39b163
Update main.cpp
animeshseemendra Jan 4, 2017
402238a
Update attendance.class
animeshseemendra Jan 4, 2017
2cbb58d
Merge pull request #2 from animeshseemendra/animeshseemendra-patch-2
animeshseemendra Jan 4, 2017
a6f67fc
Merge pull request #1 from animeshseemendra/animeshseemendra-patch-1
animeshseemendra Jan 4, 2017
22684d6
Update attendance.class
animeshseemendra Jan 6, 2017
5de5a41
Update attendance.class
animeshseemendra Jan 6, 2017
d472dbc
Update main.cpp
animeshseemendra Jan 6, 2017
9723bc7
Update attendance.class
animeshseemendra Jan 6, 2017
05b0423
Update attendance.class
animeshseemendra Jan 6, 2017
80e91b1
Update attendance.class
animeshseemendra Feb 17, 2017
a8b2ddc
Merge pull request #3 from animeshseemendra/animeshseemendra-patch-3
animeshseemendra Feb 17, 2017
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 19 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1 +1,19 @@
# ncs_attendance
#NCS Attendance

Features-

* **Quick attendance**. Marks present by simply pressing ENTER key, pressing anything else marks absent.
* Keeps a record of **Presence, Absence and total attendance**.
* View database.
* Modify any attendance record.
* Add new Members.
* Highly robust; hence easy to use.
* Works with **g++ compiler 4.9** on any platform.
* **new** View attendance record of any member with record of days missed.

To contribute-
* Download/Clone this repository and study _attendance.class_.
* Compile main.cpp using **g++** compiler. (g++ 4.9)
* Test with provided BLANK database or ask for original database from **authorized member**.

**_P.S._** While Compiling the code, you may notice many WARNINGS. Ignore them since they refer to vulnerable traversal in database and program is optimized against vulnerable traversal. **Executable file wil be ultimately created**.
321 changes: 321 additions & 0 deletions attendance.class
Original file line number Diff line number Diff line change
@@ -0,0 +1,321 @@
#include <fstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cstring>
#include <stdlib.h>
using namespace std;
int x;
class attendance
{
char name[25];
int att,ab,total,srno,j;
char tempd[12],date[100][12];
public:
void day();
void begin();
void getdat();
void show();
void save();
void task();
void update();
void newm();
void clear();
void end();
void caditshow();
void name_change();
void mem_delete();
attendance()
{
strcpy(name,"NULL");
strcpy(tempd,"NULL");
att=ab=total=srno=j=0;
}
};

void attendance::day()
{
if(strcmp(tempd,"NULL")==0)
{
clear();
printf("Enter todays date (dd/mm/yy)- ");
cin.ignore();
cin.getline(tempd,sizeof(tempd));
}
}

void attendance::begin()
{
clear();
printf("Welcome to NCS Attendance\n");
printf("What would you like to do??\n");
printf("1. Take Attendance\n2. See Attendance record\n");
printf("3. Update any record\n4. Add new members!\n");
printf("5. View specific member's attendance record. \n");
printf("6. Edit name of a member.\n7. Delete specific member.\n");
}


void attendance::getdat()
{

ifstream f0("database.dat",ios::binary);
attendance ob;
while(!f0.eof())
f0.read((char*)&ob,sizeof(ob));
if(ob.srno==0)
srno++;
else
srno=ob.srno+1;
f0.close();
cin.ignore();
printf("Enter name of Member\n");
cin.getline(name,sizeof(name));
printf("Enter attendance (if present earlier/required)\n");
cin>>att;
x=ob.srno;
cin.ignore();
}

void attendance::clear()
{
cout <<"\033[2J\033[1;1H";
}
void attendance::save()
{
ofstream f1("database.dat",ios::app|ios::binary);
f1.write((char*)this,sizeof(*this));
f1.close();
printf("Data Saved successfully.\n");
}

void attendance::show()
{
printf("\n\n");
ifstream f2("database.dat",ios::binary);
attendance ob;
f2.read((char*)&ob,sizeof(ob));
printf("Total Working days- %d \n",ob.total);
cout<<left<<setw(25)<<"Sr.no NAME"<<"PRESENCE"<<" | "<<"ABSENCE"<<endl;
while(!f2.eof())
{
if(ob.srno>9&&(ob.att>9||ob.ab>9))
cout<<ob.srno<<" "<<left<<setw(28)<<ob.name<<ob.att<<" | "<<ob.ab<<endl;
else if(ob.srno>9||(ob.att>9||ob.ab>9))
cout<<ob.srno<<" "<<left<<setw(29)<<ob.name<<ob.att<<" | "<<ob.ab<<endl;
else
cout<<ob.srno<<" "<<left<<setw(30)<<ob.name<<ob.att<<" | "<<ob.ab<<endl;
f2.read((char*)&ob,sizeof(ob));
}
f2.close();
}


void attendance::task()
{
fstream f3("database.dat",ios::binary|ios::in|ios::out);
attendance obj;
f3.read((char*)&obj,sizeof(obj));
while(!f3.eof())
{
if(obj.srno>9)
cout<<obj.srno<<" "<<left<<setw(29)<<obj.name<<obj.att<<" | "<<obj.ab<<endl;
else
cout<<obj.srno<<" "<<left<<setw(30)<<obj.name<<obj.att<<" | "<<obj.ab<<endl;
string temp;
getline(cin,temp);
if(temp.empty())
++(obj.att);
else
{ ++(obj.ab); strcpy(obj.date[obj.j],tempd); obj.j++; }
obj.total++;
f3.seekp(f3.tellp()-sizeof(obj));
f3.write((char*)&obj,sizeof(obj));
f3.read((char*)&obj,sizeof(obj));
}
f3.close();
}

void attendance::update()
{
while(1)
{
fstream f4("database.dat",ios::in|ios::out|ios::binary);
attendance ob;
int flag=1,no;
char choice;
show();
cout<<"Enter the serial number of member reffering the above attendance list\n";
cin>>no;
f4.read((char*)&ob,sizeof(ob));
while(!f4.eof())
{
if(no==ob.srno)
{
cout<<"\n"<<ob.srno<<" "<<left<<setw(30)<<ob.name<<ob.att<<" | "<<ob.ab<<endl;
while(1)
{
printf("Were you present?? (Y/N)\n");
cin>>choice;
if(choice=='Y'||choice=='y')
{ ob.att++; ob.ab--; ob.j--; break; }
else if(choice=='N'||choice=='n')
{ ob.att--; ob.ab++; strcpy(ob.date[ob.j],tempd); ob.j++; break; }
else
printf("Wrong choice\n");
}
f4.seekp(f4.tellp()-sizeof(ob));
f4.write((char*)&ob,sizeof(ob));
flag=0;
break;
}
f4.read((char*)&ob,sizeof(ob));
}
if(flag)
printf("No record found.\n");
f4.close();
cout<<"Want to update more records?? (Y/N)??\n";
cin>>choice;
if(choice=='y'||choice=='Y')
continue;
else if(choice=='n'||choice=='N')
break;
else
{ printf("Incorrect input. Further updates aborted.\n\n"); break; }
}
}

void attendance::newm()
{
while(1)
{
char choice;
getdat();
save();
cout<<"Want to add more members?? (Y/N)\n";
cin>>choice;
if(choice=='y'||choice=='Y')
continue;
else if(choice=='n'||choice=='N')
break;
else
{ cout<<"Wrong coice\n"; break; }
}
}

void attendance::end()
{
printf("\nThank you for using. :)\n\n");
}

void attendance::caditshow()
{
printf("\n\n");
int no,flag=1,count;
attendance ob;
ifstream f5("database.dat",ios::binary);
show();
printf("Enter member's serial number refering the above attendance list- ");
cin>>no;
f5.read((char*)&ob,sizeof(ob));
while(!f5.eof())
{
if(no==ob.srno)
{
cout<<"\n"<<ob.srno<<" "<<left<<setw(30)<<ob.name<<ob.att<<" | "<<ob.ab<<endl;
count=ob.j;
cout<<"Absent dates- \n";
while(count)
cout<<ob.date[--count]<<endl;
flag=0;
break;
}
f5.read((char*)&ob,sizeof(ob));
}
if(flag)
printf("No such member found\n");
}

void attendance::name_change()
{
printf("\n\n");
int no,flag=1;
attendance ob;
fstream f6("database.dat",ios::in|ios::out|ios::binary);
show();
printf("Enter member's serial number refering the above attendance list- ");
cin>>no;
f6.read((char*)&ob,sizeof(ob));
while(!f6.eof())
{
if(no==ob.srno)
{
cout<<"\n"<<ob.srno<<" "<<left<<setw(30)<<"Name of member - "<<ob.name<<endl;
printf("Enter the new name of member- ");
cin.ignore();
cin.getline(name,sizeof(name));
strcpy(ob.name,name);
f6.seekp(f6.tellp()-sizeof(ob));
f6.write((char*)&ob,sizeof(ob));
flag=0;
break;
}
f6.read((char*)&ob,sizeof(ob));
}
if(flag)
printf("No member found\n");
else
printf("Changes updated.\n");
}
void attendance::mem_delete()
{
ifstream f7("database.dat",ios::in|ios::binary);
ofstream f7t("temp.dat",ios::out|ios::binary);
attendance ob;
int flag=1,no,temp=0;
char choice;
show();
cout<<"Enter the serial number of member reffering the above attendance list\n";
cin>>no;
while(!f7.eof())
{
f7.read((char*)&ob,sizeof(ob));
if(temp!=1)
{
if(no==ob.srno)
{
flag=0;
cout<<"\n"<<ob.srno<<" "<<left<<setw(30)<<ob.name<<ob.att<<" | "<<ob.ab<<endl;
printf("Are you sure you want to delete this member?? (Y/N)\n");
cin>>choice;
if(choice=='N'||choice=='n')
{

f7t.write((char*)&ob,sizeof(ob));
}
else if(choice=='Y'||choice=='y')
{ temp=1;
continue;
}
}

}
if(ob.srno!=no)
{
if(temp==1)
{
ob.srno=ob.srno-1;
}
f7t.write((char*)&ob,sizeof(ob));
}
if(x==ob.srno)
break;

}
if(flag==1)
printf("No record found.\n");
f7.close();
f7t.close();
remove("database.dat");
rename("temp.dat","database.dat");
}
Empty file added database.dat
Empty file.
Loading