Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Wrtite the contents of an array to a file a:\student.dat

Status
Not open for further replies.

Clock

Programmer
Jul 25, 2000
6
GR
I have to write the C++ declaration for a atruct calledTstudent that will store the following data:<br>course&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;3 digit number (stored as a string)<br>forename&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;20 characters<br>surname&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;20 characters<br>gender&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;enumerated type ( male, female)<br>age&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;integer<br><br>Then I have to create an array of Tstudent that will hold the data on 10 students.Finally i have to write the code for a function to write the contents of the array to a file called a:\student.dat<br><br><br>That is what I have to do.I have started to write the code but I am not sure if it is correct.That is what I have done:<br><br>struct Tstudent{<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;int course[3];<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;char forename[20];<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;char surname[20];<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;enum gender {male, female};<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;gender m,f;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;int age;<br>};<br><br>Then for the creation of the array I have done the<br>&nbsp;following :<br><br>double Tstudent[10];<br><br>That is all I have tried to do.Please help me complete my task.<br>Thank you!
 
&nbsp;&nbsp;&nbsp;&nbsp;Seems to me we saw this same or similar question not that long ago. The one thing I qucikly see is you said <i>course&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;3 digit number (stored as a string)</i> but you have declared this as an integer: <i>int course[3];</i>. Otherwise it looks like you are on the right track.<br> <p>James P. Cottingham<br><a href=mailto: > </a><br><a href= Veneer Co., Inc.</a><br>All opinions are mine alone and do not necessarily reflect those of my employer.
 
You mean it is right apart from the declaration for course?<br>If so how should I declare it?<br>
 
if indeed you are trying to store course as a string, then declare it: char course[3]<br>right now, by doing: int courser[3], you have created an array of integers. <p>ray<br><a href=mailto:rheindl@bju.edu>rheindl@bju.edu</a><br><a href= > </a><br>
 
Thanks but my problem is how to store the array in the file
 
[tab]Do you have any code on this to show us?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top