Assignment #2 - Using Selection Statements

Due: Mon, Oct 2

Objective

This assignment will consist of writing two small programs, which will give practice with basic selection statements, as well as further practice with basic I/O.

Task

Write the following programs, each in a separate file. Filenames should be: (Note that the filenames are all lowercase)

Exercise 1

Write a program (filename sort.cpp) that does the following:

Prompt the user and let them enter three integers. Store them in three variables. Print the numbers in sorted order, from smallest to largest.

Sample run: (user input underlined)

  Input integer 1 : 34
  Input integer 2 : 200
  Input integer 3 : -14

  Sorted : -14 <= 34 <= 200

Exercise 2

Filename: wave.cpp

This is based on a Programming Challenge in your textbook. This table shows the approximate speed of sound in air, water, and steel.
MediumSpeed
Air1,100 feet per second
Water4,900 feet per second
Steel16,400 feet per second

Write a program that does the following:

Sample Runs

(user input is underlined, to distinguish it from output)

Sample run 1

Welcome to Sound Wave Calculator

Select the medium the sound wave will travel through.
        A       Air
        W       Water
        S       Steel

> A
How far will the sound wave travel (in feet)? 3500      
The sound wave will travel 3.1818 seconds
Goodbye

Sample run 2

Welcome to Sound Wave Calculator

Select the medium the sound wave will travel through.
        A       Air
        W       Water
        S       Steel

> w
How far will the sound wave travel (in feet)? 3500
The sound wave will travel 0.7143 seconds
Goodbye

Sample run 3

Welcome to Sound Wave Calculator

Select the medium the sound wave will travel through.
        A       Air
        W       Water
        S       Steel

> s
How far will the sound wave travel (in feet)? 98765
The sound wave will travel 6.0223 seconds
Goodbye

Sample run 4

Welcome to Sound Wave Calculator

Select the medium the sound wave will travel through.
        A       Air
        W       Water
        S       Steel

> z
Illegal entry. Aborting program.
Goodbye

Sample run 5

Welcome to Sound Wave Calculator

Select the medium the sound wave will travel through.
        A       Air
        W       Water
        S       Steel

> S
How far will the sound wave travel (in feet)? -10
Distance cannot be negative.  Aborting program.
Goodbye

Requirements for both programs


Submitting:

Submit only your source code files with the submission command below. As there are two of them, this will require doing the command twice, once for each of your files.

Format:

  ~myers/csub/submit2 yourfilenamehere.cpp

For example:

  ~myers/csub/submit2 sort.cpp
Do this for both files (sort.cpp and wave.cpp), substituting the appropriate filename each time. Remember to do this command from your CS acocunt from the same location as your code files.