Question: (please i need help with this c programming project) Project Description: In this project, you will create and manage a set of vectors through dynamic

(please i need help with this c programming project)

Project Description:

In this project, you will create and manage a set of vectors through dynamic memory allocation. You are required to work on the project using incremental development approach and build your test suite concurrently. Dynamic memory allocation and de-allocation should be used appropriately for this assignment.

Your program will take a series of vector processing commands. You program will repeatedly displa y a prompt "calc>" and ask the user to enter a command.

Commands are grouped into two categories: vector assignments and vector operations:

Vector assignments command

Each vector assignment command starts with a single vector name (referred as vector register specifier s), an integer of the number of elements of the vector, and followed by each element. For example, the assignment for the vector A with 5 elements (3.2, 0, -2, 5.5, 1)

calc> A 5 3.2 0 -2 5.5 1 (required format to input your vector)

In this project we limit our inputs to no more than 4 vectors (A, B, C, D), but there is no limit of the number of elements of each vector.

Vector operations commands

Command

Description

Example

bye

exit the program

calc> bye

prn

print the vector

calc> prn s1

neg

negation

calc> neg s1

sum

sum of all the elements

calc> sum s1

rms

root-mean-square

calc> rms s1

add

addition

calc> add s1 s2

sub

subtraction

calc> sub s1 s2

mul

multiplication

calc> mul s1 s2

div

division

calc> div s1 s2

Here s1 and s2 are vector register specifiers (A, B, C, or D). They can be the same or different.

Commands:

bye: The bye command simply terminates the calculator program.

pm: This command simply displays a vector in the following format (precision is 2).

Separate the elements by commas followed by single spaces. For example:

calc> prn A( 3 . 2 0 , 0 . 0 0 , - 2 . 0 0 , 5 . 5 0 , 1. 0 0 )

neg: If A= (A1,A2, A3, ..., An), then neg A gives (-A1, ..A.2, -A3, ..., -An). The original vector is unchanged. The result will be displayed in the same format as the pm command.

calc> neg A( - 3 . 2 0 , 0 . 0 0 , 2 . 0 0 , - 5 . 5 0 , - 1. 0 0 )

sum: sum A gives sum of all the elements of vector A

rms: rms A gives root-mean-square of the vector A.

add/sub /mul/divadd/sub /mul/div are two-argument commands. These binary vector operations will add, subtract, multiply, or divide two vectors element by element if two vectors have the same length. The program will display corresponding error messages if (1) the vector is not assigned before the operation; (2) the vector name is not valid; (3) The vectors have different lengths; (4) the second vector has any zero element when division. The result will be displayed in the same format as the pm command.

For example:

add A B = (A1+B1, A2+B2, A3+B3, ... , An+Bn)

subAB= ( A1-B1, A2-B2, A3-B3, ..., An-Bn)

mul AB= (A1B1, AiB 2, A3B3, ..., AnBn)

div AB= (Ai/B1, A2 /Ih , A3/B3, ..., An/Bn)

calc> A 5 3.2 0 -2 5.5 1

calc> B 5 3.587 10 2.8 -2.3 4

calc> add AB

( 6 . 7 9 , 10.00, 0.80, -5.50, 5.00)

calc> div BA

Error. Cannot divide by zero! calc> C 3 3 10 2

calc> sub AB

Error. Vectors have different lengths!

Error Checking:

Your program should check thoroughly for relevant errors. Upon encountering an error, the program should report an informative error message and handle the error accordingly (either recoverable or fatal). Here are some examples (but not limited to) that your program should detect:

Failure to allocate memory for a vector

Invalid command

Invalid vector length (cannot be negative or zero, but no maximum limit as memory permits)

Missing or invalid coefficients

A vector register specify is invalid (not A, B, C, or D)

A vector is not assigned yet before it is used in the operation

A number is divide by 0

Two vectors do not have same length in a binary vector operation

Think carefully about other relevant errors and implement code that detects, and reports such errors. In most cases , errors should be recoverable.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!