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

Info icon This 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"); }
Image of page 1

Info icon This 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");
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 ]}

What students are saying

  • Left Quote Icon

    As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

    Student Picture

    Kiran Temple University Fox School of Business ‘17, Course Hero Intern

  • Left Quote Icon

    I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

    Student Picture

    Dana University of Pennsylvania ‘17, Course Hero Intern

  • Left Quote Icon

    The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

    Student Picture

    Jill Tulane University ‘16, Course Hero Intern