Coppin State College s1

Total Page:16

File Type:pdf, Size:1020Kb

Coppin State College s1

Coppin State College COSC 199 – Fall 2005 Programming Assignment 3 Due Date: Thursday. October 27, 2005 (55 points)

Student’s Name: ______NOTE: (1pt) Staple this instruction page as a cover page to your submitted assignment. Your assignment will be graded based on style and correctness of your program. Penalty for not submitting in due date: Each class-day late – 10% you will receive zero; if I post the solution. Follow the class examples to write the following programs.

Example Program: Write a C++ program in ISO/ANSI 1998 standard (New) to convert Celsius temperature to its Fahrenheit equivalent. /* Description: This program will convert Celsius temperature to its Fahrenheit equivalent. 9 Fahrenheit = --- Celsius + 32 5 - Use standard input and output - Use New C++ Standard (ISO/ANSI 1998) Programmer: Sisir Ray Program Name: CelsiusToFahrenheit.cpp Course Name: COSC 199 002 Start date: Completion date: */

// preprocessor directives #include using namespace std;

// main function starts int main() { // Declaration Statements float celsius, fahrenheit;

// Input Statements: get the data from input file: add.dat cout << "Please enter temperature in Celsius: "; cin >> celsius;

// Process Statement fahrenheit = 9.0/5.0 * celsius + 32.0; // Output Statements cout << endl; // this will provide a blank line between input and output cout << "Temperature in Celsius = " << celsius << endl; cout << "Equivalent temperature in Fahrenheit = " << fahrenheit<< endl;

// Terminate the main function and the program return 0; }

/* OUTPUT Please enter temperature in Celsius: 100.0

Temperature in Celsius = 100 Equivalent temperature in Fahrenheit = 212

Please enter temperature in Celsius: 0

Temperature in Celsius = 0 Equivalent temperature in Fahrenheit = 32

*/

TASK 1 (5pts) Using the above program as an example, write a C++ program in ISO/ANSI 1998 standard (New) to convert Fahrenheit temperature to its Celsius equivalent. Modify the temperature converting equation appropriately. Declare all identifiers as floating point type. Use the name of the program: COSC199Prog3a.cpp. Test the program with following data: 32.0, 212.0, 0, and 90.5. Check manually (may use a calculator) for the correctness of your output. Preserve the programming writing style as shown in the example program.

TASK 2 (10pts) Write a C++ program in ISO/ANSI 1998 standard (New) to compute the two roots of the quadratic equation: ax2 + bx + c = 0. The formula of computing two roots is

-b ± √ (b2 - 4ac) ------2a

Declare all identifiers as floating point type. Use the C++ function sqrt(x) to solve the radical part of the equation. Use the name of the program: COSC199Prog3b.cpp. Test the program for the quadratic equation: 3x2 + 6x - 9 = 0. Check manually (may use a calculator) for the correctness of your output. Preserve the programming writing style as shown in the example program. . Tasks 3 (10pts) Write a C++ program in ISO/ANSI 1998 standard (New) to compute the following algebraic expression:

zn ------w + z

Declare all identifiers as floating point type. Use the C++ function pow(x, n) to solve the exponent part of the equation. Use the name of the program: COSC199Prog3c.cpp. Test the program with w = 6.0, z = 3.0, n = 5. Check manually (may use a calculator) for the correctness of your output. Preserve the programming writing style as shown in the example program.

TASK 4 (10 pts) Write the expressions and equations of the Programming Warm-Up Exercises 3 and 4, p.136. Write a C++ program to solve your obtained equations in (i) total pennies and (ii) total dollars for the given Problems 3 and 4. Test your results with following data: dollars = 5, quarters = 18, dimes = 21, nickels = 9, pennies = 11. Use the name of the program: COSC199Prog3d.cpp

TASK 5 (5pts) Complete the Programming Problem 1, p.137. Use the name of the program: COSC199Prog3e.cpp. Preserve the programming writing style as shown in the example program.

TASK 6 (10 pts) Write the expressions and equations of the Programming Warm-Up Exercises 2(a) & 2(b), p.136. Complete the C++ Programming for the Problem 2 in one single program. Test your results with following data: (a) days = 23, (b) days = 365. Use the name of the program: COSC199Prog3f.cpp. Preserve the programming writing style as shown in the example program.

REQUIREMENTS: 1. (2pts) Your source code for each task should clearly indicate the preprocessor directives, local declarations, inputs, processes, and outputs, if there be any. 2. (2pts) After you compile and run successfully your programs from C: drive, save all the .cpp files with their outputs in a folder, COSC199 Programming Assignment 3 in a floppy disk. Submit the floppy disk and hardcopies of all the programs.

NOTE: General Format of your Submitted program listing and output: /* Standard information */

The Source Code with proper styles and comments (your .cpp program)

/* Results: Paste your output here */

Recommended publications