CSCI 201 Fall 2000: Assignment 2

Program 1: Work assignment number 4.5 on page 149 of the text

Write a program called numtoeng.cpp to perform the task described in problem 4.5. The output of the program could look similar to the example below.


   Enter an integer number that is less than 1 million:

   1153

   the digits are: one one five three

Alternatively, the output could look like:


   Enter an integer number that is less than 1 million:

   1153

   the number is: three times ten raised to the zero power plus 
   five times ten raised to the first power plus
   one times ten raised to the second power plus
   one times ten raised to the third power

Other variations are acceptable as well.

The program numtoeng.cpp must be turned in by transferring it to your ftp directory for this class. Only the source code file should be turned in and it must be named numtoeng.cpp.


Hint: Read chapter 4 to find a program similar to the one assigned here.

Program 2: Work assignment number 4.6 on page 149 of the text

Write a program called printRoots.cpp to calculate the roots of a quadratic equation; the program should prompt the user to enter the coefficients and then display the roots as demonstrated below.


   Enter the coefficients of the quadratic equation that you want to
   solve:

   1 -5 6

   The roots of equation: 1*x^2 + -5*x + 6 are: 2.0 and 3.0
(Note that this is slightly different from the problem in the text which says that you should only write a function called printRoots.cpp.) The program printRoots.cpp must be turned in by transferring it to your ftp directory for this class. Only the source code file should be turned in and it must be named printRoots.cpp.


Hint: The roots of a quadratic equation are given by the following expression:
(-b + or - sqrt(b 2 -4ac)) / 2a
Where: a is the coefficient of x 2 , b is the coefficient of x, and c is the constant term.

Programming Style

Note that 10% of your program grade is based on the readability of your program. This includes things like style, comments, and the naming of variables and functions. Make sure you include a comment at the top of each program with your name, course and purpose of the program specified.

// Name: YOUR NAME HERE // // Course: CSCI 201 // // Purpose: purpose of program here //

Submitting Programs

As stated above, the programs written for this assignment must be turned in by transferring the C++ source code files to your ftp directory for this class. Only the source code files (i.e., numtoeng.cpp and printRoots.cpp) should be turned in. You were shown how to transfer files to your class ftp directory in lab01, here is a quick repeat.