Hey everybody, I am super stuck on an assignment and need help just for the start of it. For the assignment I'm supposed to store information from text files into struct arrays.
What I am given
- enum program types.
- struct for nameType with first name, middle initial, and last name
- struct for studentType with name, ID, email, GPA, and program
- external files (classroster.txt) & (studentlist.txt)
- functions with parameters
This is the classroster.txt
20
Maleeha K Galloway 12832 smallpaul@optonline.net
Autumn J Oconnell 18704 noahb@yahoo.ca
Chaya R Hampton 19628 ralamosm@aol.com
Victoria W Searle 10114 dimensio@gmail.com
Deborah Q Barnett 18172 martink@optonline.net
Maja P Allison 13427 mirod@gmail.com
Darren B Wade 10121 metzzo@yahoo.ca
Amba C Whittington 12673 parksh@yahoo.com
Elisha P Medina 16115 improv@outlook.com
Renesmae Y Crane 17940 dkrishna@optonline.net
Jaiden E Kearns 14066 gavinls@yahoo.com
Lily L Espinoza 10204 dinther@live.com
Pippa Q Chamberlain 15084 qrczak@outlook.com
Keagan N West 19430 doche@verizon.net
Krisha O Montgomery 17526 biglou@gmail.com
Karl E Linebaugh 17156 mosses@live.com
Silva T Pressey 14606 corrada@hotmail.com
Anthony L Contreras 19425 mlewan@aol.com
Gordon G Cisneros 17928 cyrus@live.com
Azul X Rich 16185 jguyer@aol.com
What I am trying to figure out at the moment and what I am stuck on. I am only trying to work on the readClassRoster function at this point.
- Am I declaring my structs okay?
- What does the & on ifstream and int allow me to do?
- When and where do should I put ifstream...
- How do I input the things from the external file into arrays in nameType for first name, middle initial, and last name, which in turn will be used as the name variable in studentType?
- How do I go about inputting the next objects from the external files such as ID and email?
- When the function is finished, how should I go about calling it in main?
Things I've tried and issues caused.
- Using a for loop to input into something like in >> nameType[i].firstName. I have also tried other variations of this but they always return an "expected primary expression before...
Thanks to anyone who took the time to read and help out. I understand that the program doesn't even do anything but I just need the file input figured out. I'm not asking for the solution but an explanation and a "walkthrough" would be helpful. Thanks!
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64
|
#include <iostream>
#include <fstream>
#include <string>
using namespace std;
const int ARRAY_SIZE = 20;
enum programType {CSCI, DBMS, INFM, SDEV};
struct nameType
{
string firstName;
char middleInitial;
string lastName;
};
struct studentType
{
nameType name;
int ID;
string email;
int GPA;
programType program;
};
void readClassRoster(ifstream&, studentType[], int&);
void readProgramGPA(ifstream&, studentType[], int);
int findStudentByID(int, const studentType[], int);
double findHighestGPA(const studentType[], int);
void printHighestGPA(double, const studentType[], int);
int main()
{
return 0;
}
void readClassRoster(ifstream&, studentType[], int&)
{
}
void readProgramGPA(ifstream&, studentType[], int)
{
}
int findStudentByID(int, const studentType[], int)
{
return 0;
}
double findHighestGPA(const studentType[], int)
{
return 0;
}
void printHighestGPA(double, const studentType[], int)
{
}
|