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

Info iconThis preview shows pages 1–2. 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 DocumentRight Arrow Icon
Image of page 2
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 03/09/2008 for the course CSE 109 taught by Professor Kay during the Spring '08 term at Lehigh University .

Page1 / 4

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

This preview shows document pages 1 - 2. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online