(1)
You left off the attribute for "available".
Your letter case is inconsistent ("
Class_name" and "
room_number", for example). Pick one or the other.
The "number of students" is duplicate information. Since you have a vector with the student names, you also know how many students there are -- it is the same as the
size() of the vector.
I'll get back to that in a moment.
Watch your indentation.
(2)
I am always bothered by solutions where user input is mixed into modifiers, and also by the names you used for the operation. This is a personal issue, but it is due to what people understand about your code based upon naming.
A name like "get foo" suggests that you return foo from the struct/class -- it is surprising that it communicates to the user.
(3)
Your assignment
does not ask for user input. So, IMHO, you should either get rid of it or move it to main:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
|
int main()
{
classroom my_classroom;
string s;
int n;
cout << "What is your class name? ";
getline( cin, s );
set_class_name( my_classroom, s );
cout << "What is your class room number? ";
cin >> n;
cin.ignore( 1000, '\n' );
set_room_number( my_classroom, n );
...
}
|
1 2 3 4 5 6 7 8
|
int main()
{
classroom my_classroom;
set_class_name( my_classroom, "Biomechanics I" );
set_room_number( my_classroom, 201 );
...
}
|
(4)
To add multiple values to a vector, use a loop. Quit when an empty line is entered:
1 2 3 4 5 6 7 8
|
vector <string> names;
string s;
cout << "Enter student names, one per line. Press Enter twice to finish.\n> ";
while (getline( cin, s ) && !s.empty())
{
names.push_back( s );
cout << "> ";
}
|
When that is done, you have all the student names
and you know how many students there are.
(5) You are required to compare two classrooms two different ways. That means you will need two classrooms.
1 2 3 4 5
|
int main()
{
classroom classroom1;
classroom classroom2;
...
|
1 2 3 4
|
int main()
{
classroom classrooms[ 2 ];
...
|
You will need functions to compare the classrooms -- one for each method
1 2 3 4 5
|
bool is_classroom_larger( const classroom& A, const classroom& B )
{
// return true if A has more chairs than B
// return false otherwise
}
|
1 2 3 4 5 6 7 8 9
|
bool is_classroom_more_utilized( const classroom& A, const classroom& B )
{
// By 'utilization' I assume your professor means that more chairs are
// filled. You will have to compute some percentages here:
// student_names.size() / (double)number_of_chairs
// Don't forget that explicit cast to double -- it is important.
// Compare the ratios. The larger number is more utilized.
}
|
Finally, don't forget to make a function to print your class information:
1 2 3 4
|
void print_classroom( const classroom& A )
{
...
}
|
Hope this helps.