Click here to Skip to main content
15,887,683 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: SetWindowText for static control Pin
_AnsHUMAN_ 20-Apr-09 23:04
_AnsHUMAN_ 20-Apr-09 23:04 
Questionvariable and class View Pin
durban220-Apr-09 21:11
durban220-Apr-09 21:11 
AnswerRe: variable and class View Pin
CPallini20-Apr-09 21:49
mveCPallini20-Apr-09 21:49 
QuestionWindows events Pin
sunny_vc20-Apr-09 19:05
sunny_vc20-Apr-09 19:05 
AnswerRe: Windows events Pin
Stuart Dootson20-Apr-09 20:09
professionalStuart Dootson20-Apr-09 20:09 
GeneralRe: Windows events Pin
sunny_vc20-Apr-09 20:15
sunny_vc20-Apr-09 20:15 
GeneralRe: Windows events Pin
Stuart Dootson20-Apr-09 21:05
professionalStuart Dootson20-Apr-09 21:05 
QuestionHow to Read data using IfStream in while loop? [modified] Pin
pohcb_sonic20-Apr-09 16:31
pohcb_sonic20-Apr-09 16:31 
Hi guys,

I have a following problem. I'm trying to read a range of data information from the following .dat file specified below.

I'm using the ifStream to read in the data from the Info.dat file. I have created the Student class object S[4], then using it to set the data that I've read in using variables. It is also a need for while loop to be used in the program. However, the problem is that it does not work out well.

My intended output is as such:

output:
------------
Alan  <br />
no of subjects taken: 4<br />
no of passes :3<br />
total credits : 17
and so on.

Really appreciate the help.


Info.dat
Alan English 4 F Maths 3 P Science 5 P Geo 5 P
Danny English 2 P Maths 3 P Science 4 P Geo 2 P
Jane English 1 F Maths 3 F Science 3 P Computing 8 P
Keith English 5 P Maths 3 P Science 5 P Literature 4 P



int main()<br />
{<br />
	Student S[4]; //set the no. of students objects from Student Class here.<br />
        //Inside Student Class, there is another object called Modules[4], declared as private instance,<br />
        //which is used to initialise and called in the Student Class.    <br />
<br />
<br />
	int count, credits, totalCred;<br />
	string stud, module;<br />
	char pass;<br />
	<br />
	int Cols;<br />
	int Rows; <br />
<br />
	Cols = 0;<br />
	Rows = 0;<br />
	<br />
	<br />
	count = 0;<br />
	totalCU = 0;<br />
<br />
   	ifstream inFile;<br />
<br />
	inFile.open("Info.dat");<br />
<br />
	if (inFile.fail()){<br />
		cout<<"ERROR: File cannot be opened!"<<endl;<br />
	    getchar();<br />
		exit(1);<br />
	}<br />
<br />
<br />
	if (inFile.good()){<br />
                <br />
          <br />
            //Suspected problem in coding begins here <br />
		<br />
		while (Rows < 4){<br />
                        <br />
                        //Read in name of each students  <br />
			inFile>>stud;<br />
	<br />
		<br />
			S[Rows].setName(stud); <br />
<br />
<br />
			while (Cols < 4){ <br />
                                //read in of the module details <br />
				inFile >>module>>credits>>pass;<br />
			       <br />
                               //setting of each individual module variable data here. 	<br />
                               S[Rows].setCode(module, Cols);<br />
				...<br />
<br />
			//Pass refers to the no. of passed subjects/modules	<br />
			if (pass == 'P'){<br />
					count++;<br />
				}<br />
<br />
				totalCred = totalCred + credits;<br />
<br />
				Cols++;<br />
			}<br />
<br />
<br />
				//Setting of counting of number of passed subjects here.<br />
                                S[Rows].setCount(count);<br />
				 <br />
 <br />
<br />
<br />
			<br />
<br />
			Rows++;<br />
<br />
<br />
		}<br />
	}<br />
<br />
	inFile.close();


DA: http://www.pohcbsonic.deviantart.com/
Blog: http://www.pohcbsonicx.blogspot.com/
Homepage: http://www.pohcbsonic.tripod.com/

modified on Tuesday, April 21, 2009 12:42 AM

QuestionRe: How to Read data using IfStream? Pin
David Crow20-Apr-09 17:17
David Crow20-Apr-09 17:17 
AnswerRe: How to Read data using IfStream? Pin
pohcb_sonic20-Apr-09 18:42
pohcb_sonic20-Apr-09 18:42 
QuestionRe: How to Read data using IfStream? Pin
David Crow21-Apr-09 3:12
David Crow21-Apr-09 3:12 
AnswerRe: How to Read data using IfStream? Pin
pohcb_sonic21-Apr-09 14:31
pohcb_sonic21-Apr-09 14:31 
QuestionRe: How to Read data using IfStream? Pin
David Crow22-Apr-09 2:50
David Crow22-Apr-09 2:50 
QuestionHaving trouble converting Java Code to C++ Pin
NxtGr8One20-Apr-09 16:23
NxtGr8One20-Apr-09 16:23 
AnswerRe: Having trouble converting Java Code to C++ Pin
David Crow20-Apr-09 16:51
David Crow20-Apr-09 16:51 
QuestionC++ Directory Functions Pin
gamefreak229120-Apr-09 15:37
gamefreak229120-Apr-09 15:37 
AnswerRe: C++ Directory Functions [modified] Pin
Joe Woodbury20-Apr-09 16:33
professionalJoe Woodbury20-Apr-09 16:33 
GeneralRe: C++ Directory Functions Pin
gamefreak229120-Apr-09 17:01
gamefreak229120-Apr-09 17:01 
QuestionRe: C++ Directory Functions Pin
David Crow20-Apr-09 17:37
David Crow20-Apr-09 17:37 
AnswerRe: C++ Directory Functions Pin
gamefreak229120-Apr-09 18:16
gamefreak229120-Apr-09 18:16 
AnswerRe: C++ Directory Functions Pin
krmed21-Apr-09 3:03
krmed21-Apr-09 3:03 
QuestionWhat I should Use...bitset, vector &LT bool&GT, or bit_vector? Pin
JohnnyG20-Apr-09 13:51
JohnnyG20-Apr-09 13:51 
AnswerRe: What I should Use...bitset, vector &LT bool&GT, or bit_vector? Pin
Stuart Dootson20-Apr-09 20:07
professionalStuart Dootson20-Apr-09 20:07 
GeneralRe: What I should Use...bitset, vector &LT bool&GT, or bit_vector? Pin
JohnnyG21-Apr-09 11:18
JohnnyG21-Apr-09 11:18 
Questionsprintf and rounding issues [modified] Pin
Jim Crafton20-Apr-09 8:27
Jim Crafton20-Apr-09 8:27 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.