Course Home | Class Schedule | Moodle CMS | Git Submission | Perusall | Tutoring

Saint Louis University

Computer Science 1300/5001
Introduction to Object-Oriented Programming

Michael Goldwasser

Fall 2019

Computer Science Department

Homework Assignment 14

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


  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 2019
Last modified: Sunday, 22 December 2019
Course Home | Class Schedule | Moodle CMS | Git Submission | Perusall | Tutoring