Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

A student has a first name (fname), a last name (lname), an identification numbe

ID: 3794913 • Letter: A

Question

A student has a first name (fname), a last name (lname), an identification number (id), a gender (male/female), a course name (cname) and the number of lectures (lcount) attended by the student. a. Define gender as an enum b. Define a structure datatype for the student. (Use character array of 30 characters for the members fname, lname , cname and enum for gender) c. From the provided input file (students.txt) read the number of students, create an array of students to hold all information and fill it with the data in the file (one student per line). d. Print all students to the user. e. Print all female students to the user. A student has a first name (fname), a last name (lname), an identification number (id), a gender (male/female), a course name (cname) and the number of lectures (lcount) attended by the student. a. Define gender as an enum b. Define a structure datatype for the student. (Use character array of 30 characters for the members fname, lname , cname and enum for gender) c. From the provided input file (students.txt) read the number of students, create an array of students to hold all information and fill it with the data in the file (one student per line). d. Print all students to the user. e. Print all female students to the user. A student has a first name (fname), a last name (lname), an identification number (id), a gender (male/female), a course name (cname) and the number of lectures (lcount) attended by the student. a. Define gender as an enum b. Define a structure datatype for the student. (Use character array of 30 characters for the members fname, lname , cname and enum for gender) c. From the provided input file (students.txt) read the number of students, create an array of students to hold all information and fill it with the data in the file (one student per line). d. Print all students to the user. e. Print all female students to the user.

Explanation / Answer

#include <stdio.h>
#include <string.h>
#define BUFF_SIZE 1024
enum gender { male, female };
struct Student {
char fname[50];
char lname[50];   
char cname[50];
int id;
int lcount;
enum gender gen;
};
struct Student students[50];
struct Student insertRec(char buff[BUFF_SIZE]);
void printAllStudents(struct Student students[]);
void printFemaleStudents(struct Student students[]);
int main() {

FILE *fp;
char buff[BUFF_SIZE];
int i=1;

fp = fopen("students.txt", "r"); /* provide students details in a file using , seperated Ex: fname,lname,cname,id,lcount,gen -- max 50 users */
  
fgets(buff, BUFF_SIZE, (FILE*)fp);
students[0] = insertRec(buff);
while(buff != EOF) {
   fgets(buff, BUFF_SIZE, (FILE*)fp);
   students[0] = insertRec(buff);
   i = i+1;     
}
fclose(fp);
printAllStudents(students);
printFemaleStudents(students);
return 0;
}

struct Student insertRec(char buff[]) {
int i = 0;
char *p = strtok (buff, ",");
char *array[6];

while (p != NULL)
{
array[i++] = p;
p = strtok (NULL, "/");
}
struct Student stud;
stud.fname = array[0];
   stud.lname = array[1];
   stud.cname = array[2];
   stud.id = array[3];
   stud.lcount = array[4];
   stud.gen = array[5];
   return student;
}

void printAllStudents(struct Student students[]) {
   for(i=0; i<sizeof(students); i++)
{
printf(" Records of STUDENT : %d ", i+1);
printf(" Id is: %d ", students[i].fname);
printf(" Name is: %s ", students[i].lname);
printf(" Percentage is: %f ",students[i].id);
}
  
}

void printFemaleStudents(struct Student students[]) {
   for(i=0; i<sizeof(students); i++)
{
       if(students[i].gender == gender.female) {
           printf(" Records of STUDENT : %d ", i+1);
           printf(" Id is: %d ", students[i].fname);
           printf(" Name is: %s ", students[i].lname);
           printf(" Percentage is: %f ",students[i].id);
       }

}
  
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Chat Now And Get Quote