Develop a specification for two data types: a. [10 marks] A string of ASCII char
ID: 3915225 • Letter: D
Question
Develop a specification for two data types: a. [10 marks] A string of ASCII characters. b. [10 marks] A coordinate in 3-dimensional space (x.y,z) For each case, list data (properties) and operations (functions) that will be relevant to the data type. Separate those data and operations which define the data type from those which dont. E.g. For the Stack data type, it is defined by a sequence of data pushx)- add an item pop) remove an item in LIFO order; behaviour is undefined if stack empty isEmpty()-returns true iff stack contains 0 elements · Some of the extra data and operations might be the length of the stack (number of items) size) - returns current length top0 probe the topmost itemExplanation / Answer
Data Type:
String - Sequence of characters
properties (data part):
1.length of string
2.Array of chars
Operations
2.isEmpty() - checks if string is empty
3.Size() - returns length of the string
4.get(i) - accesses the element at ith index in string
5.set(i,val) - sets the value at the ith index in string
6.addlast(string a) - adds another string object to this string object at last
7.addFront(string a) - adds another string object to this string object at front
8.clone(string) - return a copy of the string object
9.compare(string s1, string s2) : compares string objects .return 1 if s1 > s2
0 if s1 == s2 , -1 if s1 < s2
10copy(string s1, string s2) - copies s1 to s2
11.Search(string s1, string s2) - returns true or false based on the presence of
s1 in s2
12.Upper() - converts all the characters to uppercase
13.lower() - converts all the characters to lowercase
14. getArray() - returns the array of characters
3D point
Properties (Data part):
x - X-coordinate
y - Y-coordinate
z - Z-coordinate
Operations:
1.getX() - returns the X-Coodinate
2.getY() - returns the Y-Coodinate
3.getZ() - returns the Z-Coodinate
4.setX(val) - sets val to the X-Coodinate
5.setY(val) - sets val to the Y-Coodinate
6.setZ(val) - sets val to the Z-Coodinate
7.Dist() - returns distance from the origin - sqrt(x^2 + y^2 + z^2)
8.Dist(3Dpoint p) - Distance from an other 3D point object sqrt((x-p.x)^2 + (y-p.y)^2 + (z-p.z)^2)
9.add(val) - Adds val to the respective co-ordinates the point (x+val,y+val,z+val)
10.mul(val) - Multiplies val to the respective co-ordinates the point (x*val,y*val,z*val)
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.