Course Home | Class Schedule | Assignments | Git Submission | Perusall | Python | Tutoring

Saint Louis University

Computer Science 1300/5001
Introduction to Object-Oriented Programming

Michael Goldwasser

Fall 2018

Computer Science Department

Homework Assignment 12

Error Checking and Exceptions

Overview

Topic: Error Checking and Exceptions
Related Reading: Chapter 13
Due: 10:00am, Tuesday 16 October 2018

Please make sure you adhere to the policies on academic integrity.


Problems to be Submitted (20 points)

  1. (10 points)

    Write a program that asks a user for a weight in pounds (possibly fractional), and outputs the weight in kilograms. (For the record, 1 pound equals approximately 0.45359 kilograms.)

    Your program should ensure that the user correctly entered a nonnegative numeric value as input. As sample session might appear as follows

    Enter a weight in pounds: no
    That is not a valid number.	
    Enter a weight in pounds: -5.3
    Weights must be nonnegative.
    Enter a weight in pounds: 2.5
    That is equal to 1.13398 kilograms.	
    

  2. (10 points)

    Assume that we are writing a function doSomething(word, k) which expects that parameter word is a nonempty string, and that parameter k is a nonnegative intger that has value no greater than the length of the given word.

    Give an implementation of such a function that rigorously checks that the parameters adhere to these expectations. (Once you've performed the parameter-checking, you don't need to do anything within the function body.)


Michael Goldwasser
CSCI 1300/5001, Fall 2018
Last modified: Sunday, 14 October 2018
Course Home | Class Schedule | Assignments | Git Submission | Perusall | Python | Tutoring