Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Test case 6 Test case 7 Test case 8 Test case 9 Test case 1 0 Test case 1 1 Test case 1 2 Test

Test case 6
Test case 7
Test case 8
Test case 9
Test case 10 Test case 11
Test case 12
Test case 13
Test case 14
Test case 15 Test case 16
Test case 17
Test case 18
Test case 19Name,Email,Join Time,Leave Time,Duration(Minutes)
Feyza Nur
Duman,fnur.duman@tedu.edu.tr,02/28/202010:54:38,02/28/202012:56:38,122.0
Eda Nur
YILMAZ,enur.yilmaz@tedu.edu.tr,02/28/202010:57:09,02/28/202010:58:28,2.0
Serhat Gokhan
YAMAC,sgokhan.yamac@tedu.edu.tr,02/28/202010:59:19,02/28/202012:56:28,118.0
Duru Yamac,,02/28/202010:59:27,02/28/202012:56:11,117.0
Asya Hale
Gencel,ahale.gencel@tedu.edu.tr,02/28/202010:59:28,02/28/202012:56:38,118.0
Eda Nur
YILMAZ,enur.yilmaz@tedu.edu.tr,02/28/202010:59:30,02/28/202012:33:32,95.0
Taner
Ceyhun,taner.ceyhun@tedu.edu.tr,02/28/202011:00:12,02/28/202011:00:24,1.0
Sevil
TERZI,sevil.terzi@tedu.edu.tr,02/28/202011:00:33,02/28/202012:21:07,81.0#include
#include
#include
#include // for tolower function
#define MAX_NAME_LENGTH 100
#define MAX_EMAIL_LENGTH 100
#define MAX_LINE_LENGTH 256
#define MAX_ATTENDEES 500
typedef struct {
char firstName[MAX_NAME_LENGTH];
double totalDuration;
} Attendee;
// Fonksiyonun banda tanmlanmaldr.
int compareAttendees(const void* a, const void* b){
Attendee* attendeeA =(Attendee*)a;
Attendee* attendeeB =(Attendee*)b;
return strcmp(attendeeA->firstName, attendeeB->firstName);
}
void processAttendance(const char* filename, double minDuration, int sorted){
FILE* file = fopen(filename,"r");
if (file == NULL){
printf("Unable to open the file.
");
return;
}
char line[MAX_LINE_LENGTH];
Attendee attendees[MAX_ATTENDEES];
int attendeeCount =0;
// Skip the header line
fgets(line, MAX_LINE_LENGTH, file);
while (fgets(line, MAX_LINE_LENGTH, file)!= NULL){
char name[MAX_NAME_LENGTH];
double duration;
// Parse the line to extract name and duration
sscanf(line,"%[^,],%*[^,],%*[^,],%*[^,],%lf", name, &duration);
// Extract the names
char* token = strtok(name,"");
char* names[5];
int nameCount =0;
// Split the name into tokens
while (token != NULL && nameCount <5){
names[nameCount++]= token;
token = strtok(NULL,"");
}
// Reorder the names
char firstName[MAX_NAME_LENGTH]="";
if (nameCount >1){
// Son ismi baa al
strcpy(firstName, names[nameCount -1]);
strcat(firstName,"");
for (int i =0; i < nameCount -1; i++){
strcat(firstName, names[i]);
strcat(firstName,"");
}
} else {
strcpy(firstName, names[0]);
}
// Kk harfe dntrmeden nce orijinal ismi sakla
char originalName[MAX_NAME_LENGTH];
strcpy(originalName, firstName);
// Kk harfe dntr
for (int i =0; firstName[i]!='\0'; i++){
firstName[i]= tolower(firstName[i]);
}
// Ayn kii mi kontrol et
int existingIndex =-1;
for (int i =0; i < attendeeCount; i++){
char temp[MAX_NAME_LENGTH];
strcpy(temp, attendees[i].firstName);
// Kk harfe dntr
for (int j =0; temp[j]!='\0'; j++){
temp[j]= tolower(temp[j]);
}
if (strcmp(temp, firstName)==0){
existingIndex = i;
break;
}
}
if (existingIndex !=-1){
// Ayn kii ise sreyi ekle
attendees[existingIndex].totalDuration += duration;
} else {
// Yeni bir katlmc ise listeye ekle
strcpy(attendees[attendeeCount].firstName, originalName);
attendees[attendeeCount].totalDuration = duration;
attendeeCount++;
}
}
fclose(file);
// Sralkt isteniyorsa katlmclar srala
if (sorted){
qsort(attendees, attendeeCount, sizeof(Attendee), compareAttendees);
}
// Katlmc bilgilerini gster
for (int i =0; i < attendeeCount; i++){
if (attendees[i].totalDuration >= minDuration){
printf("%s %.2lf
", attendees[i].firstName, attendees[i].totalDuration);
}
}
}
int main(){
char filename[MAX_LINE_LENGTH];
double minDuration;
char sortedInput[10];
int sorted;
//printf("Enter the input file name, minimum duration, and 'sorted' option (e.g., filename.txt 60 sorted): ");
scanf("%s %lf %s", filename, &minDuration, sortedInput);
// Kk harfe dntr
for (int i =0; sortedInput[i]!='\0'; i++){
sortedInput[i]= tolower(sortedInput[i]);
}
if (strcmp(sortedInput, "sorted")==0){
sorted =1;
} else {
sorted =

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access with AI-Powered Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions