Programming Assignment #1: User Interface Module

 

Purpose

To implement an interpreter for our very simple BIOLA language, the very first module we want is a simple user interface module, which serves as a simple editor for editing programs written in the BIOLA language and later also serve as a front-end interface to submit the statements to a parser-evaluator module for execution. In this programming assignment, we would like to build the editor part of the module. (Later you’ll see it is easy to add additional things to make it works as a front end to the parser-evaluator module.)

 

Object-oriented programming

In CSCI 105 (Intro to Computer Science), we learned about the very basics of C++ programming starting from a procedure-oriented programming style. We wrote global functions, declared some global data structures shared by these functions, and primarily looked at program execution from the perspective of functions calling functions. A global function in its essence describes the procedure of doing some task according to some input arguments. In some programming languages like PASCAL, they actually use the term “procedure” to refer to the kind of global functions you write in C/C++. That is why this style is called procedure-oriented programming.

In CSCI 106 (Data Structures), we transitioned from the procedure-oriented programming style in csci105 to object-oriented programming using objects and classes. We’ll continue to use object-oriented programming style in this course. In object-oriented programming, we look at program execution from the perspective of objects interacting with objects by calling their member functions. We define classes and create objects of these classes to model real-world or conceptual objects. Data are stored as data members of the objects and the behavior of objects are specified by the member functions of their classes.

 

About the Interface class

To provide the functionality of the user interface, we need to implement an Interface class and an object of the Interface class must be able to read, store, and process the lines of statements written in the BIOLA language. The Interface class should implement member functions that can allow the user (as the sample interpreter in this zip file does) to

(1) read in a program as a bunch of lines of statements from a file specified by the user,

(2) display these lines of statements,

(3) append new lines of statements to the end repeatedly until a single period is entered to stop the insertion process,

(4) insert new lines before an existing line repeatedly until a single period is entered to stop the insertion process,

(5) delete a range of existing lines,

(6) replace the contents of an existing line with new things from user input, and

(7) save these lines of statements into a file specified by the use, and

(8) in addition, the Interface class should provide a startInterface member function to repeatedly display the main menu, read the user’s choice of options, and call other member functions to process the lines of statements stored in the vector of strings.

 

Using the STL vector class and the String Class for storing and processing lines of statements:

In this programming assignment, we need to use the C++ string class for processing strings (you’ll see the compiler directive #include <string> appears in the beginning of the source code). Each object of the Interface class has a vector of strings as its data member and stores the lines of statements in a Biola source program as a vector of strings. In other words, each line of statement in a Biola source program is stored as a string object in that vector of strings. This allows an object of Interface class to insert into or delete lines of statements from the vector very conveniently by appropriately calling the insert method and the erase method of the vector of strings.

 

What you should add into the skeleton framework to complete the programming assignment:

  1. Carefully study the source code files (the .h files and the .cpp files) in this skeleton sample framework (zipped) and play with the sample executable enclosed in the zipped file. A partial implementation of the Interface class is already provided in the skeleton sample framework while the sample executable is compiled from a fully implemented version to show you the functionalities we want from Interface class the in the end. You should fill in your own code in all the empty functions in interface.cpp of the skeleton sample framework to make the program run in a way compatible with the sample executable enclosed in the zipped file.
  2. You have to review and understand the use of iterators and member functions such as begin( ), end( ), push_back( ), pop_back( ), insert( ), erase( ), clear( ), size( ), empty() of the vector container in the C++ standard template library to complete this assignment smoothly. For this purpose, refresh your memory by reading the related sections in C++ Primer and the online MSDN document on the member functions of STL vector class: especially the descriptions and sample code there.
  3. Please download and unzip this getlineDemo.zip file to examine and run the demo code in the Visual C++ project about the usage of getline to read in strings possibly with white spaces in them. The demo code show you the following things: (i) You need to use getline(cin, myString) to read in a string including spaces from the input into a string object myString. (ii) Using cin >> myString does not work since it will break the string upon spaces (and other whitespace characters). (iii) In some context getline may read in empty lines unexpectedly. To void unexpected empty lines, you can check the string you got to make sure it is not an empty string. If it is, repeat the getline(cin, myString) until you get an non-empty string. The code segment may look like:

    getline(cin, myString);

while ( myString.empty( ) )

getline(cin, myString);

  1. Submission under Canvas: By the due date, compress and submit your Visual C++ 2103 programming project folder (with source .h & .cpp files in it) and the self-evaluation report of Programming #1 as a zip file under Canvas.

 

 

Self-Evaluation and Peer Review

The programming assignment will be graded in a 0-6 scale based on the following guidelines. You also need to fill out the self-evaluation report with peer review and proper description of test cases conducted to check your program. Up to 2 points will be deducted from your work if self-evaluation report is submitted without a peer review or proper description of your test cases. 

 

  1. Nothing done.
  2. Source code is completed but the code fails to compile successfully.
  3. Source code can compile and do something required, but has serious bugs or miss a couple of key features.
  4. Source code can compile and do most of the features required, but has many minor bugs or miss a key required feature.
  5. Source code can compile and do all the features required, nearly fully functional, only a couple of minor bugs.
  6. Source code can compile and do all the features required, fully functional, no bugs.
  7. In addition to the points received above, get one more point if the source code is well indented and commented to make it visually very readable.