利用jsshell 实现的学生信息管理系统

利用JS实现的学生信息管理系统

//全局变量
var x = 0;//用作判断是执行
var arrayNum = 0;
var infoArray = [{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{}];
function headOuput(){
    print("\n");
    print("\t\t\t------------------------- STUDENT INFO MANAGE SYSTEM -------------------------");
    print("\t\t\t|*                             1.input record                               *|");
    print("\t\t\t|*                             2.delete record                              *|");
    print("\t\t\t|*                             3.list record                                *|");
    print("\t\t\t|*                             4.search record                              *|");
    print("\t\t\t|*                             5.quit system                                *|");
    print("\t\t\t------------------------------ -------------- --------------------------------\n");
}


//用于系统循环
function loopExcute(){
        print("\t\t\tplease choose one number !");
        x = readline();//用户在控制台输入一个数,存入X中
        if(x == 5){
            print("Exit the System Successful, see you later !");
        }else{
            if(x == 1){
                inputR();
            }else if(x == 2){
                deleteR();
            }else if(x == 3){
                listR();
            }else if(x == 4){
                searchR();
            }else{
                print("Please input the number between one to five!");
                loopExcute();
            } 
        }
          
}


//输入记录的函数
function inputR(){
    print("If you do not want to input,please input 'no / NO' !");
    var id,clas,tel,name;
    while(1){
        print("name:")
            name = readline();
        if(name != "no" && name != "NO"){
            var ob = new Object();
            ob.name = checkName(name);
            print("id:");
            id = readline();
            ob.id = checkID(id);
            print("class:");
            clas = readline();
            ob.class = checkClass(clas);
            print("Tel:");
            tel = readline();
            ob.tel = checkTel(tel);
            print("chinese:");
            ob.chinese = readline();
            print("math:");
            ob.math = readline();
            print("english:");
            ob.english = readline();
            infoArray[arrayNum] = ob;
            arrayNum++;
            print("Input Successful!\n");
        }
        else{
           break;
        }
    }
    loopExcute(); 
}
//删除记录的函数
function deleteR(){
    print("Please input the number you want to delete !");
    var Idnum = readline();
    for(var i = 0 ; i<arrayNum; i++){
        if(infoArray[i].id == Idnum){
            infoArray.splice(i,1);
            //判断是否删除成功
            print("Delete Successful !");
            arrayNum--;
            loopExcute();
        }
    }
    if(i == arrayNum){
           print("No destination you want to delete !");
           loopExcute();
        }
}


//输出记录的函数
function listR(){
    if(arrayNum>0){
        print("\t\t\t\t\t\t  STUDENTS INFOMATION TABLE");
        print("\t\t\t-------------------------------------------------------------------------------");
        print("\t\t\t|*  name  |   id   |  clas  |      tel      |  chinese  |  math  |  english  *|")
        print("\t\t\t-------------------------------------------------------------------------------");
        for(var i = 0 ; i < arrayNum ; i++){
                print("\t\t\t|*"+infoArray[i].name+"|"+infoArray[i].id+"|    "+infoArray[i].class+"   |  "+infoArray[i].tel+"  |    "+infoArray[i].chinese+"    |  "+infoArray[i].math+"   |     "+infoArray[i].english+"   *|");
                print("\t\t\t-------------------------------------------------------------------------------");
            }
            print("\n");
        loopExcute();
    }else{
        print("There is no any record !");
        print(arrayNum);
        loopExcute();
    }
    
}
function searchR(){
    print("Please input the id number you want to find !");
    var Idnum = readline();
    findId(Idnum);    
}
function findId(idNum){
    var i = 0;
    var id,clas,tel;
        for(i = 0 ; i<arrayNum; i++){
        if(infoArray[i].id == idNum){
            print("The info of the student is\n");
            print("name:"+infoArray[i].name);
            print("id:"+infoArray[i].id);
            print("class:"+infoArray[i].class);
            print("tel:"+infoArray[i].tel);
            loopExcute();
        }
    }
    if(i >= arrayNum){
            print("Do not find the result !\n");
            print("Y/N to input the ID !")
            var isInput = readline();
            if(isInput == "Y" || isInput == "y"){
                var ob = new Object();
                print("name:");
                name = readline();
                ob.name = checkName(name);
                print("id:");
                print(idNum);
                ob.id = idNum;
                print("class:");
                clas = readline();
                ob.class = checkClass(clas);
                print("Tel:");
                tel = readline();
                ob.tel = checkTel(tel);
                print("chinese:");
                ob.chinese = readline();
                print("math:");
                ob.math = readline();
                print("english:");
                ob.english = readline();
                infoArray[arrayNum] = ob;
                arrayNum++;
                print("Input Successful!\n");
                loopExcute();
            }else{
                loopExcute();
            }
        }
}


function checkName(name){
    var isCharactor;
    var nameL
    for(var i = 0 ; i<name.length ; i++){
        if(!((name[i] >= "a" && name[i] <= "z")||(name[i] >= "A" && name[i] <= "Z"))){
            isCharactor = true
        }
    }
    if (isCharactor) {
        print("Name must be contained by a~z / A~Z !");
        name = readline();
        if(name == "no" && name == "NO"){
            loopExcute();
        }
        checkName(name);
    }
    return name;
}


function checkID(id){
    var idString = String(id);
    var isnum;
    for(var i = 0 ;i<idString.length;i++){
        if(!(idString[i] >=0 && idString[i]<=9)){
            isnum = true;
        }
    }
    if(isnum){
        print("The id must be contained by 0~9 !");
        id = readline();
        checkID(id);
    }
    return id;
}


function checkClass(clas){
    if(!(clas >= 0 && clas <= 9)){
        print("The class must be contained by 0~9 !");
        clas = readline();
        checkClass(clas);
    }
    return clas;
}
function checkTel(tel){
    var telPhone = String(tel);
    var isEven;
    var isNum;
    for(var i = 0; i<telPhone.length ;i++){
        if(telPhone.length == 11){
            isEven = true;
        }
        if(!(telPhone[i]>=0 && telPhone[i]<=9)){
            isNum = true;
        }
    }
    if(isEven){
        if(isNum){
            print("The telPhone number must be contained by 0~9");
            tel = readline();
            checkTel(tel);
        }
    }else{
        print("The telPhone number must have 11 bunbers!");
        tel = readline();
        checkTel(tel);
    }
    return tel;
}
headOuput();
loopExcute();
    

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值