[Csharp]
/*
* Start the program header annotation.
* Copyright and version Declaration of the program
* Copyright (c) 2011, a student from the computer College of Yantai University
* All rights reserved.
* File name: name of all students whose student ID is odd
* Author: Xue Guangchen
* Completion date: January 1, September 16, 2011
* Version No.: x1.0
* Description of tasks and Solutions
* Input description:
* Problem description: Enter the student ID and name, and add the nonexistent student ID to the hashtable instance,
* A prompt is displayed for the student ID. After the input, all students whose student IDs are odd are output.
* Program output:
* End the comment in the program Header
*/
Using System;
Using System. Collections. Generic;
Using System. Linq;
Using System. Text;
Namespace Student
{
Class Program
{
Static void Main (string [] args)
{
Bool B = true;
Console. Write ("Enter the number of students you want to save :");
Int count = int. Parse (Console. ReadLine ());
Hashtable [] h = new hashtable [count];
Int I = 1;
Do
{
If (I <count)
{
Console. Write ("Enter the student ID {0}:", I );
Int num = int. Parse (Console. ReadLine ());
Console. Write ("enter the name of student {0}:", I );
String name = Console. ReadLine ();
For (int k = 0; k <I-1; ++ k)
{
If (h [k]. get_Number (). Equals (num ))
{
Console. WriteLine ("this student's information has been saved. Please do not enter it again! ");
B = false;
Break;
}
}
If (B)
{
H [I-1] = new hashtable ();
H [I-1]. set_Input (num, name );
++ I;
}
}
Else
{
Console. WriteLine ("the number of students you entered has reached your preset value. Please stop typing! ");
Break;
}
Console. WriteLine ();
Console. WriteLine ("press 0 to end the input, any key to continue ...");
If (Console. ReadLine () = "0 ")
Break;
} While (true );
Console. WriteLine ("{0} {1}", h [0]. num, h [0]. name );
Hashtable. output (h, I );
Console. ReadKey ();
}
}
Class hashtable
{
Public int num;
Public string name;
Public hashtable (int num1, string name1)
{
Num = num1;
Name = name1;
}
Public hashtable ()
{
Num = 0;
Name = null;
}
Public void set_Input (int num1, string name1)
{
Num = num1;
Name = name1;
}
Public int get_Number ()
{
Return num;
}
Public static void output (hashtable [] h, int I)
{
Console. WriteLine ("student ID name ");
For (int n = 0; n <I-1; ++ n)
{
If (h [n]. get_Number () % 2! = 0)
{
Console. WriteLine ("{0} {1}", h [n]. num, h [n]. name );
}
}
}
}
}
Running result: