联系方式

  • QQ:99515681
  • 邮箱:99515681@qq.com
  • 工作时间:8:00-23:00
  • 微信:codehelp

您当前位置:首页 >> Matlab程序Matlab程序

日期:2021-01-30 09:29

Programming Assignment 1:
Submission date: before 11:59 pm Jan 30, 2021.


The program assignment consists of two parts.
Part 1 (65 Marks):
The first part of the program reads an arithmetic operation when the user keys in one of the following forms:
a + b; a - b; a * b; a/b
where a and b can be either positive or negative integers. There may be spaces or no space between a and a valid arithmetic operation and also similarly between the valid arithmetic operation and b. Some valid examples are given below:
a + b, a + -b, a+ -b, a +-b, a+-b
-a + b, -a + -b, -a+ -b, -a +-b, -a+-b
a - b, a - -b, a- -b, a --b, a--b
-a - b, -a - -b, -a- -b, -a --b, -a--b
a * b, a * -b, a* -b, a *-b, a*-b
-a * b, -a * -b, -a* -b, -a *-b, -a*-b
a / b, a / -b, a/ -b, a /-b, a/-b
-a / b, -a / -b, -a/ -b, -a /-b, -a/-b

Your program should detect any non valid arithmetic operations by informing the user “it’s an invalid arithmetic operator” and prompting the user to retry. A maximum of three tries are given to the user and the program terminates when the user exceeds the number of tries.

In addition to the main class create two classes in this program: addSubtract and multiplyDivide.
In the main class, the program reads the user entry and first determines if the entry is valid. Next, it determines the integers a and b and also the sign of the operation. Based on the sign, they are then passed on to one of the classes.
In both addSubtract and multiplyDivide classes the arithmetic operations are carried out and also the result of the operation is printed.
In the multiplyDivide class, the output is in a Double format.

An important function in the developed program solution is testing. Your program should test for all possible valid data entries and invalid ones too. Some of the valid ones are given below
Replace a and b with any values not exceeding 1000.
a + b, a + -b, a+ -b, a +-b, a+-b
-a + b, -a + -b, -a+ -b, -a +-b, -a+-b
a - b, a - -b, a- -b, a --b, a--b
-a - b, -a - -b, -a- -b, -a --b, -a--b
a * b, a * -b, a* -b, a *-b, a*-b
-a * b, -a * -b, -a* -b, -a *-b, -a*-b
a / b, a / -b, a/ -b, a /-b, a/-b
-a / b, -a / -b, -a/ -b, -a /-b, -a/-b

In submitting your solution show proof, your program worked for all valid and invalid cases.
The grading will check for the correctness of the program (50 Marks) and testing with proof (15 marks).

Part 2 (35 Marks)

This program reads two valid arithmetic operations. Assume the arithmetic operation sign for the purposes of the description to be of & (+, -, *, /). They can be in the form of:
a & b & c. Some examples are
a + b + c,
a -b*c,
a/b*c,
a*-b /c
-a- -b*c
The classes and the rest of the description is exactly the same as in Part 1.

The following marks will be awarded for the correctness of the program (20 Marks) and testing with proof (15 marks).

You should submit the following files: Part 1, TestPart1, Part2 and. TestPart2.

Test Cases for Assignment 1

Valid Cases:
1) 823 + -145
2) -23 + -245
3) -23 *-45
4) -23 / -345
5) -23 --45
6)

Non Valid Cases
1) --23 + 45
2) -23 +* 45
3) -23 +/ 45
4) -23 -/ 45
5) -23 */ 45
6) --23 */-45
7) 23 ++45
8) 23 **5
9) 23 // 42



How about cases such as the following
10) 23 a-56
11) 23 + 67i
12) -j33 +98

Part 2.
Valid cases

1) 23+78-9
2) -23--56+9
3) 3 -8*4
4) 23/8*2
5) 934+-78*2

版权所有:留学生编程辅导网 2021,All Rights Reserved 联系方式:QQ:99515681 电子信箱:99515681@qq.com
免责声明:本站部分内容从网络整理而来,只供参考!如有版权问题可联系本站删除。