can someone please help with these questions

i have a few questions that i cant answer.
my program is for inputting student details into a file then searching for certain ones.

here is my code:
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
const int NUM_SCORES = 6;
	typedef struct 
	{
		int day;
		int month;
		int year;
	} Date;
	struct Student 
	{
		int number;
		Date dob;
		float scores[NUM_SCORES];
	}; Student student;

	const int MAX_ITEMS = 10;
	 
	struct ListType 
	{
		int length;
		int info[MAX_ITEMS];
	}; ListType list;

	struct ItemType
	{
		int aStudent;
		int findStudent;
	};

void readstudent(void);
void writestudent(void);

int _tmain(int argc, _TCHAR* argv[])
{
	Student student [15];

	ListType list;
	list.length = 0;

	ifstream in ("StudentFile.txt");	
	
    while(!in.eof())
		for (int i = 0; i < 15; i++)
	{
		in >> student[i].number >> student[i].dob.day >> student[i].dob.month >> student[i].dob.year 
		>> student[i].scores[0]
		>> student[i].scores[1]
		>> student[i].scores[2]
		>> student[i].scores[3]
		>> student[i].scores[4]
		>> student[i].scores[5];
	}

	cout << "The Class List Is: " << endl;
	cout << "Name " << "\t" << "Date" << "\t\t" << "Scores" << endl;
	for (int i = 0; i < 15; i++)
		{
			cout << student[i].number << "\t" << student[i].dob.day << "/" << student[i].dob.month << "/" << student[i].dob.year << "\t" 
			<< student[i].scores[0]
			<< student[i].scores[1]
			<< student[i].scores[2]
			<< student[i].scores[3]
			<< student[i].scores[4]
			<< student[i].scores[5] << endl;

		}

	in.close();	

	return 0;
}

void readstudent(ifstream &in, ItemType &aStudent)
{
	in >> student.number;
	in >> student.dob.day >> student.dob.month >> student.dob.year;
	for (int i = 0; i < NUM_SCORES; i++)
	{
		in >> student.scores[i];
	}
}

void writestudent(ItemType student)
{
   //not sure what to put here
}


i've answered most of the questions i was given but i'm confused on the last few:
one of the things i have to do is assign list.info[list.length] to aStudent - not sure what this means
another is call method writeStudent() to output an element of list.info of type student.
last thing is enter a student number to search for a student into findStudent.number and if the student is found call writeStudent() to output findStudent.

Last edited on
hope someone can help with these questions
thanks
For your writestudent() function, you will want to do the opposite of what you did in your readstudent() function.

Your question about "assign list.info[ list.length ] to aStudent" sounds like you are supposed to use the list structure for containing your student info. You might have misread some of the assignment, but without all of what you were given, I'm only guessing.
ok but I'm still not sure what do put into writestudent() do you mean just cout >> student.number etc. and the assignment gave some code so I have to make the changes to it so what would I change in the code to assign list.info [list.length] to aStudent? thanks
can anyone help with this?
thanks
closed account (D80DSL3A)
As kooth wrote, it seems like the ListType structure is meant for storing the student info. You are storing it in an array you created in _tmain() instead.

If this is correct try:
1
2
3
4
5
struct ListType 
	{
		int length;
		Student info[MAX_ITEMS];
	}; ListType list;

instead of:
1
2
3
4
5
struct ListType 
	{
		int length;
		int info[MAX_ITEMS];
	}; ListType list;


Omit the for loop on line 42 - that's what the while loop is for. Increment list.length in the loop.
You may also want to modify the condition in the while loop (line 41) to check for array size reached as well as !in.eof(). Your array size is MAX_ITEMS.

Actually, as I look further at your code it looks more and more like a mess of confusion:
1) The prototypes for readstudent() and writestudent() don't match the definitions.
2) You are probably supposed to be using the readstudent() for getting the data from the file. Call this function in place of your code lines 44-50. This function should be taking a Student& instead of an ItemType& as an argument. The variable name in the function should be aStudent, not student. Pass list[list.length] to the function when you call it in the while loop.
3) What is struct ItemType supposed to be for?

4) The writestudent() is probably supposed to be doing what lines 57-63 are doing.

Hope that gets you going in a better direction!
Last edited on
the code from lines 41 to 65 are just for displaying the text file so the for loop on line 42 needs to stay in or i get errors. the assignment said on the while loop instead of checking for the sentinel value, check for eof - line 41 is this correct?

i have to call readStudent() to read in the first student from the file and into variable aStudent
so after line 67 i will put cout "Enter students number"; then i will call the function, etc. i just want to get the void functions right before i do this

and if the student is found writeStudent() has to output findStudent but im not sure what to put into writeStudent. writeStudent() has to output an element of list.info of type student and if the student is not found output findStudent.number and not found message

as for struct ItemType i had to declare aStudent and findStudent as type ItemType
please i really need help with this heres what i tired but i know its wrong because it says findStudent.number is undefined

1
2
3
4
5
6
7
8
void writestudent(ItemType Student)
{
	cout << "Enter a student number : ";
	if (student.number == findStudent.number)
		cout << findStudent;
	else
		cout << "student number not found";	
}
Topic archived. No new replies allowed.