Input password login to main interface, enter student number, sort after output

Source: Internet
Author: User
Tags strcmp

N title: input password Login to main interface, enter student number, sort after output

N 1. Language and Environment

A, the implementation of language

C Language

B, environmental requirements

VC + + 6.0

N 2. Requirements

Please write a C language program. output Several student numbers in alphabetical order (from small to large).

The functional requirements for the program are as follows:

    1)    input password " admin ", right into the main interface, error is directly introduced ( exit ( 0

2) Enter 5 student number "BJS1001"from the keyboard, "BJS2001". "BJS1011", "SHS2001" and "SHS1001".

3) sort the 5 student numbers.

4) output The sorted student number to the screen.

The program performs the reference interface diagram to see:

Figure 1

Figure 2

N 3. Algorithm Description

The size of the character in the student number. Can be implemented using the bubble sort method or the Insert Sort method.

N 4. Recommended Implementation Steps

1. Write the main function

1) define an array for holding student numbers:Char str[5][20];

2)   According to the number of student numbers specified (requires 5 to store the student number entered by the keyboard in the array (1 student number. Loop accepts gets (Str[i]) , str[i] is the first address of each string).

3) Call the Sort sub-function sort ()and use the bubble sort or insert Sort method to sort the 5 student numbers from small to large. (Similar to normal one-dimensional arrays, with strcmp(str[i],str[i+1])>0 The size of the string as an inference condition. Use strcpy (str[i],str[i+1])) and a temporary character array temp[20] to implement the exchange of strings).

4) Achieve the output of the sorted student number.

2. Write the Sort() sub-function

There are 2 parameters required:

The first 1 parameters are: An array of student numbers in the sort order,char name[5][20].

The first 2 Participants are the number of student numbers in the students number array. int n.

Function:

1) Use the cycle to compare the size of multiple student numbers.

2) to call the system function when comparing the student number size:

strcmp (string1, string2);

3) Use the bubble Sort method or select the sorting method.

N 5. Precautions

A, please note that the necessary gaze is added to the code;

B, please note that the code is written and named in accordance with the specification.

N 6. Submit Content

Submit program code



#include <stdio.h>
#include <string.h>
void Main ()
{


Char mima[10];
int x[100];
int k,a,b,c,t;
printf ("Password:");
Gets (Mima);
while (1)
{
K=STRCMP (Mima, "123");
if (k==0)
{
printf ("landed successfully. Please continue with the operation ");
printf ("Please enter the number of students");
scanf ("%d", &a);
for (b=0;b<a;b++)
{
printf ("Please enter the number of%d students", b+1);
scanf ("%d", &x[b]);

}
for (b=0;b<a-1;b++)
{for (c=0;c<a-b-1;c++)
if (x[c]>x[c+1])
{
T=X[C];
X[C]=X[C+1];
x[c+1]=t;
}
}
printf ("The result is \ n");
for (b=0;b<a;b++) printf ("%d\n", X[b]);
}
}

}

Input password login to main interface, enter student number, sort after output

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.