C # assignments for week 4 3.4 all students whose student IDs are odd

Source: Internet
Author: User

[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:

 

Related Article

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.