Top Banner
General Computer Science General Computer Science for Engineers for Engineers CISC 106 CISC 106 Lecture 28 Lecture 28 Dr. John Cavazos Computer and Information Sciences 04/29/2009
15

General Computer Science for Engineers CISC 106 Lecture 28 Dr. John Cavazos Computer and Information Sciences 04/29/2009.

Dec 19, 2015

Download

Documents

Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: General Computer Science for Engineers CISC 106 Lecture 28 Dr. John Cavazos Computer and Information Sciences 04/29/2009.

General Computer General Computer Science Science

for Engineersfor EngineersCISC 106CISC 106

Lecture 28Lecture 28

Dr. John CavazosComputer and Information Sciences

04/29/2009

Page 2: General Computer Science for Engineers CISC 106 Lecture 28 Dr. John Cavazos Computer and Information Sciences 04/29/2009.

Lecture OverviewLecture OverviewProject 2 overviewC++ data types (again)Scopes (Global, Inner, Outer)

Page 3: General Computer Science for Engineers CISC 106 Lecture 28 Dr. John Cavazos Computer and Information Sciences 04/29/2009.

Project 2: Itunes User Project 2: Itunes User InterfaceInterfaceWork by yourself or in a team of 2Extra credit if done in C++

Harder!!Tests skills in sorting and searchingWritten report of two pages required

Serves as documentation for your work

Page 4: General Computer Science for Engineers CISC 106 Lecture 28 Dr. John Cavazos Computer and Information Sciences 04/29/2009.

Project 2: OverviewProject 2: OverviewCreate a struct with artist, song

informationArtistSong TitleSizeEtc...

SortArtist or Song (A to Z, Z to A)Size

User input (for menu option)Filter (by size and by artist)

Page 5: General Computer Science for Engineers CISC 106 Lecture 28 Dr. John Cavazos Computer and Information Sciences 04/29/2009.

C++ Data TypesC++ Data TypesInteger

short, int, long (unsigned)Floating point

float, double, long doubleLogical

bool (values: true, false)Character

charText

String (“Hello World”)

Page 6: General Computer Science for Engineers CISC 106 Lecture 28 Dr. John Cavazos Computer and Information Sciences 04/29/2009.

C++ Data TypesC++ Data Typesunsigned short quantity = 127;short temperature = -10;

int carValue = 0; // always initialize variables!!

carValue = 57000;

quantity = carValue;

carValue = quantity;

The variable quantity cannot store big numbers

Page 7: General Computer Science for Engineers CISC 106 Lecture 28 Dr. John Cavazos Computer and Information Sciences 04/29/2009.

C++ Data TypesC++ Data Typeschar Letter = ‘a’;

string greeting = “This is a string”;

greeting = Letter;

Letter = greeting;

The variable Letter cannot store strings; Think: A character is a string but a string is not a character.

Page 8: General Computer Science for Engineers CISC 106 Lecture 28 Dr. John Cavazos Computer and Information Sciences 04/29/2009.
Page 9: General Computer Science for Engineers CISC 106 Lecture 28 Dr. John Cavazos Computer and Information Sciences 04/29/2009.

Clicker timeClicker time

Page 10: General Computer Science for Engineers CISC 106 Lecture 28 Dr. John Cavazos Computer and Information Sciences 04/29/2009.

C++ ScopesC++ ScopesCurly braces {} introduces a new

blockCreates a ScopeFunctions create a scopeLoops and if statements create a

scope

Page 11: General Computer Science for Engineers CISC 106 Lecture 28 Dr. John Cavazos Computer and Information Sciences 04/29/2009.

C++ ScopesC++ Scopes// this for loop creates a scopefor (…) { …}

for (…) { // variables created in first for

loop scope // are not visible here …}

Page 12: General Computer Science for Engineers CISC 106 Lecture 28 Dr. John Cavazos Computer and Information Sciences 04/29/2009.

C++ ScopesC++ Scopes

int main() { int x = 19; // x is known in all

of main

if (x == 19) { int y = 20; cout << “x + y is “ << x + y

<< endl; } // y is not visible here!}

Page 13: General Computer Science for Engineers CISC 106 Lecture 28 Dr. John Cavazos Computer and Information Sciences 04/29/2009.

Inner versus Outer ScopesInner versus Outer Scopes

int main() { int i = 0; // i is outer scope int j = 100; if (j > 0) { int i = 20; cout << “Inner i is “ << i <<

endl; } cout << “Inner i is “ << i <<

endl;}

Page 14: General Computer Science for Engineers CISC 106 Lecture 28 Dr. John Cavazos Computer and Information Sciences 04/29/2009.

Global scope and :: Global scope and :: operatoroperatorint i = 100;int main() { int i = 0; // i is outer scope

cout << “i in main is “ << i << endl;

cout << “global i “ << ::i << endl;

}

Page 15: General Computer Science for Engineers CISC 106 Lecture 28 Dr. John Cavazos Computer and Information Sciences 04/29/2009.

Coding StandardsCoding StandardsAlways initialize your variablesDefine variables where usedPick names carefullyAlways use the :: (scope resolution

operator) to access globalsAvoid using variables of the same

name for different purposes