It's due tomorrow night.
As you can see below, entering a negative one will stop the inputs.
Problem: Before MyPurdue students could only select classes and the Office of the Registrar would assign each student
to a particular division and section of a course. The students with potential conflicts with another class are given priority
for sections that work with their schedule and the remaining students will fill in sections such that the enrollment of each
section is as balanced as possible. While this approach was unpopular resulting in early morning classes and schedules
with significant gaps in between class meetings, it did maximize the space in each class and resulted in fewer students
being denied enrollment in a class because the only sections that did not conflict with another required class were closed.
Given the space available in up to 25 sections and the number of students without conflicts who want to add the course,
distribute these students among the available sections such that after adding all of the students the sections have nearly the
same number of spaces available.
Example Execution:
Enter the space remaining for div01sec01: 7
Enter the space remaining for div01sec02: 6
Enter the space remaining for div02sec01: 8
Enter the space remaining for div02sec02: 4
Enter the space remaining for div03sec01: 9
Enter the space remaining for div03sec02: 3
Enter the space remaining for div04sec01: 1
Enter the space remaining for div04sec02: 2
Enter the space remaining for div05sec01: 6
Enter the space remaining for div05sec02: -1
Enter the number of new students to enroll: 10
Total Sections Used: 9
Original Space Available:
div01sec01: 7
div01sec02: 6
div02sec01: 8
div02sec02: 4
div03sec01: 9
div03sec02: 3
div04sec01: 1
div04sec02: 2
div05sec01: 6
Space Now Available:
div01sec01: 5
div01sec02: 5
div02sec01: 5
div02sec02: 4
div03sec01: 5
div03sec02: 3
div04sec01: 1
div04sec02: 2
div05sec01: 6
Example Execution #2:
Enter the space remaining for div01sec01: 10
Enter the space remaining for div01sec02: 12
Enter the space remaining for div02sec01: 14
Enter the space remaining for div02sec02: 15
Enter the space remaining for div03sec01: 18
Enter the space remaining for div03sec02: 22
Enter the space remaining for div04sec01: 10
Enter the space remaining for div04sec02: 20
Enter the space remaining for div05sec01: 13
Enter the space remaining for div05sec02: 10
Enter the space remaining for div06sec01: 12
Enter the space remaining for div06sec02: 13
Enter the space remaining for div07sec01: 18
Enter the space remaining for div07sec02: 20
Enter the space remaining for div08sec01: 21
Enter the space remaining for div08sec02: 22
Enter the space remaining for div09sec01: 21
Enter the space remaining for div09sec02: 20
Enter the space remaining for div10sec01: 21
Enter the space remaining for div10sec02: 22
Enter the space remaining for div11sec01: 15
Enter the space remaining for div11sec02: 18
Enter the space remaining for div12sec01: 17
Enter the space remaining for div12sec02: 15
Enter the space remaining for div13sec01: 10
Enter the number of new students to enroll: 300
Total Sections Used: 25
Original Space Available:
div01sec01: 10
div01sec02: 12
div02sec01: 14
div02sec02: 15
div03sec01: 18
div03sec02: 22
div04sec01: 10
div04sec02: 20
div05sec01: 13
div05sec02: 10
div06sec01: 12
div06sec02: 13
div07sec01: 18
div07sec02: 20
div08sec01: 21
div08sec02: 22
div09sec01: 21
div09sec02: 20
div10sec01: 21
div10sec02: 22
div11sec01: 15
div11sec02: 18
div12sec01: 17
div12sec02: 15
div13sec01: 10
Space Now Available:
div01sec01: 4
div01sec02: 4
div02sec01: 4
div02sec02: 4
div03sec01: 4
div03sec02: 4
div04sec01: 4
div04sec02: 4
div05sec01: 4
div05sec02: 4
div06sec01: 4
div06sec02: 4
div07sec01: 4
div07sec02: 4
div08sec01: 4
div08sec02: 4
div09sec01: 5
div09sec02: 5
div10sec01: 5
div10sec02: 5
div11sec01: 5
div11sec02: 5
div12sec01: 5
div12sec02: 5
div13sec01: 5
15 replies to this topic
#1
Posted 24 April 2011 - 12:25 PM
|
|
|
#2
Posted 24 April 2011 - 12:37 PM
What do you have so far?
#3
Posted 24 April 2011 - 12:39 PM
#include<stdio.h>
int getInput(int[]);
int main()
{
int array[25];
int x;
x = getInput(array);
return 0;
}
int getInput(int array[])
{
int i = 0;
int div;
int sec;
for (div = 1; div < 14; div++)
{
for (sec = 1; sec < 3; sec++)
{
printf("Enter the space remaining for div%dsec%d: ", div, sec);
scanf("%d", &array[i]);
i++;
}
}
return (i-1);
}
That's my work on the input. I can't seem to have it stop at -1 or at 25 iterations.
#4
Posted 24 April 2011 - 12:42 PM
I can give you some hints to help out, but you have to do that yourself and i would be happy to suggest ways when you are stuck:
Following is a rough algorithm:
1. Use an array of sections where each element indicates the remaining number of vacant student slots.
2. When ever you receive a number of students who have no conflicts, iterate through the array. At each slot decrement by one meaning you removed one seat from that section.
3. Also decrement total num of students since you adjusted one of them in a class.
4. Do this by taking % (mod) available classes. The termination condition would be while remaining students to be added is not zero or all classes are full.
Mod does this (say you have 20 students to fill in 5 classes). Your array size would be 5 for 5 classes and you iterate mod 5. In first iteration you put five student in each of 5 classes, then
because of mod 6th boy gets into class 1, 7th in 2 and so on.
Hope that helps.
Following is a rough algorithm:
1. Use an array of sections where each element indicates the remaining number of vacant student slots.
2. When ever you receive a number of students who have no conflicts, iterate through the array. At each slot decrement by one meaning you removed one seat from that section.
3. Also decrement total num of students since you adjusted one of them in a class.
4. Do this by taking % (mod) available classes. The termination condition would be while remaining students to be added is not zero or all classes are full.
Mod does this (say you have 20 students to fill in 5 classes). Your array size would be 5 for 5 classes and you iterate mod 5. In first iteration you put five student in each of 5 classes, then
because of mod 6th boy gets into class 1, 7th in 2 and so on.
Hope that helps.
#5
Posted 24 April 2011 - 12:51 PM
This was my idea as I get farther into the program:
Set an array to represent each amount of available seats in the classes like you said. Then have it search for the highest number in that array and take one away from it. Also, take on away from the total number of students that need a class. Then rerun that function to find the highest number again and take one away from it. So on and so on. The termination would be all numbers in the array are 0 or the number of students needing a class is 0. Does this make sens and will this work? Your post kind of confused me towards the end a little bit with the mods.
Set an array to represent each amount of available seats in the classes like you said. Then have it search for the highest number in that array and take one away from it. Also, take on away from the total number of students that need a class. Then rerun that function to find the highest number again and take one away from it. So on and so on. The termination would be all numbers in the array are 0 or the number of students needing a class is 0. Does this make sens and will this work? Your post kind of confused me towards the end a little bit with the mods.
#6
Posted 24 April 2011 - 12:55 PM
KingSnake91 said:
This was my idea as I get farther into the program:
Set an array to represent each amount of available seats in the classes like you said. Then have it search for the highest number in that array and take one away from it. Also, take on away from the total number of students that need a class. Then rerun that function to find the highest number again and take one away from it. So on and so on. The termination would be all numbers in the array are 0 or the number of students needing a class is 0. Does this make sens and will this work? Your post kind of confused me towards the end a little bit with the mods.
Set an array to represent each amount of available seats in the classes like you said. Then have it search for the highest number in that array and take one away from it. Also, take on away from the total number of students that need a class. Then rerun that function to find the highest number again and take one away from it. So on and so on. The termination would be all numbers in the array are 0 or the number of students needing a class is 0. Does this make sens and will this work? Your post kind of confused me towards the end a little bit with the mods.
You should go ask Bill Crum, buddy. He knows how to do it. How did you do on the second exam?
#7
Posted 24 April 2011 - 12:57 PM
I would but I have 2 meetings soon =/ does he have office hours tomorrow? Ummmm I got just a little above average. You?
#8
Posted 24 April 2011 - 01:20 PM
KingSnake91 said:
I would but I have 2 meetings soon =/ does he have office hours tomorrow? Ummmm I got just a little above average. You?
I got 78.
I am really struggling with this assignment as well. I cannot even figure out the getInput function.
#9
Posted 24 April 2011 - 01:29 PM
Can you text me if you figure it out?! 1-812-453-1893
#10
Posted 24 April 2011 - 01:30 PM
KingSnake91 said:
This was my idea as I get farther into the program:
Set an array to represent each amount of available seats in the classes like you said. Then have it search for the highest number in that array and take one away from it. Also, take on away from the total number of students that need a class. Then rerun that function to find the highest number again and take one away from it. So on and so on. The termination would be all numbers in the array are 0 or the number of students needing a class is 0. Does this make sens and will this work? Your post kind of confused me towards the end a little bit with the mods.
Set an array to represent each amount of available seats in the classes like you said. Then have it search for the highest number in that array and take one away from it. Also, take on away from the total number of students that need a class. Then rerun that function to find the highest number again and take one away from it. So on and so on. The termination would be all numbers in the array are 0 or the number of students needing a class is 0. Does this make sens and will this work? Your post kind of confused me towards the end a little bit with the mods.
Your idea is fine - I missed the aspect of "highest number present already". So modes is only useful if you know you have to put students sequentially going into every class. Where as here you need to take their current count into account.
#11
Posted 24 April 2011 - 01:35 PM
To stop at -1 you can immediately check input after scanf and break.
To limit to 25 iterations, you can put a separate counter in the start of input function which keeps incrementing every time a successful entry is made.
This would work even if there is a bug in the rest of your code.
To limit to 25 iterations, you can put a separate counter in the start of input function which keeps incrementing every time a successful entry is made.
This would work even if there is a bug in the rest of your code.
#12
Posted 24 April 2011 - 03:22 PM
KingSnake91 said:
Can you text me if you figure it out?! 1-812-453-1893
If I cannot figure out the getInput tonite, I think I will give up.
1 user(s) are reading this topic
0 members, 1 guests, 0 anonymous users


Sign In
Create Account

Back to top









