Automatic assignment of exam numbers

Source: Internet
Author: User

# Include <iostream>
# Include <vector>
# Include <cstring>
# Include <string>
# Include <iomanip>

Using namespace std;

Typedef struct
{
Int num; // student ID
Char name [20]; // Student name
Char textID [9]; // student admission ticket No.
} Student;
Vector <Student> svec;
Int a3; // use a3 to store the number of test rooms
Int a4; // used to store the number of people in the last unfilled classroom
Const CODE = 18; // The school CODE has been set to 18;
Vector <Student>: iterator iter_begin;

Void input_students_info () // function for inputting Student Information
{
String str;
While (! (Str = "N" | str = "n "))
{

Cout <"/n enter your student ID:" <endl;
Int a1; // enter the student ID.
Cin> a1;
While (a1 <0 | a1> 1000000000)
{
Cout <"the student ID range does not meet the requirements. Please enter it again! "<Endl;
Cin> a1;
Cin. clear ();
}

Cout <"enter your name:" <endl;
Char p1 [20];
Cin. clear ();
Cin> p1;
Cin. clear ();

Student s;
S. num = a1;
Strcpy (s. name, p1 );
Strcpy (s. textID ,"");
Svec. push_back (s );
Cout <"do I need to enter the information of the next candidate? Press (N/n) to end the input, and press any key to continue: "<endl;
Cin> str;

} // While ends

Cout <"the examinee information is entered! "<Endl;
Cout <"Total" <svec. size () <"candidates apply for exams" <endl;
Return;
}

Void produce_text_number ()
{
Int a2; // used to record the maximum number of students per Exam Room
Cout <"Enter the maximum number of students per test room (no more than 30):" <endl;
Cin> a2;
Cin. clear ();
While (! (A2> = 0 & a2 <= 30 ))
{
Cout <"the input does not meet the requirements. Please enter it again! "<Endl;
Cin> a2;
Cin. clear ();
}

If (svec. size () % a2) // if it is not just full, add a test room
{
A3 = svec. size ()/a2 + 1;
A4 = svec. size () % a2;
}

Else a3 = SVEC. Size ()/A2; // the classroom is full.

Iter_begin = SVEC. Begin ();
If (A4! = 0) // when a classroom is not full
{

For (INT I = 1; I <= a3-1; ++ I) // first-installed classroom
{
For (Int J = 1; j <= a2; ++ J, ++ (iter_begin ))
{
Char S1 [9];
Int first = 0, second = 0, oldfirst = 0, oldsecond = 0; // used to find the first two digits of the student ID
S1 [0] = (I/10) + 48;
S1 [1] = (I % 10) + 48;
S1 [2] = (code/10) + 48;
S1 [3] = (code % 10) + 48;
First = (* iter_begin). Num/10;
Second = (* iter_begin). Num % 10;
While (first! = 0)
{
Oldfirst = first;
Oldsecond = second;
Second = first % 10;
First = first/10; // The error is found here, and their order is not noticed. If it is first = first/10, then second = first % 10;
// The remainder of the new first is obtained, and the remainder of the oldfirst is required. You can write it like this.
// First = oldfirst/10; second = oldfirst % 10; do not care about their order
}
S1 [4] = oldfirst + 48;
S1 [5] = oldsecond + 48;
S1 [6] = (j/10) + 48;
S1 [7] = (j % 10) + 48;
S1 [8] = '/0 ';
Strcpy (* iter_begin). textID, s1 );
} // The End Of The for Loop
} // The external for loop ends.

For (int k = 1; k <= a4; ++ k, ++ (iter_begin) // process test rooms that are not full
{
Char s1 [9];
Int first = 0, second = 0, oldfirst = 0, oldsecond = 0; // used to find the first two digits of the student ID
S1 [0] = (I/10) + 48;
S1 [1] = (I % 10) + 48;
S1 [2] = (CODE/10) + 48;
S1 [3] = (CODE % 10) + 48;
First = (* iter_begin). num/10;
Second = (* iter_begin). num % 10;
While (first! = 0)
{
Oldfirst = first;
Oldsecond = second;
Second = first % 10;
First = first/10;
}
S1 [4] = oldfirst + 48;
S1 [5] = oldsecond + 48;
S1 [6] = (k/10) + 48;
S1 [7] = (k % 10) + 48;
S1 [8] = '/0 ';
Strcpy (* iter_begin). textid, S1 );
}

 

} // If (A4! = 0) Processing ended

Else
{
For (INT I = 1; I <= A3; ++ I) // you can specify a full classroom.
{
For (int j = 1; j <= a2; ++ j, ++ (iter_begin ))
{
Char s1 [9];
Int first = 0, second = 0, oldfirst = 0, oldsecond = 0; // used to find the first two digits of the student ID
S1 [0] = (I/10) + 48;
S1 [1] = (I % 10) + 48;
S1 [2] = (CODE/10) + 48;
S1 [3] = (CODE % 10) + 48;
First = (* iter_begin). num/10;
Second = (* iter_begin). num % 10;
While (first! = 0)
{
Oldfirst = first;
Oldsecond = second;
Second = first % 10;
First = first/10;
}
S1 [4] = oldfirst + 48;
S1 [5] = oldsecond + 48;
S1 [6] = (J/10) + 48;
S1 [7] = (J % 10) + 48;
S1 [8] = '/0 ';
Strcpy (* iter_begin). textid, S1 );
} // The End Of The For Loop
} // The external for loop ends.

} // Else ends

}

Void show_arrange_result ()
{
Char ch;
Iter_begin = SVEC. Begin ();
For (; iter_begin! = SVEC. End (); ++ iter_begin)
{
Cout <"name:" <setw (20) <(* iter_begin ). name <"student ID:" <setw (10) <(* iter_begin ). num <"Admission Ticket number" <setw (10) <(* iter_begin ). textID <endl;
}
Cin> ch;

}

Void main ()
{
Input_students_info ();
Produce_text_number ();
Show_arrange_result ();

}

/* Error summary:

(1) This is a low-level error and does not notice their order. If it is first = first/10, then second = first % 10;
The remainder of the new first is obtained, and the remainder of the oldfirst is required. You can write it like this.
First = oldfirst/10; second = oldfirst % 10; so do not care about their order

*/
 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.