Parsing the file for student information

I have written the code so far but i am stuck with how to get the output , which i have pasted. Pleas can someone help me?
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
#include <iostream>
#include <vector>
#include <fstream>
using namespace std;

struct Course
{
string coursename;
int lectures;
};

struct Student
{
string fname;
char minit;
string lname;
string id;
string username;
vector<Course>enrolled; 
};



int main(){
Student professor;
Course types;
ifstream inputFile;

inputFile.open("psuid.txt");

while(!inputFile){
cout << "File not opened!" << endl;
}

getline(inputFile, professor.fname);
getline(inputFile, professor.minit);
getline(inputFile, professor.lname);
getline(inputFile, professor.id);
getline(inputFile, professor.username);


cout << professor.fname << endl;
cout << professor.minit << endl;
cout << professor.lname << endl;
cout << professor.id << endl;
cout << professor.username << endl;
}



Sample input:
FNAME: Chaman
MINIT: S
LNAME: Chintu
ID: 12345
USER: chachi12
CMPSC121-002-003L
-M 905AM 50Lecture - T 10 05 AM 110 Lab
-W 905AM 50Lecture MATH140-001
-M1225PM 50Lecture -T1225PM 50Lecture -W1225PM 50Lecture -R1225PM 50Lecture PSU007-001
-W0600PM 50Lecture ENGL101-004
-M1115AM 50Lecture -W1115AM 50Lecture -F1115AM 50Lecture PHYS211-003-006L
-T 335PM 90Lecture -R 335PM 90Lecture - F 12 00 PM 110 Lab

Sample output:
FNAME: Chaman
MINIT: S
LNAME: Chintu
ID: 23423
USER: chach13

CMPSC121-002-003L
3 lectures
MATH140-001
4 lectures
PSU007-001
1 lecture
ENGL101-004
3 lectures
PHYS211-003-006L
3 lectures
explain in plain english how you'll get the number of lectures from each line
(¿what do the codes mean?)
Last edited on
So I was thinking to read the title line for the lecture, then skip whitespace and use peek() to look at the first character of the next line. If it's a '-' then it's a lecture for the current course.

Im new to this struct and file parsing so needed help and guidance.
closed account (E0p9LyTq)
Is your input really such a sloppy mess? There is no consistency of formatting for each class entry as to scheduling. And your flagging of the schedules isn't the same with each entry.

It can be parsed out, but it won't be easy.
The input is as follows:
FNAME: Andrew
MINIT: S
LNAME: Yu
ID: 912345678
USER: auy77
CMPSC121-002-003L
-M 9 05 AM 50 Lecture
- T 10 05 AM 110 Lab
-W 9 05 AM 50 Lecture
MATH140-001
-M 12 25 PM 50 Lecture
-T 12 25 PM 50 Lecture
-W 12 25 PM 50 Lecture
-R 12 25 PM 50 Lecture
PSU007-001
-W 06 00 PM 50 Lecture
ENGL101-004
-M 11 15 AM 50 Lecture
-W 11 15 AM 50 Lecture
-F 11 15 AM 50 Lecture
PHYS211-003-006L
-T 3 35 PM 90 Lecture
-R 3 35 PM 90 Lecture
-F 12 00 PM 110 Lab
Topic archived. No new replies allowed.