To see the whole version, go to the End and see HTML version on Github.com.
Development BlogContentsPSP FormIdeas of Problem-solvingDesign and Implement ProcessesCode Descriptionmain.pycommon.pyspecific_c.pyUnit TestScreenshots and DescriptionTest DataResultCoverage OptimizationPerformance TestingSummaryEnd
| Process Stages | Estimated Time(min) | Actual Time(min) |
|---|---|---|
| Analyze Problem | 10 | 5 |
| Planning Development | 10 | 5 |
| Modelling Project | 30 | 15 |
| Design Basic Framework | 20 | 20 |
| Design & Develop Assistant Tools | 30 | 120 |
| Review Assistant Tools | 10 | 30 |
| Develop Prototype working on 1st Level | 30 | 40 |
| Review & Fortify Program | 10 | 30 |
| Design 2nd Level Program | 30 | 40 |
| Develop & Review 2nd Level Program | 30 | 200 |
| Design 3rd Level Program | 30 | 20 |
| Design 4th Level Program | 40 | 80 |
| Develop & Review 3rd & 4th Level Program | 80 | 200 |
| Refine Details | 20 | 5 |
| Final Test | 20 | 10 |
| Reporting | 40 | 70 |
| Summarizing | 30 | 10 |
| Total Time | 470 | 900 |
Problem is given in four level and that's good for Incremental model.
Idea of develop solution:
Solution steps:
My project used many to assist the development process. But those do nothing with problem-solving, so I will not explain them here.
Here is key codes and their explanation:
This is the entrance of whole program. This file contains and leads to the rest.
xxxxxxxxxx101# Open File Preparation2 f = None3 try:4 # get the file name5 fileName = sys.argv[1]6 except IndexError as ie:7 estr = OINFOHEADER + f'No file input, no first parameter given. {ie}'8 raise IndexError(estr)9 # get the program directory10 programDir = osp.dirname(sys.argv[0])xxxxxxxxxx41# Check ext2 fileExt: common.ExtClass = common.ExtClass()3 # determine ext4 fileExt.extSelect(fileName)xxxxxxxxxx61# open file2 try:3 f = open(fileName)4 except FileNotFoundError as fe:5 estr = OINFOHEADER + f'{fe}'6 raise FileNotFoundError(estr)xxxxxxxxxx101# read keywords2 keys = []3 try:4 with open(osp.join(programDir, f'keywords_{fileExt.ext}.txt')) as fkey:5 # with open(programDir + dirsep + f'keywords_{fileExt.ext}.txt') as fkey:6 t = fkey.read()7 keys = t.split()8 except FileNotFoundError as fe:9 estr = OINFOHEADER + f'{fe}'10 raise FileNotFoundError(estr)xxxxxxxxxx21# read file data2 strs = f.readlines()xxxxxxxxxx31# work of 1st level2 keycnt, moreinfo = common.countKw(keys, strs)3 print('total num: ', keycnt)xxxxxxxxxx61# language-specific part of solution's entrance (of .c file)2 speMDic = {3 'c': specific_c,4 'cpp': specific_cpp5 }6 speMDic[fileExt.ext].entrance(keys, strs, moreinfo)This file contains the common parts of codes, i.e. the public codes for all modules.
xxxxxxxxxx201# Class and method for storing and determining ext2class ExtClass():34 ext = None5 exti = 06 mode: DevMode = sampleModeCommon78 def __init__(self, mode: DevMode=None):9 ...1011 def extSelect(self, fileName:str=''):12 # debug code13 ...14 15 # set ext16 t1 = fileName.rsplit(sep='.', maxsplit=3)17 self.ext = t1[-1]1819 ...20xxxxxxxxxx251# This function count keywords in strings from the file.2def countKw(keys, strs:list):3 ...4 5 for i in strs:6 cnt1 = 07 for j in keys:8 i: str9 a = k = 010 while True:11 a = i.find(j,a)12 if a == -1:13 break14 a += keylength[j]15 if i[a].isalpha() is False:16 # found a keyword here17 k += 118 # pairs of location prepared for more operation19 p = [idi, a - keylength[j], j]20 locations.append(p)21 cnt1 += k2223 cnt2 += cnt124 idi += 125 return cnt2, locationsContains part of solutions for c language.
xxxxxxxxxx271# addon entrance2def entrance(pkeys, pstrs, pmoreinfo=None):3 ...4 5 locations = extractWordsBraces(strs, wordLocation)6 7 # process switch-case8 locations_SwCsBraces = extractSwCsBraces(locations)9 SwCnt_Group = countSwCs(locations_SwCsBraces)1011 # output SwCs12 print(f'switch num: ', SwCnt_Group.__len__())13 print('case num: ', end='')14 for i in SwCnt_Group:15 print(i, end=' ')16 print('')17 18 # process if-else, if-elseif-else19 # these codes are only designed for cases with entire braces attached to keywords.20 locations_IfEsBraces = extractIfEsBraces(locations)21 cnt_IfEs, cnt_IfEsifEs = countIfEs(locations_IfEsBraces)22 cntIFES = [cnt_IfEs, cnt_IfEsifEs]2324 # output IFES25 print(f'if-else num: ', cnt_IfEs)26 print(f'if-elseif-else num: ', cnt_IfEsifEs)27xxxxxxxxxx321# This function count 'switch's and each group's 'case's. Support nested structure.2def countSwCs(plocations_SwCsBraces):3 ...45 i = 06 while i < length:7 # find a 'switch', do iteration8 if plocations_SwCsBraces[i][2]=='switch':9 ...10 interval = [i, endBrace+1]11 intervals.append(interval)12 # iterate13 CsCntItr = countSwCs(plocations_SwCsBraces[i+1:endBrace+1])14 SwCnt_Group.extend(CsCntItr)15 # print(SwCnt_Group)16 i = endBrace17 i += 11819 ...20 21 # count 'case's of given strings22 i = 023 while i < length:24 ...25 26 if plocations_SwCsBraces[i][2]=='case':27 CsCnt += 128 i += 129 if CsCnt!=0:30 SwCnt_Group.append(CsCnt)31 return SwCnt_Group32xxxxxxxxxx361# This function figures the answers of sol.3. Support nested structure.2def countIfEs(plocations_IfEsBraces):3 ...4 while i < length:5 # find a/an 'if'/'else', do iteration6 if plocations_IfEsBraces[i][2] == 'if' or \7 (plocations_IfEsBraces[i][2] == 'else' and plocations_IfEsBraces[i+1 if i+1 <length else i][2] != 'if'):8 ...9 interval = [i + 2, endBrace]10 intervals.append(interval)11 # iterate12 retv = countIfEs(plocations_IfEsBraces[i + 1:endBrace + 1])13 ...14 cnt_IfEs += retv[0]15 cnt_IfEsifEs += retv[1]16 i = endBrace17 i += 11819 ...20 21 # count cases of 'if-else' and 'if-elseif-else' of given strings22 i = 023 tlength = tpifesloclist.__len__()24 while i < tlength:25 if tpifesloclist[i][2] == 'else':26 if tpifesloclist[i+1 if i+1<tlength else i][2] == 'if':27 cnt_IfEsifEs += 128 while i < tlength:29 if tpifesloclist[i][2] == 'else' and tpifesloclist[i+1 if i+1<tlength else i][2] != 'if':30 break31 i += 132 elif tpifesloclist[i+1 if i+1<tlength else i][2] == '{':33 cnt_IfEs += 134 i += 135 cntIFES = [cnt_IfEs, cnt_IfEsifEs]36 return cntIFESmy_unit_test.py
Test file, , is copied from website. See the website at the End.
Picture shown below tells that of 4th level, i.e. the ultimate requirement. It goes to expectation.


Comment useless codes.

% ->%

In this program, I used lots of new knowledge. Software Engineering is truly a systematic engineering. Methodology is really important.
| The Link Your Class | https://bbs.csdn.net/forums/MUEE308FZU202201 |
|---|---|
| The Link of Requirement of This Assignment | https://bbs.csdn.net/topics/608734907 |
| The Aim of This Assignment | Note the development processes. |
| MU STU ID and FZU STU ID | 20123850_832001217 |
Project on Github.com: https://github.com/LiuJiewenTT/ee308fz_lab1
URL on github.com of this passage(download): https://liujiewentt.github.io/ee308fz_lab1/development%20blog.md
URL on github.com of this passage(view with Github md): https://github.com/LiuJiewenTT/ee308fz_lab1/tree/main/development%20blog.md
URL on github.com of this passage(view as html): https://liujiewentt.github.io/ee308fz_lab1/development%20blog.html
URL on csdn.net of this passage(view as html): https://bbs.csdn.net/topics/608838406