node. JS run simple student Information management system

Source: Internet
Author: User

Const ReadLine = require (' Readline-sync ');
Student Information
let users = [{
Id:1,
Name: ' Liu ',
Age: ' 17 ',
Gender: ' Male ',
Score: ' 98 '

},
{
Id:2,
Name: ' Dog ',
Age: ' 18 ',
Gender: ' Male ',
Score: ' 81 '

},
{
Id:3,
Name: ' Xingxing ',
Age: ' 20 ',
Gender: ' Male ',
Score: ' 79 '

},
{
Id:4,
Name: ' Coco ',
Age: ' 16 ',
Gender: ' Female ',
Score: ' 73 '

},
{
Id:5,
Name: ' Along ',
Age: ' 15 ',
Gender: ' Female ',
Score: ' 66 '

}
];
account password
Let admin = [{
Username: ' 1 ',
Password: ' 1 '
}]
Login
function IsLogin (admin) {
Let num = 3;
while (true) {
Console.log (' Please enter account: ');
Let username = readline.question ();
Console.log (' Please enter password: ');
Let password = readline.question ();
for (Let i = 0; i < admin.length; i++) {
if (Admin[i].username = = Username && Admin[i].password = = password) {
Console.log (' login success ');
Notemenu ();
Return
}
}
num--;
if (num <= 0) {
Console.log (' Error 3 times, lock card ');
return num;
} else
Console.log (' Login failed, you have ${num} chance, please re-enter ');
}
}
Registered
function Isregister (admin) {
while (true) {
Console.log (' Please enter account: ');
Let username = readline.question ();
Console.log (' Please enter password: ');
Let password = readline.question ();
Let isOk = false;
for (Let i = 0; i < admin.length; i++) {
if (Admin[i].username = = username) {
Console.log (' User name is registered, please re-enter ');
IsOk = true;
Break
}
}
if (!isok) {
Admin.push ({
Username
Password
});
Console.log (' registered success ')
Menu (admin);
Return
}
}
}
Main Menu
Function Menu (Admin) {
while (true) {
Console.log (' 1. Login 2. Registration 3. Switch User ')
Console.log (' Please select the action to take: ')
Let option = readline.question ()-0;
Switch (option) {
Case 1:
Let num = islogin (admin);
if (num <= 0) {
Return
}
Break
Case 2:
Isregister (admin);
Break
Case 3:
IsLogin (admin);
Break
Default
Console.log (' Please enter the correct option ');
}
}
}
Action menu
function Notemenu () {
while (true) {
Console.log (' Select operation: 1.2. Add 3. Modify 4. Delete 5. Exit ')
Let option = readline.question ()-0;
Switch (option) {
Case 1:
Find ();
Break
Case 2:
AddUsers ();
Break
Case 3:
Change ();
Break
Case 4:
Deletsth ();
Break
Case 5:
Return
Default
Console.log (' Please enter the correct option ');

}
}

}
Inquire
function Find () {

Console.log (' Please input Query method: 1. Query all 2. Category Enquiry ');
Let option = readline.question ()-0;
Switch (option) {
Case 1:
FindAll ();
Break
Case 2:
Splitclass ();
Break
Default
Console.log (' Please enter the correct option ');
}
}
Query all
function FindAll () {
for (Let i = 0; i < users.length; i++) {
Console.log (Users[i]);
}
}
Search by Category
function Splitclass () {
Console.log (' Please select operation: 1. Name 2. Age 3. Gender 4. Score ');
Let option = readline.question ()-0;
Switch (option) {
Case 1:
Allname ();
Break
Case 2:
Userage ();
Break
Case 3:
Sex ();
Break
Case 4:
Scoreall ();
Break
Default
Console.log (' Please enter the correct option ');
}
}
Name Query
function Allname () {
Console.log (' Please enter the name to be queried ');
Let name = Readline.question ();
Let isOk = false;
for (Let i = 0; i < users.length; i++) {
if ((Users[i].name). Includes (name)) {
Console.log (Users[i]);
IsOk = true;
}
}
if (!isok) {
Console.log (' did not find the student ');

}
}
Age Enquiry
function Userage () {
while (true) {
Console.log (' Please enter the age to inquire ');
Let-age = readline.question ();
Let Reg =/^\d{1,3}$/;
Let isOk = false;
if (reg.test (age) = = True) {
for (Let i = 0; i < users.length; i++) {
if ((Users[i].age). Includes (age)) {
Console.log (Users[i]);
IsOk = true;
}
}
if (!isok) {
Console.log (' did not find students of that age ');
Return
} else
Return
} else {
Console.log (' Error, please enter the correct age ');

}
}
}
Gender search
function Sex () {
Console.log (' Please select the gender to be queried: 1. Male 2. Female ');
Let sel = readline.question ()-0;
Let mans =/^male$/,
Woman =/^female$/;
Switch (SEL) {
Case 1:
Sexsel (man);
Break
Case 2:
Sexsel (woman);
Break
}

}
Sex screening
function Sexsel (Sex) {
for (Let i = 0; i < users.length; i++) {
if (Sex.test (Users[i].gender)) {
Console.log (Users[i]);
}
}
}
Score Query
function Scoreall () {
Console.log (' Please enter a score to query ');
Let score = Readline.question ();
Let isOk = false;
for (Let i = 0; i < users.length; i++) {
if ((Users[i].score). Includes (score)) {
Console.log (Users[i]);
IsOk = true;
}
}
if (!isok) {
Console.log (' did not find students with this score ');

}
}
New
function AddUsers () {
while (true) {
Console.log (' Please enter new Student's name: ');
Let name = Readline.question ();
Console.log (' Please enter new Student Age: ');
Let-age = readline.question ();
Console.log (' Please enter new Student gender: ');
Let gender = readline.question ();
Console.log (' Please enter new Student score: ');
Let score = Readline.question ();
Let regname =/^[a-za-z]+$/; Restricted names can only be made up of letters
Let regage =/^\d{1,2}$/; Limit age can only be made up of numbers
Let Reggender =/^female|male$/; Restricted by male and female only
Let Regscore =/^ ((\d{1,2}) | ( 1[0-4]\D) | (150)) $/; Limit grades to only 0-150
if (regname.test (name)) {
if (Regage.test (age)) {
if (reggender.test (gender)) {
if (Regscore.test (score)) {
Users.push ({
ID: ' ${users.length+1} ',
Name
Age
Gender
Score
})
Console.log (' added successfully, the student information is as follows: ');
Console.log (Users.pop ());
Return
} else
Console.log (' score can only be in 0-150, please re-enter ');
} else
Console.log (' Sex can only be male or female, please re-enter ');
} else
Console.log (' Age can only be made up of numbers, please re-enter ');
} else
Console.log (' name can only consist of letters, please re-enter ');
}

}
//Modify
Function Change () {
Console.log (' Please enter the student number to be modified: ');
Let Stunum = readline.question ()-0;
for (l et i = 0; i < users.length; i++) {
if (users[i].id = = = Stunum) {
Console.log (' Current student information is as follows: ');
Console.log (Users[i]);
Changeall (i);
Return
}
}
Console.log (' Students without this number ');
}
//Modify Main Menu
Function Changeall (i) {
Console.log (' Select the information you want to modify: 1. Name 2. Age 3. Gender 4. Results ');
let option = Readline.question ()-0;
Switch (option) {
Case 1:
Stuname (i),
Break,
Case 2:
Stuage (i),
Break,
Case 3:
Stusex (i);
break;
Case 4:
Stuscore (i),
break,
Default:
Console.log (' Please enter the correct option ');
}
}
//Modify name
function Stuname (i) {
while (true) {
Console.log (' Enter name to modify: ');
Let name = Readline.question ();
Let Reg =/^[a-za-z]+$/;
if (reg.test (name) = = True) {
Users[i].name = name;
Console.log (' modified successfully! The student's information is as follows: ');
Console.log (Users[i]);
return;

} else
Console.log (' Please enter the correct name (letter) ');
}

}
Modify Age
function Stuage (i) {
while (true) {
Console.log (' Please enter the age to be modified: ');
Let-age = readline.question ();
Let Reg =/^\d{1,2}$/;
if (reg.test (age) = = True) {
Users[i].age = age;
Console.log (' modified successfully! The student's information is as follows: ');
Console.log (Users[i]);
Return
} else
Console.log (' Please enter the correct age number (1-2 digits) ');

}

}
Modify gender
function Stusex (i) {
while (true) {
Console.log (' Please enter the gender to be modified: ');
Let gender = readline.question ();
Let Reg =/^female|male$/;
if (reg.test (gender) = = True) {
Users[i].gender = gender;
Console.log (' modified successfully! The student's information is as follows: ');
Console.log (Users[i]);
Return
} else
Console.log (' Please enter the correct gender (male or Famel) ');
}


}
//Modify score
Function Stuscore (i) {
while (true) {
Console.log (' Please enter the score to be modified: ');
Let score = Readline.question ();
Let Reg =/^ ((\d{1,2}) | ( 1[0-4]\D) | (150)) $/;
if (reg.test (score) = = True) {
Users[i].score = score;
Console.log (' modified successfully! The student's information is as follows: ');
Console.log (Users[i]);
return;
} else
Console.log (' Please enter the correct score (0-150) ');
}
}
//delete
function Deletsth () {
while (true) {
Console.log (' Enter student number to delete: ');
Let Stunum = Readline.question ()-0;
Let Reg =/^\d+$/;
if (reg.test (stunum) = = True) {
for (let i = 0; i < users.length; i++) {
if (users[i].id = = = Stunum) {
Console.log (' Current student information is as follows: ');
Console.log (Users[i]);
Deletmenu (i);
return;
}
}
Console.log (' No students found ');
} else
Console.log (' Please enter the correct student number (number) ');
}


}
Delete Main Menu
function Deletmenu (i) {
Console.log (' Is it OK to delete: ');
Console.log (' 1. is 2. No ');
Let option = readline.question ()-0;
Switch (option) {
Case 1:
Delettrue (i);
Break

Case 2:
Return
}
}
OK delete
function Delettrue (i) {
Users.splice (i, 1);
Console.log (' Delete succeeded! ');
}
Menu (admin);

node. JS run simple student Information management system

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.