I know I am bad, can I get some help?

I have to build program to generate seating plan for an exam. The program should read three numbers . The first number is the number of students, the number of rows and the number of seats in a row ( same for every row ).There will be one empty seat between every two neighboring students on the same row or on the same column. After user input the number of student, rows and seats in a row, the program should compute and print out the maximum number of students that the classroom can support. The program will stop immediately if the number of student provided by the user is larger than the maximum value. Otherwise, The program should also print out the seating plan row by row on the screen. If a seat is taken by a student, it will simply print out his/her student ID. Otherwise, -1 will be printed. This project assumes that the student IDs are 1000001 for the first student, 1000002 for the second...... The width of output is set to 10 .


How to generate the plan if there is one row and when there are multiple rows? I know I am so bad to ask all of the program but can someone help me please? Much appreciation.
1. The program should read three numbers .
2. The first number is the number of students, the number of rows and the number of seats in a row ( same for every row ).
3. There will be one empty seat between every two neighboring students on the same row or on the same column.
4. After user input the number of student, rows and seats in a row, the program should compute and print out the maximum number of students that the classroom can support.
5. The program will stop immediately if the number of student provided by the user is larger than the maximum value. Otherwise, The program should also print out the seating plan row by row on the screen.
6. If a seat is taken by a student, it will simply print out his/her student ID. Otherwise, -1 will be printed.
7. This project assumes that the student IDs are 1000001 for the first student, 1000002 for the second......
8. The width of output is set to 10 .

You have 8 steps.

Steps 1 and 2....

How would you accomplish this? Show us some code, or an effort at some code at least.
Sorry I am still new to C++. I am currently working on Q.1(where there's only one row.

#include<iostream>
using namespace std;
int n_of_students, n_of_rows, n_of_seatsinarow;
void main(){
cin>> n_of_students >> n_of_rows >> n_of_seatsinarow;

cout << "Maximum number of students is: " << n_of_seatsinarow/2 + n_of_seatsinarow%2 ;

if (n_of_students < n_of_seatsinarow/2 + n_of_seatsinarow%2)
cout <<


}

I can only come up these codes and have no idea about how to generate the sitting plan. I am thinking about using the for loop? I am not certain how to actually do it.



First... on the right side of the box you are typing in is a picture menu labeled format.
Select your code (it turns blue) then hit <> Those are code tags. :)

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
#include<iostream>  // You need a space between include and <iostream>
using namespace std; // This is a bad practice, It's okay for this program level, 
                                 // but as soon as you get the chance read up on namespaces.
                                 // The sooner you break this habit, the better you'll be.

int n_of_students, n_of_rows, n_of_seatsinarow;
                                // Those variable names are okay, but long. You'll be typing them
                               // quite a bit. You sure about those names?
             



// void main(){           NEVER.. EVER EVER EVER Even if Santa promises you a new
                             // choo choo for Christmas use void main... 

int main(){

cin>> n_of_students >> n_of_rows >> n_of_seatsinarow;

// This will not work in C++. You need to print a line, then ask for input.

cout << "Maximum number of students is: " << n_of_seatsinarow/2 +n_of_seatsinarow%2 ;

// Wait a minute... where does the value for  n_of_seatsinarow come from? You haven't declared this anywhere...

if (n_of_students < n_of_seatsinarow/2 + n_of_seatsinarow%2)
// You are missing the opening bracket for this block of code
cout <<

return 0; // ( required from int main )
}

Man, you jump right in there don't cha? Okay, let's back and plan this out. You don't have one line of code correct, except line 6. You need to catch up to the class young man.

You need a chart of the seats. How many rows? How many seats in a row?
How can we keep track of where a STUDENT is sitting? In what row? What seat?

I have an idea... Let try for the coveted two dimensional array.

student [n_of_rows] [n_of_seatsinarow]={-1};

// There you have your seats all lined up, and they = -1 (for the empty seats.
// another requirement for your project)

Google "C++ two dimensional arrays" and read up on them... I bet they'll help you a lot.
Here's one to get you started.

http://www.cplusplus.com/doc/tutorial/arrays/
You also need to read up on variables, assigning a value to them, cin, and functions. You have a lot to do.


Last edited on
Topic archived. No new replies allowed.