csc-201 - computer science i lecture #3: chapter...
TRANSCRIPT
-
1/34
Schedule Miscellanea Chapter 5 Break Test preps. Hands on Q & A Conclusion References Files
CSC-201 - Computer Science ILecture #3: Chapter 5
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
September 5, 2016 at 10:19pmSeptember 5, 2016 at 10:19pmSeptember 5, 2016 at 10:19pmSeptember 5, 2016 at 10:19pmSeptember 5, 2016 at 10:19pmSeptember 5, 2016 at 10:19pmSeptember 5, 2016 at 10:19pmSeptember 5, 2016 at 10:19pmSeptember 5, 2016 at 10:19pmSeptember 5, 2016 at 10:19pmSeptember 5, 2016 at 10:19pmSeptember 5, 2016 at 10:19pmSeptember 5, 2016 at 10:19pmSeptember 5, 2016 at 10:19pmSeptember 5, 2016 at 10:19pmSeptember 5, 2016 at 10:19pmSeptember 5, 2016 at 10:19pmSeptember 5, 2016 at 10:19pmSeptember 5, 2016 at 10:19pmSeptember 5, 2016 at 10:19pmSeptember 5, 2016 at 10:19pm
-
2/34
Schedule Miscellanea Chapter 5 Break Test preps. Hands on Q & A Conclusion References Files
Table of contents I
1 Schedule
2 Miscellanea
3 Chapter 5
4 Break
5 Test preps.
6 Hands on
7 Q & A
8 Conclusion
9 References
10 Files
-
3/34
Schedule Miscellanea Chapter 5 Break Test preps. Hands on Q & A Conclusion References Files
Schedule for the semester
Wk. Date Topic Wk. Date Topic1 08/22 Chaps. 1 2 X 9 10/17 Chap. 102 08/29 Chaps. 3 4 X 10 10/31 Chaps. 10 113 09/05 Chap. 5 11 10/31 Chaps. 10 114 09/12 Test Chap. 6 12 11/07 Test Chap. 145 09/19 Chap. 7 13 11/14 Chap. 146 09/26 Chap. 8 14 11/28 Chap. 187 10/03 Chap. 9 15 12/05 Chap. 188 10/10 Test Chap. 10 16 12/12 Exam
-
4/34
Schedule Miscellanea Chapter 5 Break Test preps. Hands on Q & A Conclusion References Files
Corrections and additions since last lecture.
Answered a few questionse-mails about theassignment
Assignment #01 due bybeginning of class
-
5/34
Schedule Miscellanea Chapter 5 Break Test preps. Hands on Q & A Conclusion References Files
This and that
Read from a file.
Objectives are fairlystraightforward:
Read strings from a datafile.
Output strings to the screenin a particular format
Submit your source code.
This is a single person effort (nota team effort).
Any questions or problems?
-
6/34
Schedule Miscellanea Chapter 5 Break Test preps. Hands on Q & A Conclusion References Files
Conditions, logical expressions, and selection control structures
Flow of control
There are limited number of different flow of control
Sequential instructions are executed in order
Function calls program execution is transferred to a functionand then returned (with or without a return value)
Selection some instructions are executed, but others are not
Looping a set of instructions is executed more than once
Weve talked about sequential, and function calls. Now, welladdress selection.
-
7/34
Schedule Miscellanea Chapter 5 Break Test preps. Hands on Q & A Conclusion References Files
Conditions, logical expressions, and selection control structures
C++ operators we will know and love.
There are a lot of declaredoperators in C++. Over the nextfew months will will learn aboutthe ones in red, and possibly theones in green.
Image from [3].
-
8/34
Schedule Miscellanea Chapter 5 Break Test preps. Hands on Q & A Conclusion References Files
Conditions, logical expressions, and selection control structures
Same image.
Image from [3].
-
9/34
Schedule Miscellanea Chapter 5 Break Test preps. Hands on Q & A Conclusion References Files
Conditions, logical expressions, and selection control structures
With so many operators, which has precedence?
Not all operations are left toright. Precedence can be affectedby using parenthesis.
Image from [4].
-
10/34
Schedule Miscellanea Chapter 5 Break Test preps. Hands on Q & A Conclusion References Files
Conditions, logical expressions, and selection control structures
Same image.
Image from [4].
-
11/34
Schedule Miscellanea Chapter 5 Break Test preps. Hands on Q & A Conclusion References Files
Conditions, logical expressions, and selection control structures
The if statement.
The if statement, evaluates a conditional as true orfalseWhen the conditional is true then the next statement isexecuted.The conditional can be simple or complex.
Examples of if statements:if ( true ) cout
-
12/34
Schedule Miscellanea Chapter 5 Break Test preps. Hands on Q & A Conclusion References Files
Conditions, logical expressions, and selection control structures
The if statement continued.
What is the output/result of these statements?
c = a = 3;
c = a == 3;
if ( a = 3 )
cout
-
13/34
Schedule Miscellanea Chapter 5 Break Test preps. Hands on Q & A Conclusion References Files
Conditions, logical expressions, and selection control structures
The if statement some more.
What if we dont want the true case ?
if ( !true ) cout
-
14/34
Schedule Miscellanea Chapter 5 Break Test preps. Hands on Q & A Conclusion References Files
Conditions, logical expressions, and selection control structures
The true and false conditions with an ifstatement.
How can we handle both the true and false conditions?
if ( true ) cout
-
15/34
Schedule Miscellanea Chapter 5 Break Test preps. Hands on Q & A Conclusion References Files
Conditions, logical expressions, and selection control structures
What if we want to execute more than one statement?
We look at what defines a statement.
if ( true ) cout
-
16/34
Schedule Miscellanea Chapter 5 Break Test preps. Hands on Q & A Conclusion References Files
Conditions, logical expressions, and selection control structures
Things are easy with integer numbers.
How about strings?
The logical operators can be used on strings.
Strings are compared, character by character based on theASCII1 coding scheme.
One string can be equal to, less than, or greater than anotherstring.
What happens with non-ASCII strings?
1ASCII is the American Standard Code for Information Interchangehttp://man7.org/linux/man-pages/man7/ascii.7.html
http://man7.org/linux/man-pages/man7/ascii.7.html
-
17/34
Schedule Miscellanea Chapter 5 Break Test preps. Hands on Q & A Conclusion References Files
Conditions, logical expressions, and selection control structures
if conditionals with strings.
Do these conditionals evaluate to true or false
string myState = "Texas";
string yourState = "Maryland";
myState == yourState
myState > yourState
myState == "Texas"
myState == "texas"
myState < "texas"
-
18/34
Schedule Miscellanea Chapter 5 Break Test preps. Hands on Q & A Conclusion References Files
Conditions, logical expressions, and selection control structures
Can we use conditionals with non-integer numbers
Yes, but they may not work.We talked about this last week. The way floating point numbersare represented in memory means that some decimals can not berepresented accurately.If you have to use floating point variables in conditionals, thendont test for equality, test for close enough.
double epsilon = 0.00001;
if ( fabs (fp1 - fp2)
-
19/34
Schedule Miscellanea Chapter 5 Break Test preps. Hands on Q & A Conclusion References Files
Conditions, logical expressions, and selection control structures
How about if there are lots of conditions to test,
And the conditions are somehowrelated??
An if statement is astatement.
An if statement willbranch and execute astatement.
Therefore an if statement canexecute another if statement.Hands-on exercise.
Image from [1].
Hands on exercise.
-
20/34
Schedule Miscellanea Chapter 5 Break Test preps. Hands on Q & A Conclusion References Files
Conditions, logical expressions, and selection control structures
Same image.
Image from [1].
Hands on exercise.
-
21/34
Schedule Miscellanea Chapter 5 Break Test preps. Hands on Q & A Conclusion References Files
Conditions, logical expressions, and selection control structures
You can test I/O as well.
You can test the state of the Input/Output stream.
An input stream can fail:
Try to read invalid dataTry to open a file that doesnt existTry to read past the end of a file
An output stream can fail:
Try to create a file with an invalid nameTry to create a file on a write-protected mediumTry to create a file on a full disk
After using a stream, you should check its state to see if theoperation was a success.
-
22/34
Schedule Miscellanea Chapter 5 Break Test preps. Hands on Q & A Conclusion References Files
Conditions, logical expressions, and selection control structures
Checking I/O example
std::string fileName = "/tmp/temp.txt";
std::ifstream inputFile;
inputFile.open(fileName.c_str());
if ( !inputFile )
{
std::cout
-
23/34
Schedule Miscellanea Chapter 5 Break Test preps. Hands on Q & A Conclusion References Files
Testing
Where does testing belong?
Software testing is one element of a broader topicthat is often referred to as verification and validation(V&V). Verification refers to the set of tasks that ensurethat software correctly implements a specific function.Validation refers to a different set of tasks that ensurethat the software that has been built is traceable tocustomer requirements.
Pressman [2]
-
24/34
Schedule Miscellanea Chapter 5 Break Test preps. Hands on Q & A Conclusion References Files
Testing
Generic testing classifications
Testing requires enough data sets to ensure that each branch isexecuted at least once.The difference is how much insight you have into the software:
White box testing total visibility into the software
Black box testing no visibility into the software
-
25/34
Schedule Miscellanea Chapter 5 Break Test preps. Hands on Q & A Conclusion References Files
Testing
Incremental and regression testing
Two different types of testing that require different types of tools.
Incremental code a little,test a little
Regression stop codingand test a lot. Instrumentcode to see test coverage.
Full regression testing often requires support software.
-
26/34
Schedule Miscellanea Chapter 5 Break Test preps. Hands on Q & A Conclusion References Files
Testing
Good testing requires a plan
There are different testing phases, and each needs to be in theplan.
Unit testing a developertests the software instandalone environment
Integration testing a teamtest software from differentdevelopers together
Top-down integrationBottom-up integrationRegression testingSmoke testing
Documentation
Alpha and beta testing
-
27/34
Schedule Miscellanea Chapter 5 Break Test preps. Hands on Q & A Conclusion References Files
Break time.
Take about 10 minutes.
-
28/34
Schedule Miscellanea Chapter 5 Break Test preps. Hands on Q & A Conclusion References Files
Some ideas
Broad things from different chapters
1 Lots of vocabulary andordering things
2 More vocabulary and basicsyntax
3 Variables of different typesand what you can do withthem
4 Extraction operators andsimple programs
5 if . . . then . . . else andconditionals
-
29/34
Schedule Miscellanea Chapter 5 Break Test preps. Hands on Q & A Conclusion References Files
Some ideas
There will be an exam.
Cover chapters 1 through 5(inclusive)
Exam has not been writtenyet
Exam should take about anhour
When finished with exam,leave room with answers
Lecture will start after examends
Any questions? Now is the time to ask.
-
30/34
Schedule Miscellanea Chapter 5 Break Test preps. Hands on Q & A Conclusion References Files
Practice exercises
Programs to load into CodeBlocks and get running:
1 testIfStatements.cpp (get the program working)
2 BMI.cpp (trace nested if statements)
3 testIO.cpp (see if you can open a file)
Others, if you have time.
-
31/34
Schedule Miscellanea Chapter 5 Break Test preps. Hands on Q & A Conclusion References Files
Q & A time.
The Answer to the GreatQuestion . . . Of Life, the Universeand Everything . . . is. . . forty-two, said DeepThought, with infinite majestyand calm.Douglas Adams, TheHitchhikers Guide to theGalaxy
-
32/34
Schedule Miscellanea Chapter 5 Break Test preps. Hands on Q & A Conclusion References Files
What have we covered?
Covered if statementsCovered software testingrequirementsGave hints about what will be onthe testGot our hands dirty with live code
Next time: Test and Chapter 6
-
33/34
Schedule Miscellanea Chapter 5 Break Test preps. Hands on Q & A Conclusion References Files
References I
[1] Nell Dale and Chip Weems, Programming and problem solvingwith c++: Comprehensive, Jones & Bartlett Publishers, 2013.
[2] Roger S Pressman, Software engineering: A practitionersapproach, Palgrave Macmillan, 2005.
[3] Richard Smith et al., Working draft, standard for programminglanguage c++, ISO/IEC JTC1/SC22/WG21 document N4296 (2015).
[4] C++ Staff, C++ operator precedence,http://en.cppreference.com/w/cpp/language/
operator_precedence, 2016.
http://en.cppreference.com/w/cpp/language/operator_precedencehttp://en.cppreference.com/w/cpp/language/operator_precedence
-
34/34
Schedule Miscellanea Chapter 5 Break Test preps. Hands on Q & A Conclusion References Files
Files of interest
1 BMI.cpp
2 testIfStatements.cpp
3 testIO.cpp
4 virtualization.pdf
BMI.cpp//****************************************************************
//BMIProgram
//Thisprogramcalculatesthebodymassindex(BMI)givenaweight
//inpoundsandaheightininchesandprintsahealthmessage
//basedontheBMI.InputinEnglishmeasures.
//*****************************************************************
#include
usingnamespacestd;
intmain()
{
constintBMI_CONSTANT=703;//Constantinnon-metricformula
floatweight;//Weightinweight
floatheight;//Heightinheight
floatbodyMassIndex;//AppropriateBMI
booldataIsOK;//Trueifdatanon-negative
//Promptforandinputweightandheight
cout
-
1/10
How do programs operate? What is Virtualization? What is it good for? What is it not good for? Conclusion References
CS-495/595Big Data
Virtualization
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
21 Jan. 201521 Jan. 201521 Jan. 201521 Jan. 201521 Jan. 201521 Jan. 201521 Jan. 201521 Jan. 201521 Jan. 201521 Jan. 201521 Jan. 201521 Jan. 201521 Jan. 201521 Jan. 201521 Jan. 201521 Jan. 201521 Jan. 201521 Jan. 201521 Jan. 201521 Jan. 201521 Jan. 2015
-
2/10
How do programs operate? What is Virtualization? What is it good for? What is it not good for? Conclusion References
Table of contents
1 How do programs operate?
2 What is Virtualization?
3 What is it good for?
4 What is it not good for?
5 Conclusion
6 References
-
3/10
How do programs operate? What is Virtualization? What is it good for? What is it not good for? Conclusion References
A 50,000 foot view
What are the layers in this cake?
User the person (orthing) that wantssomething done
Application the programthat does the work
Hardware the silicone,copper, other tangibles thatgenerate heat
Operating system arbitrates between multipleprograms and limitedresources
Figure : Notional view of computerlayers [3].
-
4/10
How do programs operate? What is Virtualization? What is it good for? What is it not good for? Conclusion References
Focusing on the OS
What does it do?
Provides a user interface(maybe a Command LineInterface)
Schedules access to thehardware
Schedules the functions ofthe CPU
Figure : A few OS details [2].
An OS is a program (albeit, a large program). What if we couldwrite a program that would run an OS as an application??
-
5/10
How do programs operate? What is Virtualization? What is it good for? What is it not good for? Conclusion References
Tricking the upper layer.
Higher layers rely on lowerlayers for services
Layers create interfaces
Interfaces allow for hidingdetails
What is real? And, what isvirtual? [1]
As long as the lower layer supplies all the services, the upper layerwont know where the services originated.
-
6/10
How do programs operate? What is Virtualization? What is it good for? What is it not good for? Conclusion References
One hardware suite can run many OS in virtualmachines.
Ultimately the hardwaredetermines how many virtualmachines can be run
Faster CPU(s), more RAM,more network connections,more disks, . . . , more isbetter
Fewer actual machinesusually means lower power,lower cooling, cheaperupgrade path
With clever software, almost anything can be virtualized. Hadoopis clever software.
-
7/10
How do programs operate? What is Virtualization? What is it good for? What is it not good for? Conclusion References
Anything that has to be fast.
Underlying hardware suite isshared across all machines
Mission critical applications
-
8/10
How do programs operate? What is Virtualization? What is it good for? What is it not good for? Conclusion References
In summary.
To use virtual machines, or
To not use virtual machines.
It depends on what is important.
-
9/10
How do programs operate? What is Virtualization? What is it good for? What is it not good for? Conclusion References
What have we covered?
There are lots of free virtualmachine programs for you totryThey are good for trying,testing, experimentingThey are good for maximumuse of available hardwareThey are not good forreal-time applicationsHDFS is a virtual file system
-
10/10
How do programs operate? What is Virtualization? What is it good for? What is it not good for? Conclusion References
References I
[1] Paul Hodge, Virtualization 101: Understanding how to do morewith less, https://www.isa.org/standards-and-publications/isa-publications/intech-magazine/2011/august/system-integration-virtualization-101-understanding-how-to-do-more-with-less/,2011.
[2] Willy-Peter Schaub,UNISA Chatter Operating System Concepts: Part 2 System Structureshttp://blogs.msdn.com/b/willy-peter schaub/archive/2010/01/07/unisa-chatter-operating-system-concepts-part-2-system-structures.aspx,2010.
[3] Wikipedia, Software Wikipedia, The Free Encyclopedia,http://en.wikipedia.org/wiki/Software, 2015.
How do programs operate?
What is Virtualization?
What is it good for?
What is it not good for?
Conclusion
References
"Chuck Cartledge"
ScheduleMiscellaneaCorrections and additions since last lecture.This and that
Chapter 5Conditions, logical expressions, and selection control structuresTesting
BreakTest preps.Some ideas
Hands onQ & AConclusionReferencesFiles