Listing and analyzing data from a file

Hello! I am a novice programmer and I'm having trouble with one of my exercises. I need to create a program that reads the student information (SSN, First & last name, test score) from a file, and then uses four global parallel arrays to store the student information. I'm required to use an int array to store SSNs, a string array to store first names, a string array to store last names, and a double array to store scores. The operations include listing the students' info like this
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
     SSN     Last-Name  First-Name Score
628130189    James,      Paul         92.0
237698211    Cook ,       Daniel      86.0
201895367    Garza,       Melessa   78.0
491066285    Barbara,    Jessica     62.0
168606868    Bruce,       Elizabeth  90.0
378205732    Lee,          Sarah       91.5
118453900    Brian,        David       87.0
583192186    Garza,       Cody        92.0
226665118    Lewis,       Gage        78.0
175382843    Collins,      James      69.5
816231095    White,       Ann          88.5
376651608    Jackson,    Mark        72.0
508234567    Freeman,   Mark        86.0
763211099    William,     Jack         52.0
286204723    Rodriguez, John         69.5


But of course, the .txt file is just SSN First-name last-name and score unaligned and separated by comas. Then I have to display the student with the highest score, and then the lowest, and the average of all scores, which i think I can do my self. I just dont know how to get it to read the file in the first place and make the data so that it's organized into columns.

Also...I have to report an error message and exit the program immediately if the file cannot be found? Otherwise, the program should display a main menu as follows to allow the user to complete the listed
operations.

Here's what I have so far.
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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
#include <iostream>
#include<iomanip>
#include<fstream>
using namespace std;

void mainmenu();
/*
void sort_name();();
void sort_ssn();
void sort_score ();
*/
void average(); 
void lowest_score();
void highest_score();
void open_file();

const int totNum = 15; //my global variables
int ssn[totNum];
string fname [totNum]
string lname [totNum]
double score [totNum]

int main ()
{

	
		char choice;
		
		ifstream fin;
		fin.open("students.txt")
		
	for (1=0; 1 <= totalNum; i++)//this is where I'm stuck
	{
		 fin.
		
		
		
	}
	do
	{	mainmenu(); //calling main menu funtion
		cin >> choice;
		cin.ignore (10, '\n'); //spacing
		switch(choice) // switch statment for multiple cases for flexibility
		{
			case 'l':
			case 'L':
			case '1': open_file(); break; 
			/*
			case 'h':
			case 'H':	
			case '2': highest_score(); break; 
			case 'o':
			case 'O':
			case '3': lowest_score(); break;
			case 'a':
			case 'A':
			case '4': average(); break;
			
			case 's':
			case 'S':	
			case '5': sort_ssn(); break; //operation 5-7 is a bonus work
			case 'n':
			case 'N':
			case '6': sort_name(); break;
			case 'c':
			case 'C': 
			case '7': sort_score();break;
			*/
			case 'e':
			case 'E':	
			case '0': break;
			default: cout << "Wrong choice!" << endl; break;	
		}
		cout << endl;
	}	while(choice != '0'); // && choice !='E' && choice!='e')	
}
void mainmenu() //output main menu
{
	cout << "Main Menu (Assignment 8)" << endl;
	cout << "1. List students' infromation (L)" << endl;
	/*
	cout << "2. Find the highest score (H)" << endl;
	cout << "3. Find the lowest score (O)" << endl;
	cout << "4. Calculate the average score (A)" << endl;
	
	cout << "5. Sort students by SSN (S)" << endl;
	cout << "6. Dort students by name (N)" << endl;
	cout << "7. Sort students by score (C)" << endl;
	*/
	cout << "0. Exit" << endl;
	cout << "Please select an option: ";
}


Any advice or help is very appreciated!
Last edited on
Topic archived. No new replies allowed.