{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

c109sp02t - CSc 109 Test 1 Wednesday 24 April 2002 =...

Info iconThis preview shows pages 1–3. Sign up to view the full content.

View Full Document Right Arrow Icon
CSc 109 Test 1 Wednesday 24 April 2002 =============== SUGGESTED ANSWERS ================== 1. (25 pts) Given the syntax diagrams below (where [] stands for a box and () stands for a circle), write the declarations and definitions for the class Parse such that the program in main() displays "Success" if and only if a line of text entered from the console satisfies the diagram for A. I have started the answer. You can assume that the members I have declared have been defined. Your program should assume that no blanks or tabs are allowed. A B ----> (a) --->[B]----------------> ----------->(c)-->[B]-->(c)----- ^ | | | | | |----(d)----------------->| [B]<--(z)<- | | |----(e)----->[A]-----------> int main() {Parse p; p.par(); cout<<"Success\n"; } class Parse {public: Parse(); private: static void errCheck(bool b,char *mess);//if b display message and exit() char ch; // ..... your private and public declarations are below <<<<<<<<<<<<<< #include <fstream.h> #include <stdlib.h> |----(e)----- >[A]----------- class Parse {public: Parse(); private: static void errCheck(bool b,char *mess);//if b display message and exit() char ch; public: void par(); private: void A(); void B(); }; int main() {Parse p; p.par(); cout<<"Success\n"; cin.get(); cin.get(); } void Parse::par() {cin.get(ch); A(); cout<<"\nch == "<<ch<<endl; errCheck(ch!='\n',"eoln expected"); }
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
void Parse::A() {errCheck(ch!='a',"'a' expected"); cin.get(ch); B(); while(ch=='z') {cin.get(ch); B(); } } void Parse::B() {switch(ch) { case 'c': cin.get(ch); B(); errCheck(ch!='c',"'c' expected");
Background image of page 2
Image of page 3
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}