text file not displaying right

Pages: 12
both solutions are not working for me
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
93
94
95
96
97
98
99
#include "stdafx.h"
using namespace std;

const int NUM_SCORES = 6;
const int MAX_ITEMS = 15;

struct Date
 {
	int day;
	int month;
	int year;
 };

struct Student 
 {
	int number;
	Date dob;
	float scores[NUM_SCORES];
 };



typedef Student ItemType; 
struct ListType 
{
	int length;
	ItemType info [MAX_ITEMS];
};

 ListType list;
 ItemType aStudent, findStudent; 
 void readStudent (string name);
 void writeStudent ();
 void BinarySearch (ItemType& item, bool& found);
 int ForgetfulBinarySearch(ItemType& item, bool& found); 
 int REBinarySearch (ItemType& item, bool& found);

int _tmain(int argc, _TCHAR* argv[])
{
	readStudent("StudentFile.txt");
	bool found = false;
	
	cout << "Enter a student number : ";
	cin >> findStudent.number;
	
	BinarySearch(findStudent, found);
		
	if (found)
               {	
		writeStudent();
		
	}
	 else
		cout << "Student number not found in file\n" <<endl;

 return 0;
}

void readStudent (string name)
{
	
	list.length = 0;
	
	fstream infile;
	 infile.open(name);
	 int n = 0;
	while (infile >> aStudent[n].number >> aStudent[n].dob.day >> aStudent[n].dob.month >> aStudent[n].dob.year >> aStudent[n].scores[0] >> 
				aStudent[n].scores[1] >> aStudent[n].scores[2] >> aStudent[n].scores[3] >> aStudent[n].scores[4] >> aStudent[n].scores[5]) 
		{
			n++;
		};
int i=0;
	cout << "Student Number\tDOB (DD/MM/YYYY)\tStudent Scores" << endl;
	cout << "--------------\t----------------\t--------------" << endl << endl; 
	do
	{
		cout << "\t" << aStudent[i].number << "\t" << aStudent[i].dob.day <<"/" <<aStudent[i].dob.month <<"/" << aStudent[i].dob.year <<"\t\t"<< 
			aStudent[i].scores[0] << " " << aStudent[i].scores[1] << " " << aStudent[i].scores[2] << " " << aStudent[i].scores[3] << " " << 
			aStudent[i].scores[4] << " " << aStudent[i].scores[5]<< endl;
		i++;
	} while (aStudent[i].number >= 1 ); 


			list.info[list.length] = aStudent; 			                                list.length++;
		


 infile.close();
}

void writeStudent ()
{
	cout << "Student Number: " << findStudent.number << endl;
	cout << "DOB: " << findStudent.dob.day << "/" << findStudent.dob.month << "/" << findStudent.dob.year << endl;
	cout << "Exam Results: ";
	for (int i = 0; i < 6; i++)
		cout << " " << findStudent.scores[i];

}


ok heres all the code to do with opening the file. don't worry about the binary search stuff thats just for searching the file
Topic archived. No new replies allowed.
Pages: 12