Assignment #2 - Using Selection Statements

Due: Tues, Sept 27

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 Programming Challenge 18 in chapter 4 of 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 through the web submission page. As there are two of them, this will require filling out the submission page twice. Make sure to click on "Assigment 2" both times. Submit the files:
  sort.cpp  
  wave.cpp