主观

说明输入串(a,a)#是否为G的句子。

参考答案
您可能感兴趣的试题

阅读下列程序说明和C++代码,将应填入(n)处的字句写在对应栏内。

 [说明]

 ①定义私有数据成员code、english分别用于表示考生的编号、英语成绩,它们都是int型的数据。

 ②完成成员函数void Student::inputinformation()的定义,该函数用于用户输入一个考生对象的信息,输入格式如下:

 输入编号:

 英语成绩:

 计算机成绩:

 ③利用已实现的类Student的成员函数,完成函数void firstname(Student *A[],int uum)的定义,该函数根据考生信息A[],输出num个考生中总分最高者的编号及其相应的总分,在此不考虑总分相同的情况。

 源程序文件test1.cpp清单如下:

     #include < iostream. h >

     class Student

     (1) 

      int computer;

      int total;

      public

      void getinformation( );

      void computesum( );

      int getcode( );

      int gettotalscore( );

      ~Student( );

     };

     void Student: :getinformation( )

     {

     (2) 

      cout <<"英语成绩:";

      cin> >english;

      cout <<"计算机成绩:";

      cin > > computer;

     void Student:: computesum ( )

      total = english + computer;

      cout <<"编号" << code <<"总分:" <<total << endl;

     int Student::getcode( )

      return code;

  }

  int Student:: gettotalscore ( )

  {

   return total;

  }

  void firstname(Student * A[] ,int num)

  {

   (3) 

   tempsum = ( * A[0] ). gettotalscore( );

   for( int i=1; i <num; i++)

   {

    if ( ( ( * A[i] ). gettotalscore( ) ) > tempsum)

    {

       tempcode = ( * A[i] ). getcode( );

       tempsum = ( * A[i] ). gettotalscore( );

     }

    }

    cout <<"总分最高者--" << tempcode <<":" << tempsum <<endl;

  } 

  void main( )

  {

   Student * A[3];

   int i,n =3

   for(i=0;i<n;i ++)

    A[i] = new Student;

    A[i] -> getinformation( )

   for(i=0;i<n;i ++)

  {

    A[i] -> computesum( )

   firstname ( A,3 );

 }

阅读下列程序说明和C代码,将应填人(n)处的字句写在对应栏内。

 [程序5说明]

 下列文法可用来描述化学分子式的书写规则(例如,A12(CO3)3”Cu(OH)2):

 λ→β\βλ

 β→δ\δn

 δ→ξ\ξθ\(λ)

 其中:λ是—个分子式;δ或是一个元素,或是一个带括号的(子)分子式,元素或是一个大写字母(记为ξ),或是一个大写字母和一个小写字母(记为ξθ)β或是一个δ,或是在δ之后接上一个整数n,δn表示β有n个δ的元素或(子)分子式。—个完整的分子式由若干个β组成。

 当然一个正确的分子式除符合上述文法规则外,还应满足分子式本身的语义要求。

 下面的程序输入分子式,按上述文法分析分子式,并计算出该分子式的分子量。例如:元素H的原子量是1,元素O的原子量是16。输入分子式H2O,程序计算出它的分子量为18 (1×2+16)。程序中各元素的名及它的原子量从文件atom.dat中读入。

 [程序5]

  #include < stdio. h >

  #include < string. h >

  #define MAXN 300

  #define GMLEN 30

  struct elem { char name[ ]; /* 元素名*/

         double v;/*原子量*/

         } nTbl [MAXN];

  char cmStr [GMLEN], * pos;

  int c;FILE * fp;

  double factor( );

  double atom( ) /* 处理文法符号δ*/

  {char w [3];int i; double num;

   while((c = * pos++) =='||c =='\t'); /*略过空白字符*/

   if(c == '\n') return 0.0;

   if(c>='A' && C <='Z') {/*将元素名存入W */

   w[i =0]=c;c= * pos ++

   if(c >='a'&& c <='z')w[ ++i] =c;else pos--;

   w[ ++i] ='\0',

   for(i =0;nTbl [i]. v >0.0;i ++)

     if(strcmp (w,nTbl[i]. name) ==0) return nTbl [i]. v;

   printf (" \n元素表中没有所输入的无素: \t%s\n',w); retur n - 1.0;

   } elseif (c = ='(') {

   if((num=(1)) <0.0)return -l.0; /*包括可能为空的情况*/

  if( * pos ++ ! = ')') { printf (" 分子式中括号不匹配!/n") ;return - 1.0; }

  return num;

  }

 printf ("分子式中存在非法字符:\t%c\n" ,c);

 return - 1.0;

 }

 double mAtom( ) /* 处理文法符号β*/

 { double num ;int n = ];

 if((num=(2)) <0.0)return-l.0;

 c= *pos++;

 if(c >='O'&&c <='9') {

  n = 0; while(c > = 0&&c < ='9')

        {n=(3);

         c= *poss ++;

        }

 }

 pos --;

 return num * n;

}

double factor( ) /*处理文法符号λ*/

{ double num =0.0,d;

 if(( hum = mAtom ( )) < 0.0) return - 1.0;

 while( * pos >= 'A'&& * pos <= 'Z'||* pos == '(') {

    if((d=(4)) <0.0)return-1.0;

    (5);

 } return num;

void main( )

{ char fname[ ] ="atom. dst"; /*元素名及其原子量文件*/

int i;double num;

if((fp=fopon(fname,"r" )) == NULL) { /*以读方式打开正文文件*/

prinff("Can net open%s file. \n' ,fname) ;return /*程序非正常结束 */

i=0;

while(i < MAXN&&fscanf (fp," %s%lf,bTbl[i]. name,&nTbl[i]. v) ==2)

 i++;

fclose(fp) ;nTbl[i]. v =-1.0;

while(1) [/*输入分子式和计算分子量循环,直至输入空行结束*/

 printf(" \n 输入分子式! (空行结束) \n" ) ;gets(cmStr);

 pos = cmStr;

 if(cmStr[0] == '\0') break;

 if( (num = later( ) ) > 0.0)

 if( * pos! = '\0')printf("分子式不完整! \n" );

  else printf("分子式的分子量为%f\n",num);

 }

¥

订单号:

遇到问题请联系在线客服

订单号:

遇到问题请联系在线客服