DM560, Introduction to Programming in C++

Sheet 4

Task 1

Download the program calculator000.cpp that implements the calculator example from the text book.

Test it and determine if it works correctly. If it does not, understand what goes wrong. Repair it.

Task 2

Complete your program by:

  • checking input and output
  • adding error handling
  • handling of negative numbers
  • handling of modulo operator %
  • clean up the code by introducing constants and functions
  • check code layout (formatting)
  • add comments and release details

Task 3

Download the following extension of the calculator example debug it and correct it.

Task 4

Organize your code in header and source files and add:

  • a Makefile to automatize the building process.
  • a README file to explain how to build, install and run your program.
  • eventually a license file.

Then, make an archive of all your files:

tar czvf myprogram.tgz directory/ 

Exchange your calculator programs, test the code that you receive and report back bugs and misbehaviours. To uncompress the files that you receive execute:

tar xzvf myprogram.tgz

Task 5

Download the following extension of the calculator example debug it and correct it.

It implements the following abilities:

  • the ability to use {} beside () with the correct precedence between the two types of parenthesis. (Ex. 2 ch 6)

  • a factorial operator as a suffix !. (Ex. 3 ch 6)

  • the possibilty to define variables. For example:

    let v = 5;
    

Check how these are implemented. To handle key words like let you might need to add an higher level to your Grammar.