CSCI 131 Techniques of Programming--Spring 2014

    Home | | Schedule | | Assignments | | Lectures | | Resources

    Solution to Lab 2

    Lab 2 Grade Sheet (25 points)

    Input/Output, Files, and the Emacs Editor

    (1 pt) Question 1 What does the command C-x C-s do in Emacs? Hint: Look around in the menus to find a command with this shortcut.

    C-x C-s saves the file, i.e. writes the current buffer back to its file.

    (1 pt) Question 2 How do you cancel a partially-typed command in Emacs? Hint: try Google!

    C-g is one option.

    (1 pt) Question 3 What is the preprocessor directive necessary to use the standard cmath library?

    #include <cmath>

    (1 pt) Question 4 Given the function prototype
    float ComputePrice(float itemprice, int count, float taxrate); What type of value (if any) does the ComputePrice function return as a result?

    It returns a float, i.e. a floating point value.

    (2 pt) Question 5 How many input parameters does the ComputePrice function require?

    It takes 3 parameters (they are named itemprice, count, and taxrate; two are floats, one is an int).

    (2 pt) Question 6 Write a line of code that computes the total price of four books, each of which costs $13.75, with a 6.25 percent tax rate, then prints the resulting value. Use the above function.

    cout << ComputePrice(13.75, 4, 6.25);

    (2 pt) Question 7 In which cases does the output of the modified program differ from that of the original program?

    The output is the same if the input is entered on a single line with no spaces. If there are any spaces, line breaks, tabs, or other whitespace, then the output is different.

    (3 pt) guess.cc - Fix all compile errors and indenting, add "cin>>guess" in correct place.

    (2 pt) functions.cc - Added sqrt( ) and pow( ) calls.

    (0 pt) letters.cc - Not graded.

    (4 pt) tuition.cc - Correct output; Uses setw, setprecision, left/right, and fixed correctly.

    (6 pt) king.cc -


    Home | | Schedule | | Assignments | | Lectures | | Resources



    CSCI 131: Techniques of Programming
    Last Modified: January 26, 2014
    Page Expires: September 1, 2014