COP 3014 Fall 2018 Homework 4 Total Points 200 Due Friday 11

Cop 3014 Fall 2018 Homework 4total Points 200 Due Friday 1116201

The assignment involves working with C++ arrays, functions, loops, selection statements, and output formatting. You are required to develop three separate programs in a single submission, each demonstrating different skills related to arrays, mathematical functions, and matrix operations, along with potential extra credit. The core tasks include writing functions for mathematical calculations, array manipulations, and matrix norm calculations, with specific input/output and error handling requirements.

Paper For Above instruction

This assignment comprises three primary programming tasks using C++, focused on arrays, mathematical functions, and matrix operations. These tasks are designed to assess your understanding and ability to implement key programming concepts such as functions, loops, selection statements, and array manipulations, adhering strictly to output formatting and coding standards specified in the assignment.

Mathematical Functions and Array Operations Using C++

The first task involves writing functions related to mathematical calculations. The central concept is the "Special Difference," computed as the absolute difference between a number and its digit-reversal. For example, the special difference of 1234 is 3087. You will also implement a function to calculate the exponential constant e using Taylor's series expansion, and functions for factorial and summation of series terms. These functions will be used in a main program that interacts with the user to:

  • Read multiple numbers until a negative number is entered, summing their special differences.
  • Read values of x and n, then calculate e^x using the specified expansion up to n terms.
  • Display outputs formatted precisely as per samples, including summations and exponentiation results.

Your implementation should include detailed comments explaining your logic. The functions needed are:

  • difference: computes the special difference of an integer.
  • factorial: returns the factorial of an integer.
  • sum: computes e^x by summing the series up to n terms.

All computations should adhere to the mathematical definitions provided, with correct use of loops and conditionals for processing user inputs and calculations.

Sample output demonstrates user prompts and formatted display of sums and exponential calculations, emphasizing matching output precision and structure.

Array Operations Program

The second task requires managing an array with a maximum size of 100 elements. You will write functions to initialize the array with user input, print its contents, and perform insertions and deletions at specified positions. Core functionalities include:

  • Defining a global constant CAPACITY set to 100.
  • Implementing functions to initialize, print, insert, remove, and sort an array.
  • Using insertion sort to arrange array elements in ascending order.
  • Providing a command-line menu to perform these operations repeatedly until the user chooses to exit.

The menu options will allow users to print the array, insert or delete an element, sort the array, or exit. Proper input validation and message prompts are essential to ensure usability and correctness.

  • The array elements are stored in a global array, and the size is dynamically tracked.
  • Inserting involves shifting elements rightward; removing deletes the first occurrence of a specified value.
  • The sort function should employ the insertion sort algorithm provided in the instructions.

Matrix Max Norm Calculation

The third task involves calculating the maximum norm of a matrix, defined as the largest element in the matrix. You will:

  • Declare global constants ROWCAP and COLCAP, both set to 100.
  • Write functions to initialize the matrix with user input and print the matrix.
  • Implement a function findnorm that accepts the matrix and its dimensions, returning the maximum element.
  • The main program should input matrix dimensions and values, then compute and output the maximum norm.

Comments should be used extensively to explain your logic, and the code must conform to input/output specifications shown in samples, including prompts and display format.

Extra Credit: Simple Calculator

An optional extra involves creating a simple calculator using functions for basic arithmetic operations (+, -, *, /, %). The program should:

  • Use a single evaluate function that reads user input of numbers and operators until '=' is entered.
  • Invoke corresponding functions for each operation; functions take two integers and return an integer result.
  • The main function should simply call evaluate.
  • Assume valid inputs; ignore operator precedence; evaluate sequentially.

This task reinforces function writing, input parsing, and control flow, with a focus on adherence to input/output formats and code readability.

General Coding Guidelines

  • Include a header comment with your name and details at the top of each file.
  • Use only iostream, iomanip, and cmath libraries.
  • No C-style printing; use cout exclusively.
  • Format code with clear indentation, comments, and readability.
  • Develop and test with a recommended IDE (like CLion) before submission.
  • Submit only the source files: functions.cpp, arrays.cpp, matrix.cpp, and optionally evaluate.cpp for extra credit, collectively.
  • Ensure error-free compilation; errors reduce your grade significantly.

Adhering to these instructions ensures your submission meets the assignment’s standards for coding style, correctness, and completeness. Backup your files and verify compilation before submitting through Canvas.

References

  • Turner, I. (2019). C++ Programming: From Problem Analysis to Program Design (3rd ed.). Cengage Learning.
  • Stroustrup, B. (2013). The C++ Programming Language (4th ed.). Addison-Wesley.
  • Lippman, R. H., Lajoie, J., & Moo, B. E. (2012). C++ Primer (5th ed.). Addison-Wesley.
  • Prata, S. (2015). C++ Primer Plus (6th ed.). Addison-Wesley.
  • Harbison, S. P., & Steele, G. L. (2002). C++ Standard Library: A Tutorial and Reference. Addison-Wesley.
  • Deitel, P., & Deitel, H. (2017). C++ How To Program (10th ed.). Pearson.
  • Bjarne Stroustrup. (2018). Programming: Principles and Practice Using C++ (2nd ed.). Addison-Wesley.
  • Y. S. Rajpurohit. (2010). C++ Fundamentals. PHI Learning.
  • Gaddis, T. (2012). Starting Out with C++: From Control Structures through Data Structures (6th ed.). Pearson.
  • Cohoon, J. P., & Davidson, R. R. (2014). C++ Programming: From Problem Analysis to Program Design. Cengage Learning.