CSCI 2421 homework 3
Program objectives
The objectives of this assignment are as follows.
An ability to analyze a problem, and identify and define the computing requirements appropriate to its solution (ABET b).
Point value
This program is worth 15 points. The distribution of points will be as follows.
Criterion |
Value |
Global functions |
1 |
Poly class |
5 |
Program style (see below) |
3 |
Correct output with annotation |
6 |
Background
A polynomial is a function of the following form:
d p(n) =∑a_{i}n^{i }, where d is an integer and the a_{i} are the coefficients with a_{d} ≠ 0.
i=0 p(n) is said to be a polynomial in n of degree d.
Problem
Create a class named polynomial that uses a dynamic array to perform the following arithmetic for polynomials, p_{1} and p_{2}.
- p_{1} + p_{2}
- p_{1} * p_{2}
- p_{1} (n), n ∈ Z
Input
- A text file consisting of two rows of space-delimited integers. Each row represents the coefficients, a_{i} for a polynomial p. The first number on each row represents a_{0} and the last number a_{d}. Notice that any a_{i} (except a_{d}) may be 0. No coefficient will be missing, even if it is 0. The name of the text file will be available in positional parameter, argv[1].
- A number, n ∈ Z input on the command line in positional parameter argv[2] that is used to evaluate polynomial p_{1}. For example, if p_{1} = (1, 0, 3, 0, 0) and n=2, then p_{1}(2) = 28. Notice that argv[2] is type char*, so it must be converted to type int by your program (a global function).
Class requirements
- Use a dynamic array to implement your polynomial.
- Define a constant member to evaluate a polynomial at a value n.
- Define a “setter” to set any coefficient requested.
- Define a “getter” to return any coefficient requested.
- Overload operators + and * for the polynomial class.
- Overload operator << for polynomial class.
- Operator << should display the polynomial as an n-tuple in the order highest term to lowest term. For example,
(3, -2, 0, 0, 7) ≡ 3x^{4} – 2x^{3} + 7
Driver
- Greet the user.
- Instantiate p_{1} and p_{2}.
- Read the text file and set the coefficients of p_{1} and p_{2}.
- Perform the polynomial arithmetic per the problem specification and display the annotated results.
- Convert argv[2] to an int, evaluate p_{1} at this value, and display the annotated result.
Notes
- Use an appropriate annotation with all output.
- Make sure that main is short. It should basically be making top-level function calls.
- Use good program style that includes, but is not limited to, header comments, pre and post conditions, macro guards, whitespace and indentation, self-documenting names, symbolic constants where appropriate (use all caps for the name of each symbolics), separation of interface and implementation, correctly submitted program file (tar archive), and a greeting to start the program.
- You are not restricted to the polynomial members listed above; that is, you may define other members that you feel necessary.
- Be sure to use error checking where appropriate.
Subjects List
Database (48)
Accounting (39)
Economics (34)
Finance (54)
Programming (122)
Management (69)
Marketing (25)
Report Writing (52)
Engineering (79)
Statistics (39)
Business Studies(45)
Case Studies (15)
Networking (26)
UML (9)
Science (23)
Nursing (11)
MATLAB (17)
Psychology (6)
Math (20)
Data Structure (9)
Python (15)
HRM (25)
IT (21)
Computer Science (57)
Law (4)
Essay (3)
Data Analysis (2)
Big Data (3)
Philosophy (2)
History (1)