COL100 I C & C S: Recap
COL100 I C & C S: Recap
Recap
• Last Class
– Polynomials
COL100 INTRODUCTION TO COMPUTING
Indian Ins(tute of Technology Delhi
• E.g., one char, one double, or one uint8 value components of data
• All components have the same type
• Cell array
– Each cell can store something “bigger” than one
scalar, e.g., a vector, a matrix, a char vector
– The cells may store items of different types
1
3/22/18
D{2} = ‘2 Hearts’;
C= cell(1,3); % not necessary :
C{1}= ‘Oct’; D{13} = ‘K Hearts’;
D{14} = ‘A Clubs’;
C{2}= 30; :
C{3}= ones(3,2); D{52} = ‘K Diamonds’;
You can assign the empty cell array: D = {}
• But this means that have to type all combina:ons
of suits and ranks in crea:ng the deck…
– How do we proceed?
2
3/22/18
n = length(S);
mid = n/2;
T = cell(1,n); Top=cell(1,mid); Bot= cell(1,mid);
• Cut the Deck % Cut the deck
for k= 1:mid
Top{k}= S{k};
Bot{k}= S{mid+k};
end
• Alternate
% Alternate
for k= 1:mid
T{2*k-1} = Top{k};
T{2*k} = Bot{k};
end
3
3/22/18
4
3/22/18
OOP Example
• Define the classes (of the objects) • class: Rectangle
– Iden:fy the proper:es (data) and • Proper:es:
Indian Ins(tute of Technology Delhi
– lek, right
• Ac:ons—methods—of an interval include
– Scale, i.e., expand
– Shik
– Add one interval to another
– Check if one interval is in another
– Check if one interval overlaps with another
• The source code must go inside a file with the
same name
5
3/22/18