logo - 刷刷题
下载APP
【简答题】

已知检查括号匹配及注释、字符串处理的C源程序如下:
#include<stdio.h>

int brace,brack,paren;

void in_quote(int c);
void in_comment(void);
void search(int c);

/*rudimentary syntax checKer for C program*/
int main()

int c;
extern int brace,brack,paren;
while((c=getchar())!=EOF)
if(c==’/’)
if((c=getchar())==’*’)
in_comment(); /*inside comment*/
else
search(C) ;
else if(c==’\"||c=="")
in_quote(c); /*inside quote*/
else
search(c);
if(brace<0) /*output errors*/
printf("Unbalanced braces\n");
brace=0;
else if(brack<0)
printf("Unbalanced brackets\n");
brack=0;
else if(paren<0)
printf("Unbalanced parentheses\n");
paren=0;


if(brace>0) /*output errors*/
printf("Unbalanced braces\n");
if(brack>0)
printf("Unbalanced brackets\n");
if(paren>0)
printf("Unbalanced parentheses\n");
return 0;

/*search:search for rudimentary syntax errors*/
void search(int c)

extern int brace,brack,paren;
if(c==’’)
++brace;
else if(c==’’)
--brace;
else if(c==’[’)
++brack;
else if(c==’]’)
--brack;
else if(c==’(’)
++paren;
else if(c==’)’)
--paren;

/*in_comment:inside of a valid comment*/
void in_comment(void)

int c,d;
c=getchar();
d=getchar(); /*curr character*/
while(c!=’*’||d!=’/’) /*search for end*/
c=d;
d=getchar();


/*in_quote:inside quote*/
void in_quote(int c)

int d;
while((d=getchar())! =c) /*search end quote*/
if(d==’\\’)
getchar(); /*ignore escape seq*/

设计一组测试用例,使该程序所有函数的语句覆盖率和分支覆盖率均能达到100%。如果认为该程序的语句覆盖率或分支覆盖率无法达到100%,需说明为什么。

已知检查括号匹配及注释、字符串处理的C源程序如下:
#include<stdio.h>

int brace,brack,paren;

void in_quote(int c);
void in_comment(void);
void search(int c);

/*rudimentary syntax checKer for C program*/
int main()

int c;
extern int brace,brack,paren;
while((c=getchar())!=EOF)
if(c==’/’)
if((c=getchar())==’*’)
in_comment(); /*inside comment*/
else
search(C) ;
else if(c==’\"||c=="")
in_quote(c); /*inside quote*/
else
search(c);
if(brace<0) /*output errors*/
printf("Unbalanced braces\n");
brace=0;
else if(brack<0)
printf("Unbalanced brackets\n");
brack=0;
else if(paren<0)
printf("Unbalanced parentheses\n");
paren=0;


if(brace>0) /*output errors*/
printf("Unbalanced braces\n");
if(brack>0)
printf("Unbalanced brackets\n");
if(paren>0)
printf("Unbalanced parentheses\n");
return 0;

/*search:search for rudimentary syntax errors*/
void search(int c)

extern int brace,brack,paren;
if(c==’’)
++brace;
else if(c==’’)
--brace;
else if(c==’[’)
++brack;
else if(c==’]’)
--brack;
else if(c==’(’)
++paren;
else if(c==’)’)
--paren;

/*in_comment:inside of a valid comment*/
void in_comment(void)

int c,d;
c=getchar();
d=getchar(); /*curr character*/
while(c!=’*’||d!=’/’) /*search for end*/
c=d;
d=getchar();


/*in_quote:inside quote*/
void in_quote(int c)

int d;
while((d=getchar())! =c) /*search end quote*/
if(d==’\\’)
getchar(); /*ignore escape seq*/

举报
参考答案:
参考解析:
.
刷刷题刷刷变学霸
举一反三