forget exam1 and exam2. What you have in that structure is an array of exam grades. If you want the list of grades you posted in your post #28

stu.examcode.push_back(3);
stu.examcode.push_back(13);
stu.examcode.push_back(34);
... // etc etc for the complete list.

Now if you want to check if exam1 and exam2 are in the list above

for(int i = 0; i < stu.examcode.size(); i++)
{
     if( stu.examcode[i] == exam1 || stu.examcode[i] == exam2)
     {
              // found it so now do something
     }
}

Dear all,
I dont know how to make correction for line 8 and 9.

syntax error : missing ';' before '.'
syntax error : missing ';' before '.'
syntax error : missing ';' before '.'

struct stu
{
   string stuid;
   vector <int> examcode;   
};

stu.examcode.push_back(3);
stu.examcode.push_back(13);

	for(int i = 1; i < stu.examcode.size(); i++)
{
		 if( stu.examcode[i] == exam1 || stu.examcode[i] == exam2)
		 {
              return true;// found it so now do something
		 }
}
	for(int i = 1; i < stu.examcode.size(); i++)
{
		 if( stu.examcode[i] == exam1 || stu.examcode[i] == exam2)
		  {
             return false; // found it so now do something
		  }
}

Dear all,
I dont know how to make correction for line 8 and 9.

syntax error : missing ';' before '.'
syntax error : missing ';' before '.'
syntax error : missing ';' before '.'

struct stu
{
   string stuid;
   vector <int> examcode;   
};

stu.examcode.push_back(3);
stu.examcode.push_back(13);

	for(int i = 1; i < stu.examcode.size(); i++)
{
		 if( stu.examcode[i] == exam1 || stu.examcode[i] == exam2)
		 {
              return true;// found it so now do something
		 }
}
	for(int i = 1; i < stu.examcode.size(); i++)
{
		 if( stu.examcode[i] == exam1 || stu.examcode[i] == exam2)
		  {
             return false; // found it so now do something
		  }
}

Stop changing the struct! It's this:

struct student
{
   string studentid;
   vector <int> examcode;   
};

student stu;
stu.examcode.push_back(3);
stu.examcode.push_back(13);

why I can't declare i twicely?

error C2374: 'i' : redefinition; multiple initialization
see declaration of 'i'

/*------------------------------------------------------------------------------------------+
|                           Filename : ConflictMatrix.cpp                                   |
+------------------------------------------------------------------------------------------*/

#include <iostream>
#include <fstream>
#include <iomanip>
#include <string>
#include <vector>
#include <algorithm>
using namespace std;

   struct student
{
   string studentid;
   vector <int> examcode;   
};
   int main()
{
   ifstream stream1 ("STA83STU.txt");
   if ( !stream1 )
{
   cout << "While opening a file an error is encountered" << endl;
}
   else
{
   cout << "File is successfully opened" << endl;
}  
   vector <student> students;
   student aStudent;
   string tempStudentID;
   bool readEntireFile = false;     // set to true when reach end of file

   stream1 >> tempStudentID;    //  read in student id of first student
   while ( !readEntireFile )
{
   aStudent.studentid = tempStudentID;  //  new student
   int tempExamCode;
   aStudent.examcode.clear ();
   stream1 >> tempExamCode;    // read in first exam code for this student
   aStudent.examcode.push_back (tempExamCode);  // add this exam code to current student's vector of exam codes
   bool newStudent = false;   // true when a new student id is encountered
   while ( !newStudent && !readEntireFile )
{
   if ( stream1 >> tempStudentID )   // successfully read in student id
{
   if ( tempStudentID.compare (aStudent.studentid) == 0 )  // student id is same as before
{
   stream1 >> tempExamCode;   // read in exam code
   aStudent.examcode.push_back (tempExamCode); // add this exam code to this student;s vector of exam codes
}
   else
   newStudent = true;   // student id is different from before.  Therefore new student.
}
   else
   readEntireFile = true;  // end of file reached.  Want to exit inner and outer while loops
}  // if new student, do not repeat this while loop
   students.push_back (aStudent);   // no more exam codes for this student.  Add aStudent to students vector
}
   stream1.close ();  // We have read the entire file, so time to close it.

   for ( int i = 1 ; i < students.size (); i++ )
{
   cout <<i<<":\t" ;   // output student id
   for ( int j = 1;j<students.at(i).examcode.size(); j++ )
	   cout << students.at (i).examcode.at(j) <<"\t";   // output list of exam codes for this student
   cout<<""<<"\n";       
} 
/*--------------------------------------------------------------------------------------------+
|                         counting elements in StudentID                                     |
+--------------------------------------------------------------------------------------------*/
struct student
{
   string studentid;
   vector <int> examcode;   
};

student stu;
stu.examcode.push_back(3);
stu.examcode.push_back(13);
int exam1;
int exam2;

	for( int i = 1 ; i < students.size(); i++)
{
		 if( stu.examcode[i] == exam1 || stu.examcode[i] == exam2)
		 {
              return true;// found it so now do something
		 }
}

{
		 if( stu.examcode[i] == exam1 || stu.examcode[i] == exam2)
		  {
             return false; // found it so now do something
		  }
}
 

/*-------------------------------------------------------------------------------------------+		
|                                         Matrix ExamID                                       
+--------------------------------------------------------------------------------------------*/

cout<<"i,j|";
for (int colHead = 1; colHead < 11; colHead++)
cout << setw(3.5) << colHead;
cout << endl;
cout <<"__________________________________"<<endl;

		for (int rowVal = 1; rowVal < 11; rowVal++)
	{
		cout << setw(3.5)<< rowVal <<'|';

		for (int colVal =1; colVal < 11; colVal++)
		cout << setw(3.5)<<"x";
		cout <<endl;
	}
}

what line number?

in line 63 and 85 Ancient Dragon.

What is mean by this statement? I dont understand, can someone explain to me?

loaded 'ntdll.dll', no matching symbolic information found.
Loaded 'C:\WINDOWS\system32\kernel32.dll', no matching symbolic information found.
The thread 0xC4C has exited with code 0 (0x0).
The program 'C:\Documents and Settings\ashida\My Documents\MASTER C++\main\Debug\63.exe' has exited with code 0 (0x0).

He initializes 'i' the first time in line 63 then he re-initializes it in line 85

just change the int in line 85 to like 'k' or something... should fix that problem.

you are trying to assign the variable i two different values (C++ doesn't like that) if you just get rid of the 'int' initialization in line 85 or change it to a different variable label should fix the problem.

What is mean by this statement? I dont understand, can someone explain to me?

loaded 'ntdll.dll', no matching symbolic information found.
Loaded 'C:\WINDOWS\system32\kernel32.dll', no matching symbolic information found.
The thread 0xC4C has exited with code 0 (0x0).
The program 'C:\Documents and Settings\ashida\My Documents\MASTER C++\main\Debug\63.exe' has exited with code 0 (0x0).

Just ignore it as it doesn't mean much to anyone. All that is telling you is that your program is not using the debug version of the dlls that are mentioned. It does not affect your program in any way.

just what ancient said

He initializes 'i' the first time in line 63 then he re-initializes it in line 85

just change the int in line 85 to like 'k' or something... should fix that problem.

you are trying to assign the variable i two different values (C++ doesn't like that) if you just get rid of the 'int' initialization in line 85 or change it to a different variable label should fix the problem.

You are right but some compilers like VC++ 6.0 do not follow the rules and allow that construct. Errors like that are common when attempting to port a program written with VC++ 6.0 to a compiler such as VC++ 8.0 Express -- been threre and done that too :)

yea that's I have C# that I compile at my school then when I compile at home with VC++ 8.0 Express I have to re-write the whole thing big pain in the....

then, there is an error again.. I dont know what kind of this error..
63.cpp
C:\Documents and Settings\ashida\My Documents\MASTER C++\main\63.cpp(119) : warning C4715: 'main' : not all control paths return a value
C:\Documents and Settings\ashida\My Documents\MASTER C++\main\63.cpp(87) : warning C4700: local variable 'exam1' used without having been initialized
C:\Documents and Settings\ashida\My Documents\MASTER C++\main\63.cpp(87) : warning C4700: local variable 'exam2' used without having been initialized

63.obj - 0 error(s), 3 warning(s)

yea that's I have C# that I compile at my school then when I compile at home with VC++ 8.0 Express I have to re-write the whole thing big pain in the....

Why are you using VC++ 8.0 at home ans C# at school? Get a C# compiler (free) to use at home and you won't have that problem :)

>>main\63.cpp(119) : warning C4715: 'main' : not all control paths return a value
Looks like you left off the return 0; at the end of main().

>>main\63.cpp(87) : warning C4700: local variable 'exam1' used without having been initialized
That error should be obvious if you look at the line in the code -- you are attemtping to use an uninitialized variable. The value of the variable on that line contains any random value, which is a no-no if you want your program to work correctly.

how to initialize the code?

>>how to initialize the code?
That means to set it to 0 or some other value, such as int exam1 = 0;

ohooo....like that..thank you Ancient Dragon..

There is no error, but when to linking ...cannot.It said like this..

"65.exe has encountered a problem and needs to close.

If you were in the middle of something , the information you were working on might be lost.."

/*------------------------------------------------------------------------------------------+
|                           Filename : ConflictMatrix.cpp                                   |
+------------------------------------------------------------------------------------------*/

#include <iostream>
#include <fstream>
#include <iomanip>
#include <string>
#include <vector>
#include <algorithm>
using namespace std;

   struct student
{
   string studentid;
   vector <int> examcode;   
};
   int main()
{
   ifstream stream1 ("STA83STU.txt");
   if ( !stream1 )
{
   cout << "While opening a file an error is encountered" << endl;
}
   else
{
   cout << "File is successfully opened" << endl;
}  
   vector <student> students;
   student aStudent;
   string tempStudentID;
   bool readEntireFile = false;     // set to true when reach end of file

   stream1 >> tempStudentID;    //  read in student id of first student
   while ( !readEntireFile )
{
   aStudent.studentid = tempStudentID;  //  new student
   int tempExamCode;
   aStudent.examcode.clear ();
   stream1 >> tempExamCode;    // read in first exam code for this student
   aStudent.examcode.push_back (tempExamCode);  // add this exam code to current student's vector of exam codes
   bool newStudent = false;   // true when a new student id is encountered
   while ( !newStudent && !readEntireFile )
{
   if ( stream1 >> tempStudentID )   // successfully read in student id
{
   if ( tempStudentID.compare (aStudent.studentid) == 0 )  // student id is same as before
{
   stream1 >> tempExamCode;   // read in exam code
   aStudent.examcode.push_back (tempExamCode); // add this exam code to this student;s vector of exam codes
}
   else
   newStudent = true;   // student id is different from before.  Therefore new student.
}
   else
   readEntireFile = true;  // end of file reached.  Want to exit inner and outer while loops
}  // if new student, do not repeat this while loop
   students.push_back (aStudent);   // no more exam codes for this student.  Add aStudent to students vector
}
   stream1.close ();  // We have read the entire file, so time to close it.

   for ( int i = 1 ; i < students.size (); i++ )
{
   cout <<i<<":\t" ;   // output student id
   for ( int j = 1;j<students.at(i).examcode.size(); j++ )
	   cout << students.at (i).examcode.at(j) <<"\t";   // output list of exam codes for this student
   cout<<""<<"\n";       
} 
/*--------------------------------------------------------------------------------------------+
|                         counting elements in StudentID                                     |
+--------------------------------------------------------------------------------------------*/
struct student
{
   string studentid;
   vector <int> examcode;   
};

student stu;
stu.examcode.push_back(3);
stu.examcode.push_back(13);
int exam1=0;
int exam2=0;


	for( int k = 1 ; k < students.size(); k++)
{
		 if( stu.examcode[k] == exam1 || stu.examcode[i] == exam2)
		 {
              return true;// found it so now do something
		 }
}

{
		 if( stu.examcode[k] == exam1 || stu.examcode[i] == exam2)
		  {
             return false; // found it so now do something
		  }
         return 0;
}
 

/*-------------------------------------------------------------------------------------------+		
|                                         Matrix ExamID                                       
+--------------------------------------------------------------------------------------------*/

cout<<"i,j|";
for (int colHead = 1; colHead < 11; colHead++)
cout << setw(3.5) << colHead;
cout << endl;
cout <<"__________________________________"<<endl;

		for (int rowVal = 1; rowVal < 11; rowVal++)
	{
		cout << setw(3.5)<< rowVal <<'|';

		for (int colVal =1; colVal < 11; colVal++)
		cout << setw(3.5)<<"x";
		cout <<endl;
	}
}

You can't link/or run that code because too many compile errors that you have to fix. Here are a few of them.

line 86: you forgot to change i to k.

lines 95-98 are not inside a loop, so I don't know what they are supposed to do. Looks like a posting error and those lines should just be deleted.

line 118: setw() doesn't take a float -- must be an integer.

I'm having problem with this programming...

example is I have a 3 13 15 16 17

i want to call exam 3 and exam 13 and count it 1
and then call 3 and 15 and count it 1 again..until the end..is it like below programming how to call it.?

struct student
{
   string studentid;
   vector <int> examcode;   
};

student stu;
stu.examcode.push_back(3);
stu.examcode.push_back(13);
int exam1=0;
int exam2=0;


	for( int k = 1 ; k < students.size(); k++)
{
		 if( stu.examcode[k] == exam1 || stu.examcode[k] == exam2)
		 {
             cout<<"1" <<endl;
			 return true;// found it so now do something
		 }

		 if( stu.examcode[k] == exam1 || stu.examcode[k] == exam2)
		  {
             cout <<"0"<<endl;
			 return false; // found it so now do something
		  }
         return 0;
}

I want to do like this, but how to make a class of push back?


left of '.push_back' must have class/struct/union type
left of '.begin' must have class/struct/union type
left of '.end' must have class/struct/union type
Error executing cl.exe.

struct student
{
	string studentid;
	vector <int> examcode;   
};
    int examcode; 
    for( int k = 1 ; k < students.size(); k++)
{
	examcode.push_back (k);
	{
    int target_value = 2;
    int num_items = count( examcode.begin(), examcode.end(), target_value );   
    cout << "examcode contains " << num_items << " items matching " << target_value << endl;  
    return 0;
}
}

examcode is just a simple integer (line 8). Good God man why don't you try reading your own program for a change and find out what causes the errors.

commented: excellent suggestion :) +3

i have successfull done this programming. But how to call data automatically..like I have 3 13 15 17 18 19

below, i must pair1 , pair2, pair3...
i want to read like this i=1, i<11, i++

{

		struct pairStruct 
		{
			int first;
			int second;
		};

			class ExamCode
			{
			public:
			void ValMethod (int p1, pairStruct p2)
				 {
						p1 = 111;
						p2.first  = 122;
						p2.second = 133;
				}
					void PtrMethod (int *p1, pairStruct *p2)
						{
						 *p1 = 1;
						 p2->first  = 3;
						 p2->second = 2;

						}
						
					void RefMethod (int &p1, pairStruct &p2)
						{
						p1 = 2;
						p2.first  = 8;
						p2.second = 9;
						}
			};


	{
	    int num = 0;
		pairStruct pair;
		ExamCode *exam = new ExamCode;

		pair.first  = 0;
		pair.second = 0;
		exam->ValMethod(num, pair);
	    cout << "num = " << num << ", pair = " << pair.first << ", "<< pair.second << endl;

		exam->PtrMethod(&num, &pair);
		cout << "num = " << num << ", pair = " << pair.first << ", "<< pair.second << endl;

	    exam->RefMethod(num, pair);
		cout << "num = " << num << ", pair = " << pair.first << ", "<< pair.second << endl;

		delete exam;
		return(0);
		}

	}
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.