STUDENTATTENDANCE
CALCULATOR
Computer Programming
(CSE 101)
Report For Project
Faculty Name: - Radhika Nambiar : 28302
Submitted By: - Nishant Singh
Registration No: - 12216370
Roll No: - 17
Group Members:-
Nishant singh (12216370)
Tulin Kuru (12216476)
Saket Kumar (12216541)
Rishi Kumar (12216596)
1
Introduction: -
The Student Attendance Calculator is a simple
C program that allows users to manage
student attendance records. The program uses
an array of structures to store student details
such as email, registration number, course,
total lectures, and lectures attended. The
program provides a menu-driven interface for
users to add new students, display all
students, search for a student by registration
number, and modify student details.
The student attendance calculator is designed
to be a console-based program. It uses simple
user interface that allows users to enter the
attendance details of each student. The
program consists of several modules,
including the main function, input module,
output module, and calculation module.
2
Module Explanation: -
Modify Student Details [void modify( )]: -
The user can modify the student details like
name, roll number and attendance using this
module
The system saves the record to the file after the
information is entered.
Insert details of student [void edit( )]: -
The user can add an existing email in the
calculator using this module. Addition can be
made of the Students’ name, password,
registration number, or email address by
selecting the insert detail to be added. The
system saves the added record to the file after
the additions are made.
3
Display detail of student[void displayList ( )]: -
This module allows the student to add all of the
subjects in their record. The user can add any subject
of choice and then add how many classes/total
classes to attend and then how he attended then
percentage will come.
Search specific information [void SearchRecord( )]:-
This module allows the user to search the record for
a specified detail like subject wise attendance
percentage or overall percentage. Following that, the
system returns a list of result that satisfy the search
criteria.
Delete any detail [FILE *del( )]: -
The user can delete a student information from the
record using this module. The user can delete a
registration no. by selecting it and then confirming
the action. When you delete a registration no., it is
removed from the Attendance file.
4
Code: -
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
struct student {
char name[20];
int roll_no;
int attendance;
};
void add(FILE *fp);
FILE *del(FILE *fp);
void modify(FILE *fp);
void displayList(FILE *fp);
void searchRecord(FILE *fp);
int main() {
FILE *fp;
struct student s;
int option;
if ((fp = fopen("attendance.txt", "rb+")) == NULL) {
if ((fp = fopen("attendance.txt", "wb+")) == NULL) {
printf("Can't open file\n");
return 0;
}
}
while (1) {
printf("\tSTUDENT ATTENDANCE CALCULATOR\t");
printf("\n\t\t1. ADD STUDENT");
printf("\n\t\t2. DELETE STUDENT");
printf("\n\t\t3. MODIFY STUDENT");
printf("\n\t\t4. DISPLAY STUDENT LIST");
printf("\n\t\t5. Search Record");
printf("\n\t\t0. EXIT");
printf("\nEnter Your Option: ");
scanf("%d", &option);
switch (option) {
case 0:
return 1;
break;
case 1:
5
add(fp);
break;
case 2:
fp = del(fp);
break;
case 3:
modify(fp);
break;
case 4:
displayList(fp);
break;
case 5:
searchRecord(fp);
break;
default:
printf("\nInvalid Option");
printf("\nProgram terminated");
exit(0);
}
}
return 1;
}
void add(FILE *fp) {
struct student s;
fseek(fp, 0, SEEK_END);
printf("\nEnter name: ");
scanf("%s", s.name);
printf("Enter roll number: ");
scanf("%d", &s.roll_no);
printf("Enter attendance: ");
scanf("%d", &s.attendance);
fwrite(&s, sizeof(s), 1, fp);
}
FILE *del(FILE *fp) {
struct student s;
FILE *ftmp;
int r;
printf("Enter roll number to delete: ");
scanf("%d", &r);
if ((ftmp = fopen("tmpfile", "wb")) == NULL) {
printf("\nCan't open file");
return fp;
6
}
rewind(fp);
while (fread(&s, sizeof(s), 1, fp) == 1) {
if (s.roll_no != r)
fwrite(&s, sizeof(s), 1, ftmp);
}
fclose(fp);
fclose(ftmp);
remove("attendance.txt");
rename("tmpfile", "attendance.txt");
if ((fp = fopen("attendance.txt", "rb+")) == NULL) {
printf("Error opening file\n");
exit(1);
}
return fp;
}
void modify(FILE *fp) {
struct student s;
int r;
printf("Enter roll number to modify: ");
scanf("%d", &r);
rewind(fp);
while (fread(&s, sizeof(s), 1, fp) == 1) {
if (s.roll_no == r) {
fseek(fp, -sizeof(s), SEEK_CUR);
printf("\nEnter new name: ");
scanf("%s", s.name);
printf("Enter new roll number: ");
scanf("%d", &s.roll_no);
printf("Enter new attendance: ");
scanf("%d", &s.attendance);
fwrite(&s, sizeof(s), 1, fp);
break;
}
}
}
void displayList(FILE *fp) {
7
struct student s;
rewind(fp);
printf("\nName\tRoll No\tAttendance\n");
while (fread(&s, sizeof(s), 1, fp) == 1) {
printf("%s\t%d\t%d\n", s.name, s.roll_no, s.attendance);
}
}
void searchRecord(FILE *fp) {
struct student s;
int r, found = 0;
printf("Enter roll number to search: ");
scanf("%d", &r);
rewind(fp);
while (fread(&s, sizeof(s), 1, fp) == 1) {
if (s.roll_no == r) {
found = 1;
printf("\nRecord Found\n");
printf("\nName: %s", s.name);
printf("\nRoll No: %d", s.roll_no);
printf("\nAttendance: %d", s.attendance);
break;
}
}
if (!found)
printf("\nRecord Not Found\n");
}
8
Output Snapshots:
1.Add Student:-
9
2. Delete Student:-
10
3. Modify Student:-
11
4. Display Student List
12
5. Search Record
13
6. Exit Code:-
14