Upload
hathuy
View
218
Download
0
Embed Size (px)
Citation preview
144
Schedule Overview Chapters 1 amp 2 Break CodeLab CodeBlock Hands on Q amp A Conclusion References Files Vita
CSC-201 - Computer Science ILecture 1 Introduction and Overview
Chapters 1 and 2
Dr Chuck CartledgeDr Chuck CartledgeDr Chuck CartledgeDr Chuck CartledgeDr Chuck CartledgeDr Chuck CartledgeDr Chuck CartledgeDr Chuck CartledgeDr Chuck CartledgeDr Chuck CartledgeDr Chuck CartledgeDr Chuck CartledgeDr Chuck CartledgeDr Chuck CartledgeDr Chuck CartledgeDr Chuck CartledgeDr Chuck CartledgeDr Chuck CartledgeDr Chuck CartledgeDr Chuck CartledgeDr Chuck Cartledge
August 29 2016 at 933amAugust 29 2016 at 933amAugust 29 2016 at 933amAugust 29 2016 at 933amAugust 29 2016 at 933amAugust 29 2016 at 933amAugust 29 2016 at 933amAugust 29 2016 at 933amAugust 29 2016 at 933amAugust 29 2016 at 933amAugust 29 2016 at 933amAugust 29 2016 at 933amAugust 29 2016 at 933amAugust 29 2016 at 933amAugust 29 2016 at 933amAugust 29 2016 at 933amAugust 29 2016 at 933amAugust 29 2016 at 933amAugust 29 2016 at 933amAugust 29 2016 at 933amAugust 29 2016 at 933am
244
Schedule Overview Chapters 1 amp 2 Break CodeLab CodeBlock Hands on Q amp A Conclusion References Files Vita
Table of contents I1 Schedule
2 Overview
3 Chapters 1 amp 2
4 Break
5 CodeLab
6 CodeBlock
7 Hands on
8 Q amp A
9 Conclusion
10 References
11 Files
12 Vita
344
Schedule Overview Chapters 1 amp 2 Break CodeLab CodeBlock Hands on Q amp A Conclusion References Files Vita
Schedule for the semester
Wk Date Topic Wk Date Topic1 0822 Chap 1 ndash 2 9 1017 Chap 102 0829 Chap 3 ndash 4 10 1031 Chap 10 ndash 113 0905 Chap 5 11 1031 Chap 10 ndash 114 0912 Test ndash Chap 6 12 1107 Testndash Chap 145 0919 Chap 7 13 1114 Chap 146 0926 Chap 8 14 1128 Chap 187 1003 Chap 9 15 1205 Chap 188 1010 Test ndash Chap 10 16 1212 Exam
444
Schedule Overview Chapters 1 amp 2 Break CodeLab CodeBlock Hands on Q amp A Conclusion References Files Vita
Why are we here
Some reasons are obvious others not so much
1 The course is a requirement
2 The language is common
3 The language has interestingfeatures
4 Understanding the languagehelps with other languages
544
Schedule Overview Chapters 1 amp 2 Break CodeLab CodeBlock Hands on Q amp A Conclusion References Files Vita
Why are we here
Same image
644
Schedule Overview Chapters 1 amp 2 Break CodeLab CodeBlock Hands on Q amp A Conclusion References Files Vita
Why are we here
Computer languages are not static
Languages are created and evolveto meet new needsLanguages have some underlyingcommon factors because they allrun on computers
Image from [1]
httpwwwextremetechcomcomputing91572-the-
evolution-of-computer-languages-infographic
744
Schedule Overview Chapters 1 amp 2 Break CodeLab CodeBlock Hands on Q amp A Conclusion References Files Vita
Why are we here
Comparing various known languages
Each language is reflection of thecurrent state of the art in solvinga particular type of problemYou can expect to learn and usemany different languages overthe course of your career andsupporting different programmingparadigms
httphyperpolyglotorg
Use Hyperployglotorg as a language cross reference
844
Schedule Overview Chapters 1 amp 2 Break CodeLab CodeBlock Hands on Q amp A Conclusion References Files Vita
Why are we here
Hammer and nails
ldquo it is temptingif the only tool youhave is a hammer totreat everything as if itwere a nailrdquo
Abraham H Maslow [4]
Image from [9]
944
Schedule Overview Chapters 1 amp 2 Break CodeLab CodeBlock Hands on Q amp A Conclusion References Files Vita
Why are we here
Socratic method (part of your grade)
The Socraticmethod includes theuse of systematicquestioning inductivereasoning universaldefinitions and adisavowal of knowledge
James C Overholser [5]
Figure ldquoJust one more question rdquo
1044
Schedule Overview Chapters 1 amp 2 Break CodeLab CodeBlock Hands on Q amp A Conclusion References Files Vita
Chapter 1
What is computer programming
Computer programming iscreating a series of steps for acomputer to execute to achieve aresult
Image from [8]
Computers are really really stupid but fast
1144
Schedule Overview Chapters 1 amp 2 Break CodeLab CodeBlock Hands on Q amp A Conclusion References Files Vita
Chapter 1
An algorithm is a series of language agnostic steps
Algorithms say what needs to getdone not howAlgorithms can be time ormemory efficient Good ones areboth
Image from [2]
Start with easy algorithms first
1244
Schedule Overview Chapters 1 amp 2 Break CodeLab CodeBlock Hands on Q amp A Conclusion References Files Vita
Chapter 1
How does a computer ldquorunrdquo a program
There are lots of steps in theprocess
1 A human has tounderstand the problem
2 A human selects theappropriate algorithm
3 A human selects theappropriate language
4 A human writes thenecessary steps in the
language (source code)
5 A compiler translates thesource code into objectcode
6 The computer loads theobject code
7 The computer startsprogram execution at aldquowell knownrdquo spot in theobject code
Only the last two steps are fast
1344
Schedule Overview Chapters 1 amp 2 Break CodeLab CodeBlock Hands on Q amp A Conclusion References Files Vita
Chapter 1
What wersquoll do
1 Wersquoll address a problem
2 Wersquoll may or may not use an algorithm
3 Wersquoll use C++
4 Wersquoll use the CodeBlock IDE to edit compile and run ourprogram
5 Wersquoll learn new parts of the language
1444
Schedule Overview Chapters 1 amp 2 Break CodeLab CodeBlock Hands on Q amp A Conclusion References Files Vita
Chapter 1
Software development life cycle (SDLC)
There are many different SDLCmodelsFor our purposes wersquoll focus on
1 Problem solving(requirements and design)
2 Implementation(construction andverification)
3 Maintenance
Image from [3]
All models have these phases
1544
Schedule Overview Chapters 1 amp 2 Break CodeLab CodeBlock Hands on Q amp A Conclusion References Files Vita
Chapter 1
Problem solving phase[6]
Conceptualization and design
Analyze the problem and specify what the solution must do
Develop an algorithm to solve the problem
Verify that your solution really solves the problem
1644
Schedule Overview Chapters 1 amp 2 Break CodeLab CodeBlock Hands on Q amp A Conclusion References Files Vita
Chapter 1
Implementation phase
Testing your program to see if it produces correct results
Debugging your program to identify and correct errors
1744
Schedule Overview Chapters 1 amp 2 Break CodeLab CodeBlock Hands on Q amp A Conclusion References Files Vita
Chapter 1
Maintenance
Use and modify the program to meet changing requirementsor correct errors that show up in using it
Maintenance begins when your program is put into use andaccounts for the majority of effort on most programs
Wholly rewriting program with a clear design sometimes auseful alternative to modifying the existing program to meetchanging requirements
1844
Schedule Overview Chapters 1 amp 2 Break CodeLab CodeBlock Hands on Q amp A Conclusion References Files Vita
Chapter 1
First captured computer bug - 1945
Relay switches are part ofearly (and some current)computers
Grace Hopper found a mothstuck between the relaycontacts
Bug was removed from thecomputer and the programworked
Image from [10]
1944
Schedule Overview Chapters 1 amp 2 Break CodeLab CodeBlock Hands on Q amp A Conclusion References Files Vita
Chapter 1
Whats inside a computer
Things that are common to all digital computers
A way to input and outputdata
A central processing unit(CPU)
Memory (volatile andnon-volatile)
A language the CPUunderstands
The language is composedof binary values Topics of CSC-205 and CSC-215
Other computer types have similar components
2044
Schedule Overview Chapters 1 amp 2 Break CodeLab CodeBlock Hands on Q amp A Conclusion References Files Vita
Chapter 2
Elements of C++ programs
Every program must have a mainfunction that returns an integer
Every identifier is composed ofletters numbers or underscoresand must start with a letter orunderscore
Identifiers are case sensitive
Open and closing curly bracesdefine a context and may benested
There are a limited number ofbuilt-in data types
Assignments to identifiers areidentifier = expression
2144
Schedule Overview Chapters 1 amp 2 Break CodeLab CodeBlock Hands on Q amp A Conclusion References Files Vita
Chapter 2
Examples of variable assignments
a = 3
int a = 3
const int a = 3
name = Samatha
string name = Samantha
const string name = Samantha
fullName = name + Bee
f = ampmain
c = (f)()
The last two are more advanced
2244
Schedule Overview Chapters 1 amp 2 Break CodeLab CodeBlock Hands on Q amp A Conclusion References Files Vita
Chapter 2
How to get values in and out
C++ requires a preprocessor directive to include the ability toinput and output values
includeltiostreamgt
Once we include the directive we can output values
stdcout ltlt rsquorsquoHello worldrsquorsquo ltlt stdendl
stdcout ltlt thisIsA_variable ltlt anotherVariable ltlt stdendl
And we can input values into variables
stdcin gtgt anInt
stdcin gtgt aString
The ldquostdrdquo refers to a namespace Wersquoll talk about that later
2344
Schedule Overview Chapters 1 amp 2 Break CodeLab CodeBlock Hands on Q amp A Conclusion References Files Vita
Chapter 2
Built-in data types
All other types are user-definedand brought in via preprocessordirectives
signed is default unsignedmust be specified
short is at least 16 bits wide
long is at least 32 bits
long long is at least 64 bits
Image from [7]
2444
Schedule Overview Chapters 1 amp 2 Break CodeLab CodeBlock Hands on Q amp A Conclusion References Files Vita
Chapter 2
Same image
Image from [7]
2544
Schedule Overview Chapters 1 amp 2 Break CodeLab CodeBlock Hands on Q amp A Conclusion References Files Vita
Chapter 2
Additional data refinements
The choices made by each implementation about the sizes of thefundamental types are collectively known as data model Four datamodels found wide acceptance
32 bit systems
LP32 or 244 (int is 16-bit long and pointer are 32-bit)(Win16 API)ILP32 or 444 (int long and pointer are 32-bit) (Win32 APIUnix and Unix-like systems)
64 bit systems
LLP64 or 448 (int and long are 32-bit pointer is 64-bit)(Win64 API)LP64 or 488 (int is 32-bit long and pointer are 64-bit)(Unix and Unix-like systems)
2644
Schedule Overview Chapters 1 amp 2 Break CodeLab CodeBlock Hands on Q amp A Conclusion References Files Vita
Break time
Take about 10 minutes
2744
Schedule Overview Chapters 1 amp 2 Break CodeLab CodeBlock Hands on Q amp A Conclusion References Files Vita
CodeLab main screen
Is available via the InternetPassword is TIDEWA-8886-0
https
codelab3turingscraftcomcodelabjsplogin1jsp
2844
Schedule Overview Chapters 1 amp 2 Break CodeLab CodeBlock Hands on Q amp A Conclusion References Files Vita
Same image
https
codelab3turingscraftcomcodelabjsplogin1jsp
2944
Schedule Overview Chapters 1 amp 2 Break CodeLab CodeBlock Hands on Q amp A Conclusion References Files Vita
CodeBlock main screen
Should be installed on everyonersquosmachine
3044
Schedule Overview Chapters 1 amp 2 Break CodeLab CodeBlock Hands on Q amp A Conclusion References Files Vita
Same image
3144
Schedule Overview Chapters 1 amp 2 Break CodeLab CodeBlock Hands on Q amp A Conclusion References Files Vita
Open a file for editing
We will be using standalone filesNot projectsMost files will be attached to apresentation
3244
Schedule Overview Chapters 1 amp 2 Break CodeLab CodeBlock Hands on Q amp A Conclusion References Files Vita
Same image
3344
Schedule Overview Chapters 1 amp 2 Break CodeLab CodeBlock Hands on Q amp A Conclusion References Files Vita
A file will appear in a tab
Most of our coding andexploration will be using only afew files
3444
Schedule Overview Chapters 1 amp 2 Break CodeLab CodeBlock Hands on Q amp A Conclusion References Files Vita
Same image
3544
Schedule Overview Chapters 1 amp 2 Break CodeLab CodeBlock Hands on Q amp A Conclusion References Files Vita
Compile and run a file with F9
Feed back from the compiler willappear in the ldquoBuild messagesrdquotab
3644
Schedule Overview Chapters 1 amp 2 Break CodeLab CodeBlock Hands on Q amp A Conclusion References Files Vita
Same image
3744
Schedule Overview Chapters 1 amp 2 Break CodeLab CodeBlock Hands on Q amp A Conclusion References Files Vita
Practice exercises
Programs to load into CodeBlocks and get running
1 firstonecpp
2 errorcpp
3 leapYearcpp
4 dinnercpp
5 greetcpp
Others if you have time
3844
Schedule Overview Chapters 1 amp 2 Break CodeLab CodeBlock Hands on Q amp A Conclusion References Files Vita
Q amp A time
ldquorsquoThe Answer to the GreatQuestion Of Life the Universeand Everything is forty-tworsquo said DeepThought with infinite majestyand calmrdquoDouglas Adams TheHitchhikerrsquos Guide to theGalaxy
3944
Schedule Overview Chapters 1 amp 2 Break CodeLab CodeBlock Hands on Q amp A Conclusion References Files Vita
What have we covered
Why are we hereWhere wersquore goingHow wersquoll get thereBasic ideas of computerprogrammingHands on programming withCodeLab and CodeBlock
Next time Chapters 3 amp 4
4044
Schedule Overview Chapters 1 amp 2 Break CodeLab CodeBlock Hands on Q amp A Conclusion References Files Vita
References I
[1] Sebastian Anthony The evolution of computer languages(infographic)httpwwwextremetechcomcomputing91572-the-
evolution-of-computer-languages-infographic 2011
[2] Owen Astrachan Bubble sort an archaeological algorithmicanalysis ACM SIGCSE Bulletin vol 35 ACM 2003 pp 1ndash5
[3] Eric Johnson Secure software development lifecycle overviewhttps
software-securitysansorgblog20150407
secure-software-development-lifecycle-overview2015
[4] Abraham H Maslow The psychology of science HenryRegency 1966
4144
Schedule Overview Chapters 1 amp 2 Break CodeLab CodeBlock Hands on Q amp A Conclusion References Files Vita
References II
[5] James C Overholser Elements of the socratic method Vself-improvement Psychotherapy Theory Research PracticeTraining 33 (1996) no 4 549
[6] Sylvia Sorkin Programming and problem solving with c++Teacher Resource Jones and Barlett Learning 2014
[7] C++ Staff Fundamental typeshttpencppreferencecomwcpplanguagetypes2016
[8] Derivativesinvesting Staff Qc 7 toolshttpwwwderivativesinvestingnetarticle
277260716qc-7-tools 2016
4244
Schedule Overview Chapters 1 amp 2 Break CodeLab CodeBlock Hands on Q amp A Conclusion References Files Vita
References III
[9] Happiness Staff Abraham maslowhttpwwwpursuit-of-happinessorghistory-of-
happinessabraham-maslow 2016
[10] Wikipedia Staff Grace hopperhttpsenwikipediaorgwikiGrace_Hopper 2016
4344
Schedule Overview Chapters 1 amp 2 Break CodeLab CodeBlock Hands on Q amp A Conclusion References Files Vita
Files of interest
1 areacpp
2 chessboardcpp
3 dinner2cpp
4 dinnercpp
5 errorcpp
6 firstonecpp
7 greet2cpp
8 greetcpp
9 leapYearcpp
10 raincpp
11 rainin
12 rhymecpp
13 shellcpp
14 wrapcpp
15 ProgramCourseGuide 880-01pdf
Program Area calculates the area of a square
The user is prompted to enter the number of inches on each
side Note that ldquoendlrdquo in line 7 ends in the letter ldquolrdquo not
the number one
include lt iostream gt
using namespace std
int main ()
int inches
cout ltlt Enter the number of inches on a side
ltlt endl
cout ltlt Press the return key
ltlt endl
cin gtgt inches
cout ltlt endl
ltlt The area is ltlt inches inches ltlt
ltlt endl
return 0
Nell Drake and Chip Weems
chessboardcpp
Chessboard program
This program prints a chessboard pattern that is built up from
basic strings of white and black characters
include lt iostream gt
include lt string gt
using namespace std
const string BLACK = Define a line of a black square
const string WHITE = Define a line of a white square
int main ()
string whiteRow A row beginning with a white square
string blackRow A row beginning with a black square
Create a white-black row by concatenating the basic strings
whiteRow = WHITE + BLACK + WHITE + BLACK +
WHITE + BLACK + WHITE + BLACK
Create a black-white row by concatenating the basic strings
blackRow = BLACK + WHITE + BLACK + WHITE +
BLACK + WHITE + BLACK + WHITE
Print five white-black rows
cout ltlt whiteRow ltlt endl
cout ltlt whiteRow ltlt endl
cout ltlt whiteRow ltlt endl
cout ltlt whiteRow ltlt endl
cout ltlt whiteRow ltlt endl
Print five black-white rows
cout ltlt blackRow ltlt endl
cout ltlt blackRow ltlt endl
cout ltlt blackRow ltlt endl
cout ltlt blackRow ltlt endl
cout ltlt blackRow ltlt endl
Print five white-black rows
cout ltlt whiteRow ltlt endl
cout ltlt whiteRow ltlt endl
cout ltlt whiteRow ltlt endl
cout ltlt whiteRow ltlt endl
cout ltlt whiteRow ltlt endl
Print five black-white rows
cout ltlt blackRow ltlt endl