• 软工作业PSP与单元测试训练(选一)


    任务说明(二选一):

    一、实现模块判断传入的身份证号码的正确性;(选一)

    二、实现模块判断传入的电子邮箱账号的正确性;

    实现要求:

    一、实现功能模块;

    1、身份证号长度不合法,返回1;
    2、身份证号第1~17位含有非数字的字符,返回2;
    3、身份证号第18位既不是数字也不是英文小写字母x,返回3;
    4、身份证号的年信息非法,返回4;
    5、身份证号的月信息非法,返回5;
    6、身份证号的日信息非法,返回6;

    二、针对所实现的模块编写对应的单元测试代码;

    #include<stdio.h> 
    #include<stdlib.h> 
    #include<string.h>  
    int verifyIDCard(char* input); 
    int is_leapyear(int year); 
    int getyear(char* input); 
    int getmonth(char* input); 
    int getday(char* input); 
    int check_1to17(char* input); 
    int check18(char* input); 
    int chech_year_month_day(int year, int month, int day);  
    int main() 
    { 
        char input[8][100] = {"511002111222","511002abc123456789", 
        "51100219880808123a","511002188808081234","511002198813081234", 
        "511002198808321234","511002198902291234","511002198808081234"}; 
        int i; 
        for(i=0; i<8; i++) 
        { 
            printf("the IDcard is: %s, the result is: %d
    ",input[i],verifyIDCard(input[i])); 
        } 
        return 0; 
    }   
    int is_leapyear(int year) 
    { 
        if(( (year%4==0) && (year%400!=0) ) || (year%400==0)) 
            return 1; 
        return 0; 
    } 
       
    int getyear(char* input) 
    { 
        int year=0; 
        year = (input[6]-'0') * 1000 + (input[7]-'0') * 100 + 
            (input[8]-'0') * 10 + (input[9]-'0'); 
        return year; 
    }  
    int getmonth(char* input) 
    { 
        int month=0; 
        month = (input[10]-'0') * 10 + (input[11]-'0'); 
        return month; 
    }   
    int getday(char* input) 
    { 
        int day=0; 
        day = (input[12]-'0') * 10 + (input[13]-'0'); 
        return day; 
    }   
    int check_1to17(char* input) 
    { 
        int i; 
        for(i=0; i<17; i++) 
            if( !(input[i]>='0' && input[i]<='9') ) 
                return 0; 
        return 1; 
    }   
    int check18(char* input) 
    { 
        char ch = input[17]; 
        if( (ch=='x') || (ch>='0' && ch<='9') ) 
            return 1; 
        else 
            return 0; 
    }  
    int check_year_month_day(int year, int month, int day) 
    { 
        int leap; 
        leap = is_leapyear(year); 
        if(year<1900 || year>2100) 
            return 4; 
        if(month<1 || month>12) 
            return 5; 
        switch(month) 
        { 
        case 1: 
        case 3: 
        case 5: 
        case 7: 
        case 8: 
        case 10: 
        case 12: 
            { 
                if(day<1 || day>31) 
                    return 6; 
                break; 
            } 
        case 4: 
        case 6: 
        case 9: 
        case 11: 
            { 
                if(day<1 || day>30) 
                    return 6; 
                break; 
            } 
        case 2: 
            { 
                if(leap) 
                { 
                    if(day<1 || day>29) 
                        return 6; 
                    break; 
                } 
                else 
                { 
                    if(day<1 || day>28) 
                        return 6; 
                    break; 
                } 
            } 
        } 
        return 0; 
    }   
    int verifyIDCard(char* input) 
    { 
        int year,month,day; 
        if(strlen(input)!=18) 
            return 1; 
        else 
        { 
            if(!check_1to17(input)) 
                return 2; 
            else 
            { 
                 if(!check18(input)) 
                     return 3; 
                 else 
                 { 
                    year = getyear(input); 
                    month = getmonth(input); 
                    day = getday(input); 
                    return check_year_month_day(year,month,day); 
                 } 
            } 
        } 
    } 
    

     结果图:

     

    三、需要按PSP流程进行工作量估算,填写任务清单工作量估算表。

    任务清单工作量估算表:

    PSP阶段

    时间估算(小时)

    实际实际(小时)

    计划

    估计每个阶段的时间成本

     0.5

     1

    开发

    需求分析

     0.5

     1

    系统设计

     1

     1.5

    设计复审

     2.5

     2

    代码实现

     1

     0.5

    代码复审

     2

     1.5

    测试

     2

     2

    报告

    测试报告

     1.5

     2

    总结

     3

     3.5

  • 相关阅读:
    【leetcode】1215.Stepping Numbers
    【leetcode】1214.Two Sum BSTs
    【leetcode】1213.Intersection of Three Sorted Arrays
    【leetcode】1210. Minimum Moves to Reach Target with Rotations
    【leetcode】1209. Remove All Adjacent Duplicates in String II
    【leetcode】1208. Get Equal Substrings Within Budget
    【leetcode】1207. Unique Number of Occurrences
    【leetcode】689. Maximum Sum of 3 Non-Overlapping Subarrays
    【leetcode】LCP 3. Programmable Robot
    【leetcode】LCP 1. Guess Numbers
  • 原文地址:https://www.cnblogs.com/wulinping/p/8594025.html
Copyright © 2020-2023  润新知