21
General Computer Science General Computer Science for Engineers for Engineers CISC 106 CISC 106 Lecture 11 Lecture 11 James Atlas Computer and Information Sciences 07/27/2009

General Computer Science for Engineers CISC 106 Lecture 11 James Atlas Computer and Information Sciences 07/27/2009

Embed Size (px)

Citation preview

Page 1: General Computer Science for Engineers CISC 106 Lecture 11 James Atlas Computer and Information Sciences 07/27/2009

General Computer Science General Computer Science for Engineersfor Engineers

CISC 106CISC 106Lecture 11Lecture 11

James AtlasComputer and Information Sciences

07/27/2009

Page 2: General Computer Science for Engineers CISC 106 Lecture 11 James Atlas Computer and Information Sciences 07/27/2009

Lecture OverviewReview

◦ Structures in MATLABAdvanced MATLAB

◦ Classes isa function

◦ Cell ArraysGraphics

◦ Function callbacks (passing functions to functions)Project 2Lab 07Team evaluations for Project 1

Page 3: General Computer Science for Engineers CISC 106 Lecture 11 James Atlas Computer and Information Sciences 07/27/2009

Structures in MATLAB

Page 4: General Computer Science for Engineers CISC 106 Lecture 11 James Atlas Computer and Information Sciences 07/27/2009

A Database ApplicationGiven:

Name: ChrisCredits: 27Graduation: 12/15/2011

Name: SolaCredits: 18Graduation: 05/17/2011

Name: RogerCredits: 55Graduation: 06/10/2009

Name: TomCredits: 15Graduation: 05/22/2012

Page 5: General Computer Science for Engineers CISC 106 Lecture 11 James Atlas Computer and Information Sciences 07/27/2009

Given: We can implement it with arrays like this: Name Credits

Grad. 1 2 3 4

Name: ChrisCredits: 27Graduation: 12/15/2011

Name: SolaCredits: 18Graduation: 05/17/2011

Name: RogerCredits: 55Graduation: 06/10/2009

Name: TomCredits: 15Graduation: 05/22/2012

27Chris 12/15/2011

18Sola 05/17/2011

55Roger 06/10/2009

15Tom 05/22/2012

A Database Application

Page 6: General Computer Science for Engineers CISC 106 Lecture 11 James Atlas Computer and Information Sciences 07/27/2009

Given: OR we can do it like this an array with structs:

.d

Name: ChrisCredits: 27Graduation: 12/15/2011

Name: SolaCredits: 18Graduation: 05/17/2011

Name: RogerCredits: 55Graduation: 06/10/2009

Name: TomCredits: 15Graduation: 05/22/2012

Students (1). Name: ChrisStudents (1).Credits: 27Students (1). Graduation: 12/15/2011

Students (2).Name: SolaStudents (2).Credits: 18Students (2).Graduation: 05/17/2011

Students (3). Name: RogerStudents (3). Credits: 55Students (3). Graduation: 06/10/2009

Students (4). Name: TomStudents (4). Credits: 15Students (4). Graduation: 05/22/2012

A Database Application

Page 7: General Computer Science for Engineers CISC 106 Lecture 11 James Atlas Computer and Information Sciences 07/27/2009

record1.name = 'Me'; record2.name = 'Not Me';

record1.credits = 27; record2.credits = 30; record1.age = 10; record2.age = 14;

function [] = displayRecordName(record) disp(record.name);

displayRecordName(record1);displayRecordName(record2);

Initializing a structure

Page 8: General Computer Science for Engineers CISC 106 Lecture 11 James Atlas Computer and Information Sciences 07/27/2009

ClassesObject-oriented ProgrammingClasses represent types of

Objects

Similar to structs

Page 9: General Computer Science for Engineers CISC 106 Lecture 11 James Atlas Computer and Information Sciences 07/27/2009

Class definition

classdef dog properties name age endend

Page 10: General Computer Science for Engineers CISC 106 Lecture 11 James Atlas Computer and Information Sciences 07/27/2009

Class definition (cont’)classdef dog

properties

name

age

end

methods

function obj=dog(name, age)

obj.name = name;

obj.age = age;

end

end

end

Page 11: General Computer Science for Engineers CISC 106 Lecture 11 James Atlas Computer and Information Sciences 07/27/2009

The isa functionisa(object, ‘classname’)

isa(dog1, ‘dog’)

isa(dog1, ‘person’)

Page 12: General Computer Science for Engineers CISC 106 Lecture 11 James Atlas Computer and Information Sciences 07/27/2009

Arrays of classes?[dog1 dog2]

[dog1 dog2 person1] ?

Page 13: General Computer Science for Engineers CISC 106 Lecture 11 James Atlas Computer and Information Sciences 07/27/2009

Cell ArraysNormal array:

zeros(1,5) = 5 doubles[1 2 3 4] = 4 doubles

Cell array:{1 2 3 4} = ???

Page 14: General Computer Science for Engineers CISC 106 Lecture 11 James Atlas Computer and Information Sciences 07/27/2009

Cell Arrays (cont)

c = {1 2 3 4}c{1} = ‘hello’

Cell arrays store an object◦Can be another array◦Or a string◦... any struct/object/cell array

Page 15: General Computer Science for Engineers CISC 106 Lecture 11 James Atlas Computer and Information Sciences 07/27/2009

MATLAB GraphicsEvent-driven user interfaceA figure window contains:

◦axes, line, plot, image, and figure itself

◦controls such as buttons, menus, listboxes, textboxes use uicontrol, and uimenu objects

Page 16: General Computer Science for Engineers CISC 106 Lecture 11 James Atlas Computer and Information Sciences 07/27/2009

MATLAB Simple GUI

Page 17: General Computer Science for Engineers CISC 106 Lecture 11 James Atlas Computer and Information Sciences 07/27/2009

Function callbacksPassing a function to another

function

function []=functionPassTest(func, data)

func(data)

function []=printName(obj)

disp(obj.name)

cat.name = ‘Fifi’

functionPassTest(@printName, cat);

Page 18: General Computer Science for Engineers CISC 106 Lecture 11 James Atlas Computer and Information Sciences 07/27/2009

Project 2Team project

◦2-3 persons per team◦No team members the same as Project

1Due Today

◦Team name, members◦Choice of project focus

Due Aug 3◦Individual progress report

Final Project 2 Due Aug 12

Page 19: General Computer Science for Engineers CISC 106 Lecture 11 James Atlas Computer and Information Sciences 07/27/2009

Project 2 OptionsDatabase (Matlab or C)GameAnimationText EditorGraphics Editing Functions

(Matlab or C)

Page 20: General Computer Science for Engineers CISC 106 Lecture 11 James Atlas Computer and Information Sciences 07/27/2009

Lab 07Create some structures, classesExperiment with a cell arrayModify the simple GUI to add a

menu

Page 21: General Computer Science for Engineers CISC 106 Lecture 11 James Atlas Computer and Information Sciences 07/27/2009

Team Evaluations, Project 1