Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

CS 002 - Assignment 3: Mathematics Specification Collaboration Policy We encourage collaboration on various activities such as lab, codelab, and textbook exercises. However, no collaboration

CS 002 - Assignment 3: Mathematics Specification

Collaboration Policy

We encourage collaboration on various activities such as lab, codelab, and textbook exercises. However, no collaboration between students is allowed on the programming assignments.

Assignment Specifications

Math is used everywhere! However, complex problems can require significant computation. With this in mind we often utilize calculators or computers to help us.

a program that will implement several mathematical operations (we provide a list), ranging from simple mathematics to geometric equations. To allow us to have a single program that may execute a different operation with each run, we utilize branching if-statements. We will also need to include the cmath library in the same area as our other library includes:

#include .

We highly recommend you develop this program in steps, testing it and attempting to get useful feedback as you implement your solution.

Acquiring Input

  1. The first thing the user will enter is the operation she wishes to perform: user entry will be the lowercase name from the list of operations.
  2. After you know the operation, you must acquire the numerical values for the computation. Since we are implementing several operations you will have to get between one and three numbers. All numerical inputs should be capable of storing floating point values.
  3. Your program may have no more than 4 input statements (in other words, no more than 4 cin statements), so plan and organize your code accordingly (i.e. your input statements for all the operations have to be grouped together).

IF YOU HAVE MORE THAN 4 CIN STATEMENTS YOU WILL RECEIVE A 0 ON THE ASSIGNMENT.

LANGUAGE: C++

Program Output

The output will change based on the mathematical operation that is performed but it can be broken down into three categories: Equation, Result and Error. These categories should be the first thing output on the line, followed by the output for the operation.

  • You will always output an Equation - we provide examples for the non-obvious operations.
  • In your equation, your operands and operators should all have spaces around them.
  • You will never output both a Result and an Error - it will always be one or the other.
  • We provide a list of errors, to be used as appropriate:
  • Use the exact text we give you.
  • You may utilize the same error in more than one operation.
  • An operation may have more than one error.

Mathematical Operations

  • addition
  • subtraction
  • division
  • multiplication

  • fabs (floating point absolute value)
  • sqrt (square root)
  • quadratic (Quadratic Equation)
  • pythagorean (Pythagorean Theorem; result is the hypotenuse, traditionally labelled c)

List of Errors

  • Cannot divide by zero.
  • Cannot take square root of a negative number.
  • Operation not supported.

Equation Examples for non-Obvious Operations

  • fabs(-3.141)
  • sqrt(4.14)
  • sqrt(3^2 + 4^2)

Example Runs (User input has been bolded and underlined for emphasis.)

Example 1

Please choose an operation: quadratic

Enter your first number: 1

Enter your second number: 0

Enter your third number: -4.84

Equation: 1x^2 + 0x + -4.84 = 0

Result: -2.2, 2.2

Example 2

Please choose an operation: division

Enter your first number: 1.5

Enter your second number: 0

Equation: 1.5 / 0

Error: Cannot divide by zero.

Example 3

Please choose an operation: addition

Enter your first number: 3

Enter your second number: 6

Equation: 3 + 6

Result: 9

Example 4

Please choose an operation: sqrt

Enter your first number: -2

Equation: sqrt(-2)

Error: Cannot take square root of a negative number.

Example 5

Please choose an operation: sqrt

Enter your first number: 6

Equation: sqrt(6)

Result: 2.44949

Example 6

Please choose an operation: pythagorean

Enter your first number: 3

Enter your second number: 4

Equation: sqrt(3^2 + 4^2)

Result: 5

Example 7

Please choose an operation: modulo

Error: Operation not supported.

Example 8

Please choose an operation: quadratic

Enter your first number: 1

Enter your second number: 1

Enter your third number: 1

Equation: 1x^2 + 1x + 1 = 0

Error: Cannot take square root of a negative number.

Example 9

Please choose an operation: fabs

Enter your first number: -5

Equation: fabs(-5)

Result: 5

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Introduction to Wireless and Mobile Systems

Authors: Dharma P. Agrawal, Qing An Zeng

4th edition

1305087135, 978-1305087132, 9781305259621, 1305259629, 9781305537910 , 978-130508713

More Books

Students also viewed these Programming questions