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

im having trouble with my struct can someone help. #include <iostream> #include

ID: 3658987 • Letter: I

Question

im having trouble with my struct can someone help.


#include <iostream>

#include <fstream>

#include <string>

using namespace std;


const int MAXNUMCLIENTS = 15; // up to 100 books can be stored


struct Clients

{

char sex;

string name;

int answers;

};

typedef Clients ClientList [MAXNUMCLIENTS];

void ANSWERS (ifstream & inFile, ClientList clients);

void NAMES (ifstream & inFile, ClientList clients);

int Char2Int (char); // Used to convert char to int

const int BITSIZE = 10;


int main()

{

ifstream inFile;

string sex;

int males = 0,

females = 0;


cout << "======================================" << endl;

cout << "Weclome to the Computer Dating Service" << endl;

cout << "======================================" << endl;

cout << "-=-= Initial Client Data as Input =-=-" << endl;

cout << "Sex" << " " << "Answers" << " " << "Name" << endl;

cout << "-----------------------------------------------------" << endl;




inFile.open("clients.txt");


while (!inFile.eof())// loops while not end of file

{

inFile >> sex;

if(sex == "M")

{

cout << sex << " ";

ANSWERS (inFile);

NAMES (inFile);

males = males + 1;

}

else if(sex == "F")

{

cout << sex << " ";

ANSWERS (inFile);

NAMES (inFile);

females = females + 1;

}

else

{

cout << "error";

}

}

cout << "========================================" << endl;

cout << "Number of female clients: " << females << endl;

cout << "Number of male clients: " << males << endl;

}

void ANSWERS(ifstream & inFile, ClientList clients)

{

char numTemp; // character read from file

int numIntTemp; // used in conversion into int

int answers[BITSIZE]; // first array given after command

//ignores 1 spaces to get first operand

inFile.ignore(1, ' ');

//loop to get first array

for (int i = 0; i < 10; i++)

{

inFile.get(numTemp); //Gets char from text file

answers[i] = Char2Int(numTemp); //Calls Char2Int converter

if(answers[i] <= 0 || answers[i] >= 5)

{

answers[i] = 3;

cout << answers[i];

inFile.ignore(1,' ');

}

else

{

cout << answers[i];//Displays the ints in array 1

inFile.ignore(1,' ');

}

}

cout << " "; // Space between array 1 and resultant

inFile.ignore(300, ' '); // Ignore the rest of the line

}


void NAMES(ifstream & inFile, ClientList clients)

{

string name;

inFile.ignore(22, '/n');

getline(inFile,name);

cout << name;

cout << endl;

}

//This function is when a char given in the text file has to be converted to an integer.

int Char2Int(char a)

{

return (a - '0'); // return an int

}

Explanation / Answer

instead of writing "if(sex == "M")" use this to compare str1 with str2 =>str1.compare(str2) u can make ur program run