Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Repeat code but change the Enum gender to be an Enum class instead of a normal Enum. Code: //include basic libraries #include #include #include #include

Repeat code but change the Enum gender to be an Enum class instead of a normal Enum.

Code:

//include basic libraries

#include

#include

#include

#include

#include

using namespace std;

//enum declaration for gender

enum Gender{male, female};

//struct definition

struct Student{

string fname;

string lname;

you hand;

enum Gender gender;

string cname;

int lcount;

};

// read students function

vector readStudents(string file_name){

//open file in read mode

fstream myfile;

vector students;

//open file

myfile.open(file_name, ios::in);

//check if file is open

if(!myfile){

cout

}

//otherwise

else{

//read file line by line

string line;

//while there is a line to read

while(getline(myfile, line)){

//split line into tokens

stringstream ss(line);

//tokenize line

string token;

vector tokens;

//while there is a token, store in vector

while(getline(ss, token, ' ')){

tokens.push_back(token);

}

//create student object

Student student;

student.id = stoi(tokens[0]);

//set gender based on 0 or 1

if (stoi(tokens[1])==0){

student.gender = male;

}

else{

student.gender = female;

}

student.fname = tokens[2];

student.lname = tokens[3];

student.cname = tokens[4];

student.lcount =stoi(tokens[5]);

//push student object into vector

students.push_back(student);

}

}

//close file

myfile.close();

//return vector

return students;

}

//write printStudent that prints the student information

void printStudent(const Student& student){

//print student information

cout \"]>\"]>\"]>\"course:>\"]>;>

}

//define function getFemales that return a vector of Students

vector getFemales(const vector& stds){

//create vector of students

vector Femalestudents;

for(int i = 0; i

//check if student is female

if(stds[i].gender == female){

Femalestudents.push_back(stds[i]);

}

}

return Femalestudents;

}

//define function getLowAttendance

vector getLowAttendance(const vector& stds){

//create vector of students

vector LowAttendance;

for(int i = 0; i

//check if student has low attendance

if(stds[i].lcount

LowAttendance.push_back(stds[i]);

}

}

return LowAttendance;

}

int main(){

//read students from file

vector students = readStudents(\"students.txt\");

//print all students

cout ;>

for(int i = 0; i

printStudent(students[i]);

}

cout

cout ;>

cout \"the>

//get Female students

vector FemaleStds = getFemales(students);

//print FemaleStds

for(int i = 0; i

printStudent(FemaleStds[i]);

}

cout ;>

//print lowattendance students

cout ;>

cout \"the>;>

vector LowAttendanceStds = getLowAttendance(students);

for(int i = 0; i

printStudent(LowAttendanceStds[i]);

}

return 0;

}

students.txt

1 0 Mohammad Saleh CMP220 30

2 1 Sara Ali CMP220 28

5 0 Charles Dickens CMP220 25

4 1 Jain Austin CMP220 23

19 1 Ahlam Mosteghanemi CMP220 15

21 0 Mario Puzo CMP220 21

88 1 Marie Curie CMP220 30

1930 0 John Steinbeck CMP220 19

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored 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

Recommended Textbook for

Introduction to Wireless and Mobile Systems

Authors: Dharma P. Agrawal, Qing An Zeng

4th edition

1305087135, 978-1305087132, 9781305259621, 1305259629, 9781305537910 , 978-130508713

More Books

Students also viewed these Programming questions

Question

Define a traverse in Surveying?

Answered: 1 week ago