Spring Break - Programming Projects

 

Write your programs on a piece of paper or type it on the computer using a word processor. This does not have to be on cs.  It makes editing much easier if you type them, but it is not required from you to do so.  Also it makes easier to send them by e-mail to me once you are done, so I can check them for you. 

 

If you wish you can write all of them on cs.  If you decide to do so, under your 1440 directory, create a directory called projects and complete your work there. If you wish me to look at each program individually, send me an e-mail after you are done with a program, and I will send you my comments once I have gone through the program.  Note: you do not have to write, compile, and run the programs. They all can be written on paper.

 

Problem 1:

Write a complete program that asks users to input an integer then determines:

1)      Whether the number is ODD, or

2)      EVEN.

 

This program displays appropriate message on the screen.  Your program should use a function that takes an integer as its argument and returns a Boolean that indicates whether the argument was ODD (True) or Even (False).  You can then use the returned value to display appropriate messages.  Here is a possible declaration for this function:

 

bool  odd_or_even(int number);

 

Example:

Input:                23

Output:             23 is an ODD number

 

Problem 2:

Write a complete program that displays the factorial of an input integer.

 

Example:

Input:                5

Output: 5*4*3*2*1 = 120

 

This program uses two functions:

            1) void display_fact(int number)

This function will take the number and displays the sequence of values in the factorial with an “=” at the end0. For the above example this function will display:       5*4*3*2*1 =

2)      int find_fract(int number)

This function returns the factorial of the number. For the above example, the display is:   120

The output when put together will look like this: 5*4*3*2*1 = 120

Problem 3:

Write a program that reads pairs of integers from an input file (input) and write an output in the following format into a file (output).

 

first       second             first-second      first+second      first*second      first/second

= = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =

2          3                      -1                     5                      6                      0

 

Note that the division is an integer division.

 

We do not know how many values are in the input file. So, you need to read until there are no more pairs left in the input file.  

 

 

Problem 4:

Write a program that asks users to enter an arbitrary number of double values then determine the smallest and the largest. Let’s say suppose users entered n for number of values, then ask users to enter n values and determine the smallest and the largest of all values that are entered.

 

Example:

How many values are you entering: 4

Input: 2 4 1 8

Output: The smallest value was: 1 and The Largest value was: 8

 

Problem 5:

Write a program for Problem (11) at the end of Chapter 4.  Note that the number for Problem 12 did not appear in the first print of the 4th edition. So these two problems are connected. Problem 12 starts where it says “In cold weather, … Only solve problem 11.