473,396 Members | 1,760 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Matching students to university problem

40
Hello good friends, please i need your help and advice on how i should best programme the problem, if possible a different option to solve it is welcomed.

The problem a matching problem, how to much students to different universities with their choices

Each student has a chance to select 6 universities .
Each university has limited number of places for the students
Some universities demand average grade of students wanting to study there.
Some not.
This is how i started . Please i want to know whether i am on the right track.
Expand|Select|Wrap|Line Numbers
  1. #include "stdafx.h"
  2. #include<iostream>
  3. using namespace std;
  4.  
  5. struct universities{
  6.       string name;
  7.       int places;
  8.       int average grade;
  9. } university[i];
  10.  
  11. struct student{
  12.     string name;
  13.     universities choice[i];
  14. }student[i]
  15.  
  16.  
  17. int _tmain(int argc, _TCHAR* argv[])
  18.  
  19. {
  20.     ifstream in;
  21.     string filename;
  22.     cout <<"give filname";
  23.     cin filename;
  24.  
  25.     in.open(filname, c_str());
  26.  
  27.     return 0;
  28. }
  29.  
Thanks alot in advance.
Mar 19 '07
97 6103
Roonie
99
so is akzept supposed to be a function?

it looks like this:
Expand|Select|Wrap|Line Numbers
  1. for(int i;i<=30;i++)
  2. {
  3.     for(int j=0;j<=30;j++)
  4.     {
  5.         cout << university[j].max_average_grade;
  6.         university[i].average_grade=university.[j].max_average_grade;
  7.         while(university[i].places > 0 && university[i].average_grade)
  8.         {
  9.             for(int j=0;j<=50;j++)
  10.             {
  11.                 for(int k=0;k<=student[j].choice[6];k++)
  12.                 {
  13.                     if(student[j].my_average_grade==university[j].average_grade && student[j].choice[k]==university[i].name)
  14.                     {
  15.                         university[i].akzept=student[j].choice[k];
  16.                     }
  17.                 }
  18.             }
  19.         }
  20.         --university[i].places;
  21.     }
  22. }
is where you are trying to do the matching. if that is your method of making matches and you want to clean it up, first try to come up with some ideas how you might store the matches you make. it looks like youre set up to store the matches in an array of struct matching_student. so instead of using akzept, just store the match there, right? (get rid of akzept.)

try that and repost your code.
Mar 22 '07 #51
luap
40
This how i think the problem should be solved. Because not all students will be matched, because of limited number of places available. And for a student to matched to a university, the conditions must be fulfiled 1. average_grade and choice of the universtiy.

Expand|Select|Wrap|Line Numbers
  1. //
  2. #include "stdafx.h"
  3. #include <iostream>
  4. #include <string>
  5. using namespace std;
  6.  
  7.  
  8.  
  9.  
  10.  
  11. struct universities
  12.       {
  13.       string name;
  14.       int places;
  15.       double average_grade;
  16.  
  17.       }university;
  18.  
  19.  
  20. struct students
  21.  {
  22.   int id;
  23.   universities choice[6]; 
  24.   universities average_grade;
  25.   double my_average_grade;
  26. }student;
  27.  
  28.  
  29.  
  30. struct matching_student{
  31.        universities match;
  32.        students matchd;
  33.        }matching; 
  34.  
  35.  
  36.  
  37. int _tmain(int argc, _TCHAR* argv[])
  38.  
  39. {
  40.   double max_average_grade;
  41.   int i, j, k; 
  42.  
  43.  
  44.   int student_no;
  45.   int uni_start;
  46.  
  47.   const int no_of_uni=30;
  48.   universities university[no_of_uni];
  49.   const int no_of_student=50;
  50.   students student[no_of_student]; 
  51.   const int no_of_matched_students;
  52.   matching_student matching[no_of_matched_students];
  53.  
  54.  
  55.  
  56.  
  57. for(int i=0;i<=30;i++)
  58. {
  59.  university[no_of_uni].name=uni_start;
  60.  }    
  61.  
  62. for(int j=0;j<50;j++)
  63. {
  64.     student[no_of_student].id=student_no;
  65. }
  66.  
  67.  
  68.  
  69.  
  70.  for(int i=0;i<30;i++)
  71.   {
  72.     for(int j=i+1;j<30;i++)
  73.     {
  74.      if (university[i].average_grade < university[j].average_grade)
  75.       {
  76.           max_average_grade=university[j].average_grade;
  77.           university[j].average_grade=university[i].average_grade;
  78.           university[i].average_grade=max_average_grade;
  79.       }
  80.     } 
  81.   }
  82.  
  83.  
  84. for(int i;i<=30;i++)
  85.  {
  86.  
  87.  
  88.      for(int j=0;j<=30;j++)
  89.      {
  90.       cout << university[j].max_average_grade;
  91.       university[i].average_grade=university.[j].max_average_grade;
  92.  
  93.       while(university[i].places > 0 && university[i].average_grade)
  94.       {
  95.        for(int j=0;j<=50;j++)
  96.         {
  97.            for(int k=0;k<=student[j].choice[6];k++)
  98.            {
  99.              if(student[j].my_average_grade==university[j].average_grade && student[j].choice[k]==university[i].name)
  100.                {
  101.                    matching[no_of_matched_students]=student[j].choice[k];
  102.                }
  103.           }
  104.        }
  105.      }
  106.        --university[i].places;
  107.   }  
  108.  
  109.  
  110.   return 0;
  111.   }
Thanks once again.
Mar 22 '07 #52
Roonie
99
well since your matching_student looks like this:
Expand|Select|Wrap|Line Numbers
  1. struct matching_student{
  2.        universities match;
  3.        students matchd;
  4.        }matching; 
shouldnt your code to store the match look more like this:
Expand|Select|Wrap|Line Numbers
  1. matching_student[no_of_match].match=university[i];
  2. matching_student[no_of_match].matchd=student[k];
?

you also need to

1) find a length to initialize your matching_student[] to. i would suggest using an array the same size as student[]. (50.)

2) you also need to straighten out the variables you are using as iterators in your for loops. you cant use your iterator inside the loop for anything else but sequntial access (or sequential comparison . . .) specifically, in the last block of code, the second nested for loop needs a different iterator since j is already in use.

lets build a new for loop. why dont we begin with a basic method to find and assign your matches:
Expand|Select|Wrap|Line Numbers
  1. if(<the match of university[i] to student[k] is good>)
  2. {
  3. matching_student[no_of_match].match=university[i];
  4. matching_student[no_of_match].matchd=student[k];
  5. }
how would you write a conditional statement to see if the match is good?
Mar 22 '07 #53
Roonie
99
or like this, i mean:
Expand|Select|Wrap|Line Numbers
  1. if(<the match of university[i] to student[k] is good>)
  2. {
  3. matching[no_of_match].match=university[i];
  4. matching[no_of_match].matchd=student[k];
  5. }
sorry, youre just going to have to work with me here too.
Mar 22 '07 #54
luap
40
PS this how i think the the students could be properly matched. I am not really sure.

so i send my code.

Thanks
Expand|Select|Wrap|Line Numbers
  1. #include "stdafx.h"
  2. #include <iostream>
  3. #include <string>
  4. using namespace std;
  5.  
  6.  
  7.  
  8.  
  9.  
  10. struct universities
  11.       {
  12.       string name;
  13.       int places;
  14.       double average_grade;
  15.       }university;
  16.  
  17.  
  18.  
  19. struct students
  20.  {
  21.   int id;
  22.   universities choice[6]; 
  23.   universities average_grade;
  24.   double my_average_grade;
  25. }student;
  26.  
  27.  
  28.  
  29. struct matching_student{
  30.        universities match;
  31.        students matchd;
  32.        }matching; 
  33.  
  34.  
  35.  
  36. int _tmain(int argc, _TCHAR* argv[])
  37.  
  38. {
  39.   double max_average_grade;
  40.   int i, j, k,c; 
  41.  
  42.  
  43.   int student_no;
  44.   int uni_start;
  45.  
  46.   const int no_of_uni=30;
  47.   universities university[no_of_uni];
  48.   const int no_of_student=50;
  49.   students student[no_of_student];
  50.   const int no_of_match=50;
  51.   matching_student[no_of_match].match=university[i];
  52.   matching_student[no_of_match].matchd=student[k];
  53.  
  54.  
  55.  
  56.  
  57.  
  58. for(int i=0;i<=30;i++)
  59. {
  60.  university[no_of_uni].name=uni_start;
  61.  }    
  62.  
  63. for(int j=0;j<=50;j++)
  64. {
  65.     student[no_of_student].id=student_no;
  66. }
  67.  
  68.  
  69.  
  70.  
  71.  for(int i=0;i<30;i++)
  72.   {
  73.     for(int j=i+1;j<30;i++)
  74.     {
  75.      if (university[i].average_grade < university[j].average_grade)
  76.       {
  77.           max_average_grade=university[j].average_grade;
  78.           university[j].average_grade=university[i].average_grade;
  79.           university[i].average_grade=max_average_grade;
  80.       }
  81.     } 
  82.   }
  83.  
  84.  
  85. for(int i;i<=30;i++)
  86.  {
  87.  
  88.  
  89.      for(int j=0;j<=30;j++)
  90.      {
  91.       cout << university[j].max_average_grade;
  92.       university[i].average_grade=university.[j].max_average_grade;
  93.  
  94.       while(university[i].places > 0 && university[i].average_grade)
  95.       {
  96.        for(int c=0;c<=50;c++)
  97.         {
  98.            for(int k=0;k<=student[c].choice[6];k++)
  99.            {
  100.              if(student[c].my_average_grade==university[j].average_grade && student[c].choice[k]==university[j].name)
  101.                {
  102.                  {
  103.                   matching_student[no_of_match].match=university[i];
  104.                   matching_student[no_of_match].matchd=student[c];
  105.                  }
  106.                }
  107.           }
  108.        }
  109.      }
  110.        --university[i].places;
  111. }
  112. for(j=0;j<=50;j++)
  113. {
  114.     if(matching_student[no_of_match].match->my_average_grade==matching_student[no_of_matcth.average_grade)
  115. {
  116. matching_student[no_of_match].match=university[i];
  117. matching_student[no_of_match].matchd=student[k];
  118. }
  119.   }  
  120.  
  121.  
  122.   return 0;
  123.   }
Mar 22 '07 #55
Roonie
99
ok.

were going to rebuild your program completely.

it looks like your structs are ok for now:
Expand|Select|Wrap|Line Numbers
  1. struct universities
  2. {string name;
  3. int places;
  4. double average_grade;
  5. }university;
  6.  
  7. struct students
  8. {int id;
  9. universities choice[6]; 
  10. //universities average_grade; //except for this.
  11. double my_average_grade;
  12. }student;
  13.  
  14. struct matching_student
  15. {universities match;
  16. students matchd;
  17. }matching; 
now. in your main(), lets get your file input back in the picture, because i think it will be easier to get your program written if we can see what were doing to each line of input. (like you wanted, lets work on one thing at a time, but lets work on the input part first so we have the data accessible for the rest of the program) you were almost correct before . . . you want to start getting input after setting up your variables, and then put the rest of your code inside the file-access loop.

(these are your declaration/initializations - which are also good for the time being):
Expand|Select|Wrap|Line Numbers
  1. double max_average_grade;
  2. int i, j, k, c; 
  3. int student_no, uni_start;
  4.  
  5. const int no_of_uni=30;
  6. universities university[no_of_uni];
  7. const int no_of_student=50;
  8. students student[no_of_student];
  9. const int no_of_matches=50;
  10. matching_student match[no_of_matches];
so your program should look like something of the following:
Expand|Select|Wrap|Line Numbers
  1. //put your struct def's here
  2.  
  3. int main()
  4. {
  5. //and put your declarations/initializations here
  6.  
  7. //now you want to access the file and get your input:
  8.  
  9. string inputData;
  10. while (!in.eof())
  11. {
  12.     getline(data, inputData, '\n');
  13. //getline() is a function that will read in a line from istream data until a '\n'
  14. //is found and will put the line into the string inputData.
  15. //see http://www.cprogramming.com/tutorial/string.html
  16.  
  17.     <you should then take the data and store it in the appropriate struct arrays.>
  18. } // now you are done getting your input.
  19.  
  20. //next, you sort the university data and process matches.
  21.  
  22.  
try rewriting your code like that and then repost it.
Mar 22 '07 #56
luap
40
i am a bit confused, how to present the conditional statment.

I was thinking to compare the students average grade with the universities of their choice and if this true then the student should not be matched to any other university again, and the place of the university should be reduced by one.
Expand|Select|Wrap|Line Numbers
  1. for(j=0;j<=50;j++)
  2. {
  3.     if(matching_student[no_of_match].match->my_average_grade==matching_student[no_of_matcth.average_grade)
  4. {
  5. matching_student[no_of_match].match=university[i];
  6. matching_student[no_of_match].matchd=student[k];
  7. }
  8.  
This is what i thank.

Thanks.
Mar 22 '07 #57
Roonie
99
well the way you described it earlier,
Expand|Select|Wrap|Line Numbers
  1. if(<the student has chosen the university> && <the students average is high enough> && <the university has spots left>)
  2. {
  3. <accept the student>
  4. }
right?
Mar 22 '07 #58
luap
40
First of all thanks so much for the help.

I have made some changes to my code and this is how it looks like now.

Expand|Select|Wrap|Line Numbers
  1. #include "stdafx.h"
  2. #include <iostream>
  3. #include <string>
  4. #include <fstream>
  5. using namespace std;
  6.  
  7.  
  8.  
  9.  
  10.  
  11. struct universities
  12.       {
  13.       string name;
  14.       int places;
  15.       double average_grade;
  16.       }university;
  17.  
  18.  
  19.  
  20. struct students
  21.  {
  22.   int id;
  23.   universities choice[6]; 
  24.   universities average_grade;
  25.   double my_average_grade;
  26. }student;
  27.  
  28.  
  29.  
  30. struct matching_student{
  31.        universities match;
  32.        students matchd;
  33.        }matching; 
  34.  
  35.  
  36.  
  37. int _tmain(int argc, _TCHAR* argv[])
  38.  
  39. {
  40.   double max_average_grade;
  41.   int i, j, k,c; 
  42.  
  43.  
  44.   int student_no;
  45.   int uni_start;
  46.  
  47.   const int no_of_uni=30;
  48.   universities university[no_of_uni];
  49.   const int no_of_student=50;
  50.   students student[no_of_student];
  51.   const int no_of_match=50;
  52.   matching_student[no_of_match].match=university[i];
  53.   matching_student[no_of_match].matchd=student[k];
  54.  
  55.   string studentFile.txt;
  56.   string universityFile.txt;
  57.  
  58.  
  59.   while (!studentFile.eof())
  60.      {
  61.       getline(cin, studentFile.txt '\n');
  62.       for(int i=0;i<universityFile.txt.length(); i++)
  63.           {
  64.           cout << universityFile.txt[i];
  65.           university[no_of_uni]=universityFile.txt[i];
  66.           } 
  67.   while(!universityFile.eof());
  68.       getlint(cin, universityFile.txt 'n\');
  69.       for(int i = 0; i < stdudentFile.txt.length(); i++)
  70.           {
  71.           cout<< studentFile.txt[i];
  72.           student[no_of_students]=studentFile.txt[i];
  73.           }
  74.  
  75.  for(int i=0;i<=30;i++)
  76.   {
  77.   university[no_of_uni].name=uni_start;
  78.   }    
  79.  
  80. for(int j=0;j<=50;j++)
  81. {
  82.     student[no_of_student].id=student_no;
  83. }
  84.  
  85.  
  86.  
  87.  
  88.  for(int i=0;i<30;i++)
  89.   {
  90.     for(int j=i+1;j<30;i++)
  91.     {
  92.      if (university[i].average_grade < university[j].average_grade)
  93.       {
  94.           max_average_grade=university[j].average_grade;
  95.           university[j].average_grade=university[i].average_grade;
  96.           university[i].average_grade=max_average_grade;
  97.       }
  98.     } 
  99.   }
  100.  
  101.  
  102. for(int i;i<=30;i++)
  103.  {
  104.  
  105.  
  106.      for(int j=0;j<=30;j++)
  107.      {
  108.       cout << university[j].max_average_grade;
  109.       university[i].average_grade=university.[j].max_average_grade;
  110.  
  111.       while(university[i].places > 0 && university[i].average_grade)
  112.       {
  113.        for(int c=0;c<=50;c++)
  114.         {
  115.            for(int k=0;k<=student[c].choice[6];k++)
  116.            {
  117.              if(student[c].my_average_grade>=university[j].average_grade && student[c].choice[k]==university[j].name)
  118.                {
  119.                  {
  120.                   matching_student[no_of_match].match=university[i];
  121.                   matching_student[no_of_match].matchd=student[c];
  122.                  }
  123.                }
  124.           }
  125.        }
  126.      }
  127.        --university[i].places;
  128. }
  129. for(j=0;j<=50;j++)
  130. {
  131.  if(student[c].my_average_grade>=university[i].average_grade && student[c].choice[k]==university[j].name&&!( university[i].places)=0)
  132.                {
  133.                 matching_student[no_of_match].match=university[i];
  134.                 matching_student[no_of_match].matchd=student[k];
  135.                 }
  136.   }  
  137.  
  138.  
  139.   return 0;
  140.   }
  141.  
And this is what the compiler tell me.
Expand|Select|Wrap|Line Numbers
  1. :\dokumente und einstellungen\paul\eigene dateien\visual studio 2005\projects\tutorials\tutorials\tutorials.cpp(56) : error C2143: syntax error : missing ';' before '['
  2. c:\dokumente und einstellungen\paul\eigene dateien\visual studio 2005\projects\tutorials\tutorials\tutorials.cpp(56) : error C2337: 'no_of_match' : attribute not found
  3. c:\dokumente und einstellungen\paul\eigene dateien\visual studio 2005\projects\tutorials\tutorials\tutorials.cpp(56) : error C2143: syntax error : missing ';' before '.'
  4. c:\dokumente und einstellungen\paul\eigene dateien\visual studio 2005\projects\tutorials\tutorials\tutorials.cpp(57) : error C2143: syntax error : missing ';' before '['
  5. c:\dokumente und einstellungen\paul\eigene dateien\visual studio 2005\projects\tutorials\tutorials\tutorials.cpp(57) : error C2337: 'no_of_match' : attribute not found
  6. c:\dokumente und einstellungen\paul\eigene dateien\visual studio 2005\projects\tutorials\tutorials\tutorials.cpp(57) : error C2143: syntax error : missing ';' before '.'
  7. c:\dokumente und einstellungen\paul\eigene dateien\visual studio 2005\projects\tutorials\tutorials\tutorials.cpp(59) : error C2143: syntax error : missing ';' before '.'
  8. c:\dokumente und einstellungen\paul\eigene dateien\visual studio 2005\projects\tutorials\tutorials\tutorials.cpp(60) : error C2143: syntax error : missing ';' before '.'
  9. c:\dokumente und einstellungen\paul\eigene dateien\visual studio 2005\projects\tutorials\tutorials\tutorials.cpp(63) : error C2039: 'eof' : is not a member of 'std::basic_string<_Elem,_Traits,_Ax>'
  10.         with
  11.         [
  12.             _Elem=char,
  13.             _Traits=std::char_traits<char>,
  14.             _Ax=std::allocator<char>
  15.         ]
  16. c:\dokumente und einstellungen\paul\eigene dateien\visual studio 2005\projects\tutorials\tutorials\tutorials.cpp(63) : fatal error C1903: unable to recover from previous error(s); stopping compilation
  17. Build log was saved at "file://c:\Dokumente und Einstellungen\Paul\Eigene Dateien\Visual Studio 2005\Projects\tutorials\tutorials\Debug\BuildLog.htm"
  18. tutorials - 10 error(s), 0 warning(s)
  19. ========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========

Once Thanks.
Mar 22 '07 #59
Roonie
99
Expand|Select|Wrap|Line Numbers
  1. const int no_of_match=50;
  2. matching_student[no_of_match].match=university[i];
  3. matching_student[no_of_match].matchd=student[k];
im sorry, i know i told you to initialize your matching_student array, i had a momentary lapse and forgot that that was your array type . . . you need a different name for the actual array. you should only initialize your array once like this:
Expand|Select|Wrap|Line Numbers
  1. const int no_of_match=50;
  2. matching_student matches[no_of_match];
and then use matches[index] to access different match records.

and to open a file: (see http://www.cplusplus.com/doc/tutorial/files.html)
Expand|Select|Wrap|Line Numbers
  1. string filename = "studentFile.txt";
  2. ifstream inFile(filename.c_str());
(remember that to open a file with ifstream, you need a const char[] and not a string, hence the <string>.c_str() to convert the string to a char array.) and you should also end your input loop before sorting the data now stored in your arrays.
Mar 22 '07 #60
sicarie
4,677 Expert Mod 4TB
luap -

Thanks for the errors, but the parentheses and numbers after the ''......tutorial.cpp(##)' are the line numbers. The errors would be more helpful if you just posted (just) those lines or the surrounding relevant code, so we don't have to copy your program into a program, and then count down 56 lines. This also helps keep inside the Posting Guidelines of not copying your entire program's code. (We're having to start cracking down on this because of the ease at which Google finds code for people in the same class...)
Mar 22 '07 #61
DeMan
1,806 1GB
And also, if you have to post code please use code tags [code] and the same thing with a / between [ and c to finish (It makes code MUCH easier to read!!!!)
Mar 22 '07 #62
luap
40
First and fore most i would like to know how to use the code tag
And secondly please forgive me for not using the code tag
please this how code now looks like
Expand|Select|Wrap|Line Numbers
  1. }

Expand|Select|Wrap|Line Numbers
  1. #/
Mar 22 '07 #63
sicarie
4,677 Expert Mod 4TB
First and fore most i would like to know how to use the code tag
And secondly please forgive me for not using the code tag
please this how code now looks like
Expand|Select|Wrap|Line Numbers
  1. }



Expand|Select|Wrap|Line Numbers
  1. #/
The FAQ and the box on the right (titled Reply Guidelines) both show how to use code tags, if you didn't see DeMan's post above.

Then please post a very specific question about your code, and only include the code necessary to your question.
Mar 22 '07 #64
luap
40
may i am quite enough get what actually the code tag does. But i am trying again. Sorry if it should cause a problem again
Mar 22 '07 #65
sicarie
4,677 Expert Mod 4TB
may i am quite enough get what actually the code tag does. But i am trying again. Sorry if it should cause a problem again
Code tags are the word code and /code in between two square brackets [ ] . Then they frame the code:

Expand|Select|Wrap|Line Numbers
  1. your code here (as it says on the right side of the posting page)
  2.  
Also, you need to ask a specific, pointed question about your code, not "does this work" or "does this look good". Sure it looks pretty, but try running it in a compiler, then look at the error message like I was saying before. Pick a single error message, and go to that line in your code. Read the error message, it will contain keywords, and look at that line. Try to figure out what syntax is not correct. If you are still unable to figure it out, post that line, the error message, and what you tried to fix it.
Mar 22 '07 #66
luap
40
could you please explain to what this really means. I can't understand what you mean.
"And also, if you have to post code please use code tags [code] and the same thing with a / between [ and c to finish (It makes code MUCH easier to read!!!!)"

Thanks.
Mar 22 '07 #67
luap
40
please i need help in finding out how go get codes numbered in the compier.
Because without numbering, i can't figure out line. I am using the complier "c++ 2005 Express Edition.

Thanks
Mar 22 '07 #68
Roonie
99
luap,

i think we have come to the end of what we can accomplish here on this site. im afraid we can no longer help you at thescripts.

that being said though, i would love to continue helping you personally . . . but you must be willing to give up on the program you are currently working on. i think you need to work through a few other, more basic, programs first before tackling something like this.

like i said before, i will help you for as long as you want, but you have to be willing to build up to things. start small . . . get big.

send me a personal message if you are interested in my help . . . but remember, im going to make you work, and im going to make you start with the basics.

~roonie.
Mar 22 '07 #69
luap
40
It is rather unfortunate, that thescripts does not want to support me any more. I want to please know , whether i went against any rules and regulations. If I had done something wrong, i never did it with intention. I thought discussionsgroup will help anyone in need. I really want to learn, because i need this language for my studies.
I did a bit of c , but now i have to do this Assigment in c++, which i have no idea,so i have to learn the programming language within a shortest time possible to enable me solve this
problem, that is why it seems as if was doing everything in a rush.
I am really very greatful the for help, i got from thescripts and i hope they continue to help other like me who are in need.

Once again thanks very much for help.
Mar 23 '07 #70
Roonie
99
its not that we dont want to support you, it is that we cant have an entire project online for anyone and everyone who wants to copy it.

. . . i hope you understand . . .

and if you are looking for help still, please remember my offer.
Mar 23 '07 #71
luap
40
please can someone figure out what the problem could be

thanks

Expand|Select|Wrap|Line Numbers
  1. .. inFile.close(filename.c_str()); 


Expand|Select|Wrap|Line Numbers
  1. tutorials.cpp(68) : error C2660: 'std::basic_ifstream<_Elem,_Traits>::close' : function does not take 1 
Mar 23 '07 #72
sicarie
4,677 Expert Mod 4TB
please can someone figure out what the problem could be

thanks

Expand|Select|Wrap|Line Numbers
  1. .. inFile.close(filename.c_str()); 


Expand|Select|Wrap|Line Numbers
  1. tutorials.cpp(68) : error C2660: 'std::basic_ifstream<_Elem,_Traits>::close' : function does not take 1 
Yeah, according to these guys string.c_str() returns a pointer to the string - so I don't believe you want to do that straight in the inFile.close(), try de-referencing it with the '&' in front of it:

Expand|Select|Wrap|Line Numbers
  1. inFile.close(&filename.c_str());
  2.  
I'm not sure if that will work, but it's worth a try - the '&' means 'get the value of' and you have the pointer that c_str() returns. If not, let us know.
Mar 23 '07 #73
luap
40
unfortunately it did not work

Expand|Select|Wrap|Line Numbers
  1. inFile.close(&filename.c_str());
Expand|Select|Wrap|Line Numbers
  1. :\dokumente und einstellungen\paul\eigene dateien\visual studio   2005\projects\tutorials\tutorials\tutorials.cpp(86) : error C2102: '&' requires l-value 
Mar 23 '07 #74
DeMan
1,806 1GB
To close a file fou call close with no arguments. When you oppened the file, you used it's name, but now your variable inFile knows which file it's pointing to. you chould be able to
Expand|Select|Wrap|Line Numbers
  1. inFile.close();
  2.  
Mar 23 '07 #75
sicarie
4,677 Expert Mod 4TB
To close a file fou call close with no arguments. When you oppened the file, you used it's name, but now your variable inFile knows which file it's pointing to. you chould be able to
Expand|Select|Wrap|Line Numbers
  1. inFile.close();
  2.  
Oh wow. I can't believe I missed that one.

Wow....

I ... I'm speechless. Talk about missing something basic...
Mar 23 '07 #76
DeMan
1,806 1GB
it took me a while.....it's one of those things that looks correct cos you can follow the logic...
Mar 23 '07 #77
sicarie
4,677 Expert Mod 4TB
it took me a while.....it's one of those things that looks correct cos you can follow the logic...
Yeah, totally. I was just focusing on where the error was, instead of thinking what about the statement caused the error...
Mar 23 '07 #78
luap
40
Hello friends i need some help,

i want save the data in struct students by first reading the string and saving them in
buffer. this what i did.
And secondly help how to save the array "choice" in the struct?

Thanks.

Expand|Select|Wrap|Line Numbers
  1. struct students
  2.       {
  3.       int id;
  4.       double my_average_grade;
  5.       universities choice[6];
  6.       universities average_grade;
  7.       }student;
  8.  




Expand|Select|Wrap|Line Numbers
  1. while(!inFile.eof())
  2. {
  3.     istream& getline ( istream& is, string& str, char d;char e; char y);
  4.     for(int j=0;j<50;j++)
  5.     {
  6.         student[j].id=buffer;
  7.         student[j].my_average_grade=buffer;
  8.         student[j].choice[k];
  9.     }
Mar 28 '07 #79
sicarie
4,677 Expert Mod 4TB
Hello friends i need some help,

i want save the data in struct students by first reading the string and saving them in
buffer. this what i did.
And secondly help how to save the array "choice" in the struct?

Thanks.

Expand|Select|Wrap|Line Numbers
  1. struct students
  2.       {
  3.       int id;
  4.       double my_average_grade;
  5.       universities choice[6];
  6.       universities average_grade;
  7.       }student;
  8.  




Expand|Select|Wrap|Line Numbers
  1. while(!inFile.eof())
  2. {
  3.     istream& getline ( istream& is, string& str, char d;char e; char y);
  4.     for(int j=0;j<50;j++)
  5.     {
  6.         student[j].id=buffer;
  7.         student[j].my_average_grade=buffer;
  8.         student[j].choice[k];
  9.     }
How did you arrive at '50' to be your for loop control? I'm guessing student[] is the array of structs you have declared? Check out this getline() reference. You can't plug it directly into the variables, you'll need to use strtok() to parse the line. An alternative is to cin >> directly into the declared data types.

(And thanks for following the posting guidelines - that's a big help!)
Mar 28 '07 #80
JosAH
11,448 Expert 8TB
If I understand the problem correctly it is just a classical Assignment Problem
AP(S, U) where there is a cost C(s, u) associated for a student s to apply for a
university s. There are upperbounds too wrt to both the universities (maximum
numbers of students they can take and for the students. The latter constraint
can be eliminated if a student is only allowed to attend courses at one
university.

Google for: "Bertsimas and Tsitsiklis: linear network optimization" and you'll
know everything about this topic but were too afraid to ask ;-)

kind regards,

Jos
Mar 28 '07 #81
r035198x
13,262 8TB
If I understand the problem correctly it is just a classical Assignment Problem
AP(S, U) where there is a cost C(s, u) associated for a student s to apply for a
university s. There are upperbounds too wrt to both the universities (maximum
numbers of students they can take and for the students. The latter constraint
can be eliminated if a student is only allowed to attend courses at one
university.

Google for: "Bertsimas and Tsitsiklis: linear network optimization" and you'll
know everything about this topic but were too afraid to ask ;-)

kind regards,

Jos
Yeah, good pick on it Jos. I think the OP should get the algorithm right first before they start fiddling around with the code.

I was afraid of linear optimization myself, until I had to use it in my final year project...
Mar 28 '07 #82
JosAH
11,448 Expert 8TB
Yeah, good pick on it Jos. I think the OP should get the algorithm right first before they start fiddling around with the code.

I was afraid of linear optimization myself, until I had to use it in my final year project...
This problem really isn't that difficult: the internals of a solver involves just
quite a bit of tree fiddling. The (linear) algebra behind it all is quite basic:
given a current solution, find a better one and establish that solution. Repeat
the previous step until no better solution can be found anymore.

The characteristics of this problem are (among others) that the search space
is convex, so any local optimal solution is also a global optimal solution.
(ref: simplex)

Another nice characteristic of the assignment problem is that an integer start
solution to the problem will stay an integer solution over all iterations. In normal
human readable form this means that no student will be assigned partially to
more than one university.

IMHO the OP should really read about the ref I supplied in my previous reply
before s/he starts coding.

kind regards,

Jos
Mar 28 '07 #83
r035198x
13,262 8TB
...
Another nice characteristic of the assignment problem is that an integer start
solution to the problem will stay an integer solution over all iterations. In normal
human readable form this means that no student will be assigned partially to
more than one university.

...
Thus it's an integer linear programming problem?
Mar 28 '07 #84
JosAH
11,448 Expert 8TB
Thus it's an integer linear programming problem?
Yep, and the fun of these type of problems is that if the initial solution is all
integer, all following solutions (better than the previous one) are all integer
solutions too. That's the nice characteristic of MCNF (Minimal Cost Network
Flow) problems (the Assignment Problem is a sub-problem of the MCNF class
of problems).

kind regards,

Jos

ps. if you really want to be masochistic read Alexander Schrijver's book on
linear programming ;-)
Mar 28 '07 #85
r035198x
13,262 8TB
Yep, and the fun of these type of problems is that if the initial solution is all
integer, all following solutions (better than the previous one) are all integer
solutions too. That's the nice characteristic of MCNF (Minimal Cost Network
Flow) problems (the Assignment Problem is a sub-problem of the MCNF class
of problems).

kind regards,

Jos

ps. if you really want to be masochistic read Alexander Schrijver's book on
linear programming ;-)
I suppose the simplex algorithm here would fail?
Mar 28 '07 #86
JosAH
11,448 Expert 8TB
I suppose the simplex algorithm here would fail?
Nope, a general simplex solver can also solve mcnf problems. Mcnf problems
are a real sub-class of problems of the simplex class problems.

The nice thing about mcnf problems (and all its sub class problems) is that if
the initial solution is all integer, all subsequent solutions are integer solutions.

kind regards,

Jos
Mar 28 '07 #87
r035198x
13,262 8TB
Nope, a general simplex solver can also solve mcnf problems. Mcnf problems
are a real sub-class of problems of the simplex class problems.

The nice thing about mcnf problems (and all its sub class problems) is that if
the initial solution is all integer, all subsequent solutions are integer solutions.

kind regards,

Jos
Ah, so that's why you were making a fuss about subsequent solutions being integer solutions.

Thanks jos.
Mar 28 '07 #88
JosAH
11,448 Expert 8TB
Ah, so that's why you were making a fuss about subsequent solutions being integer solutions.

Thanks jos.
You're welcome of course; indeed a general (revised) simplex solver has to deal
with all sorts of floating point scaling and other inaccuracies. An mcnf solver
just has to deal with simple multimplications and additions and a much simpler
pivoting strategy. The internal data model is much simpler too.

kind regards,

Jos
Mar 28 '07 #89
luap
40
Thanks alot for the help
Mar 28 '07 #90
luap
40
Hello good friends,
first of all i want to thank you for help, that i have received from you.
I want start learning c++ from the basics and would like to know if
it is possible to cut my thread, because it is too long.

Thanks a lot.
Apr 11 '07 #91
r035198x
13,262 8TB
Hello good friends,
first of all i want to thank you for help, that i have received from you.
I want start learning c++ from the basics and would like to know if
it is possible to cut my thread, because it is too long.

Thanks a lot.
No need to cut it for being too long only. Is there any other reason you want this thread cut?
Apr 13 '07 #92
Roonie
99
i think our friend paul here is looking for general help learning to program. i was unable to help him complete his project before it was due (without doing it for him, of course), and he talked to his professor about it: he has an extension until june.

paul: now that you are no longer working on this particular program, please feel free to create a new thread when you have a new question.
Apr 13 '07 #93
luap
40
Thanks for the reply and the help, i would like to know, how to create a new thread,

Thanks in advance.
Apr 15 '07 #94
JosAH
11,448 Expert 8TB
I'm afraid the hint w.r.t. assignment problems was lost for the posterity.

kind regards,

Jos
Apr 15 '07 #95
luap
40
Hello friends,
i faced with a problem once again.
I want to write a function which can grow an array. This is my code
Expand|Select|Wrap|Line Numbers
  1.  #include "stdafx.h"
  2. #include<iostream>
  3. using namespace std;
  4.  
  5. int array_grower(int newarray[], int newsize)
  6. {
  7.  
  8. for(int i=0;i < newsize;i++)
  9. {
  10. newarray[i]= "array"[i];
  11.  
  12. return newarray[i] ;
  13. }
  14.  
  15. }
  16.  
  17.  
  18.  
  19.  
  20. int _tmain(int argc, _TCHAR* argv[])
  21.  
  22. {
  23.  
  24.  
  25. int array[9];
  26. for(int i=0;i<9;i=i++)
  27. {
  28. array[i]=i;
  29. }
  30. array_grower(array, 9);
  31. for(int i=0;i<9;i++)
  32. {
  33. array[i]=0;
  34. }
  35. for(int i=0;i<9;i=i++)
  36. {
  37. cout<< array[i];
  38. }
  39. return 0;
  40.  
  41. }
  42.  
secondly i would like to know what a function without a constant ist
Apr 27 '07 #96
JosAH
11,448 Expert 8TB
Hello friends,
i faced with a problem once again.
I want to write a function which can grow an array.secondly i would like to know what a function without a constant ist
Use a vector for that purpose; there's no need to reinvent the wheel. I don't know
what a 'function without a constant' is.

kind regards,

Jos
Apr 28 '07 #97
luap
40
Thanks a lot JosAH, i will try to impliment it with a vector.

Kind Regards
Apr 28 '07 #98

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: Sridhar R | last post by:
We are the students of Anna University and would like to share our thoughts on Python. Here it is http://cs.annauniv.edu/~portal/wiki/index.php/Python
5
by: david hepworth | last post by:
Hi All I will try to explain my problem. I am wishing to apply a template to the following XML. There are multiple event nodes within the register root node. For each of the event nodes there...
24
by: Mary Rosemount | last post by:
http://www.studentsforacademicfreedom.org/index.html
17
by: JunDa.Huang | last post by:
I am a university student, How to study program language well ?
18
by: Drayno241 | last post by:
I'm working in access 2002. I have three tables : 1- District Data (Student ID, name, grade, etc) 2- Rosters (RRec ID,Campus, Teacher ID) 3- Students on Roster(SRec ID, RRec ID, Student ID) ...
7
by: blaine | last post by:
Hey everyone, For the regular expression gurus... I'm trying to write a string matching algorithm for genomic sequences. I'm pulling out Genes from a large genomic pattern, with certain start...
4
by: pavanponnapalli | last post by:
hi, Here is my Code as under: #! /usr/bin/perl -w use DBI; my %hash; my @arr; my @arr1; my @arr2;
1
by: roxys | last post by:
Hello, I was wondering if someone could help me a bit here. Im trying to desing an electronic university students enrollement system. The system requirements are as follows: 1.Students can...
8
by: mfaisalwarraich | last post by:
hello, im trying to make an attendance record. im using a form where im entering two values, 1. Date 2. Absent Students im entering roll numbers of the absent students separated by "-"...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.