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. -
#include "stdafx.h"
-
#include<iostream>
-
using namespace std;
-
-
struct universities{
-
string name;
-
int places;
-
int average grade;
-
} university[i];
-
-
struct student{
-
string name;
-
universities choice[i];
-
}student[i]
-
-
-
int _tmain(int argc, _TCHAR* argv[])
-
-
{
-
ifstream in;
-
string filename;
-
cout <<"give filname";
-
cin filename;
-
-
in.open(filname, c_str());
-
-
return 0;
-
}
-
Thanks alot in advance.
Mar 19 '07
97 6103
so is akzept supposed to be a function?
it looks like this: - for(int i;i<=30;i++)
-
{
-
for(int j=0;j<=30;j++)
-
{
-
cout << university[j].max_average_grade;
-
university[i].average_grade=university.[j].max_average_grade;
-
while(university[i].places > 0 && university[i].average_grade)
-
{
-
for(int j=0;j<=50;j++)
-
{
-
for(int k=0;k<=student[j].choice[6];k++)
-
{
-
if(student[j].my_average_grade==university[j].average_grade && student[j].choice[k]==university[i].name)
-
{
-
university[i].akzept=student[j].choice[k];
-
}
-
}
-
}
-
}
-
--university[i].places;
-
}
-
}
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.
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.
Thanks once again.
well since your matching_student looks like this: - struct matching_student{
-
universities match;
-
students matchd;
-
}matching;
shouldnt your code to store the match look more like this: - matching_student[no_of_match].match=university[i];
-
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: -
if(<the match of university[i] to student[k] is good>)
-
{
-
matching_student[no_of_match].match=university[i];
-
matching_student[no_of_match].matchd=student[k];
-
}
how would you write a conditional statement to see if the match is good?
or like this, i mean: - if(<the match of university[i] to student[k] is good>)
-
{
-
matching[no_of_match].match=university[i];
-
matching[no_of_match].matchd=student[k];
-
}
sorry, youre just going to have to work with me here too.
PS this how i think the the students could be properly matched. I am not really sure.
so i send my code.
Thanks
ok.
were going to rebuild your program completely.
it looks like your structs are ok for now: - struct universities
-
{string name;
-
int places;
-
double average_grade;
-
}university;
-
-
struct students
-
{int id;
-
universities choice[6];
-
//universities average_grade; //except for this.
-
double my_average_grade;
-
}student;
-
-
struct matching_student
-
{universities match;
-
students matchd;
-
}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): - double max_average_grade;
-
int i, j, k, c;
-
int student_no, uni_start;
-
-
const int no_of_uni=30;
-
universities university[no_of_uni];
-
const int no_of_student=50;
-
students student[no_of_student];
-
const int no_of_matches=50;
-
matching_student match[no_of_matches];
so your program should look like something of the following: - //put your struct def's here
-
-
int main()
-
{
-
//and put your declarations/initializations here
-
-
//now you want to access the file and get your input:
-
-
string inputData;
-
while (!in.eof())
-
{
-
getline(data, inputData, '\n');
-
//getline() is a function that will read in a line from istream data until a '\n'
-
//is found and will put the line into the string inputData.
-
//see http://www.cprogramming.com/tutorial/string.html
-
-
<you should then take the data and store it in the appropriate struct arrays.>
-
} // now you are done getting your input.
-
-
//next, you sort the university data and process matches.
-
-
try rewriting your code like that and then repost it.
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. -
for(j=0;j<=50;j++)
-
{
-
if(matching_student[no_of_match].match->my_average_grade==matching_student[no_of_matcth.average_grade)
-
{
-
matching_student[no_of_match].match=university[i];
-
matching_student[no_of_match].matchd=student[k];
-
}
-
This is what i thank.
Thanks.
well the way you described it earlier, - if(<the student has chosen the university> && <the students average is high enough> && <the university has spots left>)
-
{
-
<accept the student>
-
}
right?
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.
And this is what the compiler tell me. -
:\dokumente und einstellungen\paul\eigene dateien\visual studio 2005\projects\tutorials\tutorials\tutorials.cpp(56) : error C2143: syntax error : missing ';' before '['
-
c:\dokumente und einstellungen\paul\eigene dateien\visual studio 2005\projects\tutorials\tutorials\tutorials.cpp(56) : error C2337: 'no_of_match' : attribute not found
-
c:\dokumente und einstellungen\paul\eigene dateien\visual studio 2005\projects\tutorials\tutorials\tutorials.cpp(56) : error C2143: syntax error : missing ';' before '.'
-
c:\dokumente und einstellungen\paul\eigene dateien\visual studio 2005\projects\tutorials\tutorials\tutorials.cpp(57) : error C2143: syntax error : missing ';' before '['
-
c:\dokumente und einstellungen\paul\eigene dateien\visual studio 2005\projects\tutorials\tutorials\tutorials.cpp(57) : error C2337: 'no_of_match' : attribute not found
-
c:\dokumente und einstellungen\paul\eigene dateien\visual studio 2005\projects\tutorials\tutorials\tutorials.cpp(57) : error C2143: syntax error : missing ';' before '.'
-
c:\dokumente und einstellungen\paul\eigene dateien\visual studio 2005\projects\tutorials\tutorials\tutorials.cpp(59) : error C2143: syntax error : missing ';' before '.'
-
c:\dokumente und einstellungen\paul\eigene dateien\visual studio 2005\projects\tutorials\tutorials\tutorials.cpp(60) : error C2143: syntax error : missing ';' before '.'
-
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>'
-
with
-
[
-
_Elem=char,
-
_Traits=std::char_traits<char>,
-
_Ax=std::allocator<char>
-
]
-
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
-
Build log was saved at "file://c:\Dokumente und Einstellungen\Paul\Eigene Dateien\Visual Studio 2005\Projects\tutorials\tutorials\Debug\BuildLog.htm"
-
tutorials - 10 error(s), 0 warning(s)
-
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
Once Thanks.
- const int no_of_match=50;
-
matching_student[no_of_match].match=university[i];
-
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: - const int no_of_match=50;
-
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) - string filename = "studentFile.txt";
-
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.
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...)
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!!!!)
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
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
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.
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
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: -
your code here (as it says on the right side of the posting page)
-
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.
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.
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
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.
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.
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.
please can someone figure out what the problem could be
thanks - .. inFile.close(filename.c_str());
- tutorials.cpp(68) : error C2660: 'std::basic_ifstream<_Elem,_Traits>::close' : function does not take 1
please can someone figure out what the problem could be
thanks - .. inFile.close(filename.c_str());
- 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: -
inFile.close(&filename.c_str());
-
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.
unfortunately it did not work - inFile.close(&filename.c_str());
- :\dokumente und einstellungen\paul\eigene dateien\visual studio 2005\projects\tutorials\tutorials\tutorials.cpp(86) : error C2102: '&' requires l-value
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
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
Oh wow. I can't believe I missed that one.
Wow....
I ... I'm speechless. Talk about missing something basic...
it took me a while.....it's one of those things that looks correct cos you can follow the logic...
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...
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. -
struct students
-
{
-
int id;
-
double my_average_grade;
-
universities choice[6];
-
universities average_grade;
-
}student;
-
-
while(!inFile.eof())
-
{
-
istream& getline ( istream& is, string& str, char d;char e; char y);
-
for(int j=0;j<50;j++)
-
{
-
student[j].id=buffer;
-
student[j].my_average_grade=buffer;
-
student[j].choice[k];
-
}
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. -
struct students
-
{
-
int id;
-
double my_average_grade;
-
universities choice[6];
-
universities average_grade;
-
}student;
-
-
while(!inFile.eof())
-
{
-
istream& getline ( istream& is, string& str, char d;char e; char y);
-
for(int j=0;j<50;j++)
-
{
-
student[j].id=buffer;
-
student[j].my_average_grade=buffer;
-
student[j].choice[k];
-
}
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!)
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
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...
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
...
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?
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 ;-)
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?
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
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.
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
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.
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?
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.
Thanks for the reply and the help, i would like to know, how to create a new thread,
Thanks in advance.
I'm afraid the hint w.r.t. assignment problems was lost for the posterity.
kind regards,
Jos
Hello friends,
i faced with a problem once again.
I want to write a function which can grow an array. This is my code - #include "stdafx.h"
-
#include<iostream>
-
using namespace std;
-
-
int array_grower(int newarray[], int newsize)
-
{
-
-
for(int i=0;i < newsize;i++)
-
{
-
newarray[i]= "array"[i];
-
-
return newarray[i] ;
-
}
-
-
}
-
-
-
-
-
int _tmain(int argc, _TCHAR* argv[])
-
-
{
-
-
-
int array[9];
-
for(int i=0;i<9;i=i++)
-
{
-
array[i]=i;
-
}
-
array_grower(array, 9);
-
for(int i=0;i<9;i++)
-
{
-
array[i]=0;
-
}
-
for(int i=0;i<9;i=i++)
-
{
-
cout<< array[i];
-
}
-
return 0;
-
-
}
-
secondly i would like to know what a function without a constant ist
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
Thanks a lot JosAH, i will try to impliment it with a vector.
Kind Regards
Sign in to post your reply or Sign up for a free account.
Similar topics
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
|
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...
|
by: Mary Rosemount |
last post by:
http://www.studentsforacademicfreedom.org/index.html
|
by: JunDa.Huang |
last post by:
I am a university student, How to study program language well ?
|
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)
...
|
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...
|
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;
|
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...
|
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 "-"...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
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...
|
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
|
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...
|
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...
|
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...
|
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,...
|
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...
|
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...
| |