2/22/2016 1R. Smith - University of St Thomas - Minnesota CISC 130: Today’s Class History Paper scheduleHistory Paper schedule RecapRecap Plus PlusPlus.

Slides:



Advertisements
Similar presentations
AP Computer Science Anthony Keen. Computer 101 What happens when you turn a computer on? –BIOS tries to start a system loader –A system loader tries to.
Advertisements

March R. Smith - University of St Thomas - Minnesota Today’s Class Quiz RecapQuiz Recap Exam ReviewExam Review C MaterialC Material Matlab MaterialMatlab.
1 Homework Assignments Turn in HW1 (If not done yet, catch up!) Questions about HW1? Anyone still stuck on apply / UNIX account? Everyone have the books?
March /18R. Smith - University of St Thomas - Minnesota QMCS 230: Today in Class Three exam questionsThree exam questions Lab with filesLab with.
March /18R. Smith - University of St Thomas - Minnesota QMCS 230: Today in Class Reading numbers from dialogsReading numbers from dialogs Converting.
March R. Smith - University of St Thomas - Minnesota QMCS 130: Today’s Class More about FunctionsMore about Functions RecursionRecursion.
March R. Smith - University of St Thomas - Minnesota Today’s Class Recap of a simple programRecap of a simple program A “history” of CA “history”
March /18R. Smith - University of St Thomas - Minnesota QMCS 230: Today in Class IF StatementIF Statement Revisiting assignment statementsRevisiting.
March /18R. Smith - University of St Thomas - Minnesota QMCS 230: Today in Class Hard Drives – more laterHard Drives – more later MethodsMethods.
March R. Smith - University of St Thomas - Minnesota QMCS 130: Today’s Class Exam TopicsExam Topics.
March /18R. Smith - University of St Thomas - Minnesota QMCS 230: Today in Class The project assignment, againThe project assignment, again Arrays.
March R. Smith - University of St Thomas - Minnesota QMCS 130: Today’s Class Functions and Array ArgumentsFunctions and Array Arguments ExamExam.
March R. Smith - University of St Thomas - Minnesota QMCS 130: Today’s Class Today: covering through P. 83 of textToday: covering through P. 83 of.
March R. Smith - University of St Thomas - Minnesota Today’s Class Course StuffCourse Stuff –Classroom change TOMORROW –Assignment; Lab While LoopsWhile.
March R. Smith - University of St Thomas - Minnesota Today’s Class Program LayoutProgram Layout Problem SolvingProblem Solving Reading InputReading.
March R. Smith - University of St Thomas - Minnesota ENGR 330: Today’s Class Class on Wednesday – “Lab time” in OSS 230Class on Wednesday – “Lab.
March R. Smith - University of St Thomas - Minnesota Today’s Class RecapRecap More course thingsMore course things Work on labs/projectsWork on labs/projects.
March R. Smith - University of St Thomas - Minnesota QMCS 130: Today’s Class GradingGrading The examThe exam Sorting arraysSorting arrays Pointers,
Spring R. Smith - University of St Thomas - Minnesota QMCS 130: Today’s Class Where we areWhere we are Strings and TextStrings and Text ConditionalsConditionals.
Spring R. Smith - University of St Thomas - Minnesota QMCS 130: Today’s Class Final Exam ReviewFinal Exam Review –Assessment –Exam Format –C –Matlab.
March R. Smith - University of St Thomas - Minnesota QMCS 130: Today’s Class Exam StatusExam Status Recap of Lab 7 ExampleRecap of Lab 7 Example.
March /18R. Smith - University of St Thomas - Minnesota QMCS 230: Today in Class I/O ObjectsI/O Objects Lab 12Lab 12.
March R. Smith - University of St Thomas - Minnesota QMCS 130: Today’s Class Young Scholars GrantsYoung Scholars Grants Exam Next TuesdayExam Next.
March R. Smith - University of St Thomas - Minnesota QMCS 230: Today in Class Today’s LabToday’s Lab SortingSorting.
March /18R. Smith - University of St Thomas - Minnesota QMCS 230: Today in Class Reviewing previous workReviewing previous work Using a dialog boxUsing.
March R. Smith - University of St Thomas - Minnesota QMCS 130: Today’s Class The ProjectThe Project PointersPointers.
March R. Smith - University of St Thomas - Minnesota CISC Class Today Return Homework; grading recapReturn Homework; grading recap “Enigma”
March /18R. Smith - University of St Thomas - Minnesota QMCS 230 – Today in Class Getting Homework BackGetting Homework Back DecimalFormat class.
6/22/2015 1R. Smith - University of St Thomas - Minnesota QMCS Class Today St. Lukes Case StudySt. Lukes Case Study.
Spring R. Smith - University of St Thomas - Minnesota QMCS 130: Today’s Class Return HomeworkReturn Homework Class ScheduleClass Schedule Functions:
March /18R. Smith - University of St Thomas - Minnesota QMCS 230: Today in Class Exam ReviewExam Review Arithmetic - I think everyone gets thisArithmetic.
March R. Smith - University of St Thomas - Minnesota QMCS 130: Today’s Class Upcoming Exam – April 8Upcoming Exam – April 8 Structures ReviewStructures.
March R. Smith - University of St Thomas - Minnesota QMCS Class Today Cryptography – introductory termsCryptography – introductory terms “Enigma”
Imperative Programming Prof. Béat Hirsbrunner Amine Tafat, PhD Student Matthias Buchs and Raphaël Lesceux, Graduate Students Department of Informatics.
March R. Smith - University of St Thomas - Minnesota QMCS 130: Today’s Class RecapRecap Functions and CFunctions and C Using FunctionsUsing Functions.
March /18R. Smith - University of St Thomas - Minnesota QMCS 230: Today in Class MethodsMethods Problem solving by decompositionProblem solving by.
March /18R. Smith - University of St Thomas - Minnesota QMCS 230 – Today in Class Authorizing OvertimeAuthorizing Overtime Weird Java stuff: conditionals,
March R. Smith - University of St Thomas - Minnesota Today’s Class Lab 1 commentsLab 1 comments Data Types in Chapter 4Data Types in Chapter 4 Lab.
March /18R. Smith - University of St Thomas - Minnesota QMCS 230: Today in Class Nested IFNested IF “Boolean” Logical Operations“Boolean” Logical.
March R. Smith - University of St Thomas - Minnesota ENGR 330: Today’s Class More “Clarifications” ?More “Clarifications” ? Interrupts – integrating.
March R. Smith - University of St Thomas - Minnesota Today’s Class First, course surveysFirst, course surveys RecapRecap More course thingsMore course.
March R. Smith - University of St Thomas - Minnesota QMCS 130: Today’s Class Lab Status, Paper StatusLab Status, Paper Status Comments on Ints vs.
March /18R. Smith - University of St Thomas - Minnesota QMCS 230: Today in Class Random NumbersRandom Numbers Output filesOutput files Input filesInput.
6/28/2015 1R. Smith - University of St Thomas - Minnesota CISC 130: Today’s Class History Paper recapHistory Paper recap Finish the movieFinish the movie.
March R. Smith - University of St Thomas - Minnesota QMCS 130: Today’s Class Data IndependenceData Independence Matlab #3: Exercise 5.1Matlab #3:
March R. Smith - University of St Thomas - Minnesota QMCS 230: Today in Class Buttons: Radio and Check BoxButtons: Radio and Check Box Lab 20Lab.
March R. Smith - University of St Thomas - Minnesota QMCS 130: Today’s Class StatusStatus –Survey –Returning homework ArraysArrays –What are they?
March R. Smith - University of St Thomas - Minnesota QMCS 130: Today’s Class Finish up Lab 13Finish up Lab 13 Lab 14 – DetailsLab 14 – Details.
March R. Smith - University of St Thomas - Minnesota QMCS 130: Today’s Class The examThe exam –Open book, no notes, like last time Exam TopicsExam.
March R. Smith - University of St Thomas - Minnesota ENGR 330: Today’s Class Administrative: do you want another lab?Administrative: do you want.
March R. Smith - University of St Thomas - Minnesota QMCS 130: Today’s Class Revised Lab 14/15Revised Lab 14/15 Counting WordsCounting Words Moving.
March /18R. Smith - University of St Thomas - Minnesota QMCS 230: Today in Class About HomeworkAbout Homework Increment/DecrementIncrement/Decrement.
March R. Smith - University of St Thomas - Minnesota QMCS 130: Today’s Class Homework & GradesHomework & Grades Multiple DimensionsMultiple Dimensions.
March R. Smith - University of St Thomas - Minnesota Today’s Class Homework NotesHomework Notes –Always try to match the printed output if I give.
March /18R. Smith - University of St Thomas - Minnesota QMCS 230: Today in Class More LoopsMore Loops Do While – a ‘trailing decision’ loopDo While.
March /18R. Smith - University of St Thomas - Minnesota QMCS 230: Today in Class The ExamThe Exam Homework NotesHomework Notes.
March R. Smith - University of St Thomas - Minnesota QMCS 130: Today’s Class AssignmentsAssignments Logical operationsLogical operations Summations.
9/21/2015 1R. Smith - University of St Thomas - Minnesota CISC 130: Today’s Class RecapRecap Files, writing filesFiles, writing files 1D Array Recap1D.
Spring R. Smith - University of St Thomas - Minnesota QMCS 130: Today’s Class Final Exam – rest of class scheduleFinal Exam – rest of class schedule.
5/27/2016 1R. Smith - University of St Thomas - Minnesota CISC 130: Today’s Class RecapRecap Drawing in 2 dimensionsDrawing in 2 dimensions Vertical HistogramVertical.
CS140: Intro to CS An Overview of Programming in C (part 3) by Erin Chambers.
March R. Smith - University of St Thomas - Minnesota QMCS 130: Today’s Class Grades & Lab 12Grades & Lab 12 Upcoming ExamUpcoming Exam StructuresStructures.
March R. Smith - University of St Thomas - Minnesota QMCS Class Today “Enigma” recap and finish“Enigma” recap and finish The quiz/surveyThe.
1/28/2016 1R. Smith - University of St Thomas - Minnesota CISC 130: Today’s Class Assignments 7 and 8Assignments 7 and 8 ExamExam History Paper AssignmentHistory.
1/31/2016 1R. Smith - University of St Thomas - Minnesota CISC Today’s Class RecapRecap Problem 11Problem 11 Problem 12Problem 12.
March /18R. Smith - University of St Thomas - Minnesota QMCS 230: Today in Class What’s on the Exam Next Week?What’s on the Exam Next Week? Lab 8Lab.
March R. Smith - University of St Thomas - Minnesota Today’s Class Class StuffClass Stuff ProjectProject Vectors and DimensionsVectors and Dimensions.
7/6/2016 1R. Smith - University of St Thomas - Minnesota CISC 130: Today’s Class Collect PapersCollect Papers Review: Our ZeroesReview: Our Zeroes Review:
7/6/2016 1R. Smith - University of St Thomas - Minnesota CISC 130: Today’s Class Computer HardwareComputer Hardware Recap: next programRecap: next program.
7/7/2016 1R. Smith - University of St Thomas - Minnesota CISC Today’s Class RecapRecap Project ProposalProject Proposal Problem 12Problem 12 Final.
Presentation transcript:

2/22/2016 1R. Smith - University of St Thomas - Minnesota CISC 130: Today’s Class History Paper scheduleHistory Paper schedule RecapRecap Plus PlusPlus Plus Scanning for WordsScanning for Words

Recap Finished the movieFinished the movie Recap Character I/ORecap Character I/O The getline() functionThe getline() function Converting stringsConverting strings 2/22/2016 2R. Smith - University of St Thomas - Minnesota

2/22/2016 3R. Smith - University of St Thomas - Minnesota Number conversion Variables: total, ones, tensVariables: total, ones, tens Loop while there are digitsLoop while there are digits –Multiply last result by 10 to get ‘tens’ –Subtract ‘0’ from next digit to get the ‘ones’ –Add ‘ones’ and ‘tens’ to get the running total When out of digits, return the totalWhen out of digits, return the total

Plus Plus OPTIONAL shortcuts in COPTIONAL shortcuts in C We can add doubled operators to increment or decrement variables:We can add doubled operators to increment or decrement variables:X++X-- All operators work in assignment statementsAll operators work in assignment statements X += 10 // adds 10 to x Y /= 10 // divides Y by 10

Assignment 10 Type in lines of text ended by a blank lineType in lines of text ended by a blank line Count the number of words in the linesCount the number of words in the lines At the end, generate a histogram of word lengthsAt the end, generate a histogram of word lengths 2/22/2016 5R. Smith - University of St Thomas - Minnesota

2/22/2016 6R. Smith - University of St Thomas - Minnesota Finding and Counting Words Counting CharactersCounting Characters –We just count the number of getchars() we do Counting LinesCounting Lines –We just count the number of ‘\n’ characters Counting WordsCounting Words –Words are separated by ‘white space’ –Can we just count white spaces?

2/22/2016 7R. Smith - University of St Thomas - Minnesota Counting Word Separators int sepcount(char in[LINSZ]) { int nw = 0; // number of words int nw = 0; // number of words int i = 0;// loop index int i = 0;// loop index // Loop searches for words while (in[i] != ‘\0’) { while (in[i] != ‘\0’) { if (in[i] == ' ' || in[i] == '\t') { if (in[i] == ' ' || in[i] == '\t') { nw = nw + 1; nw = nw + 1; } i = i + 1; i = i + 1;} // return the result return nw; }

2/22/2016 8R. Smith - University of St Thomas - Minnesota Reporting Word Length Sample program:Sample program: We type in a line of textWe type in a line of text For each word, we print out its lengthFor each word, we print out its length Input: a rusty tattered cogInput: a rusty tattered cog Output: – 3 -Output: – 3 - How do we do this?How do we do this?

2/22/2016 9R. Smith - University of St Thomas - Minnesota Identifying Word boundaries For each char: are we inside or outside a word?For each char: are we inside or outside a word? Use ‘states’ and a comb structureUse ‘states’ and a comb structure –One level of ‘if’ checks for white space –One level of ‘if’ checks the ‘state’ Input = White Space Input = other character State = IN Next State = OUT [ended a word] Next State = IN [inside a word] State = OUT Next State = OUT [outside a word] Next State = IN [started a word]

2/22/ R. Smith - University of St Thomas - Minnesota Comb structure for word boundaries if (ch == ‘ ‘ || ch == ‘\t’ || ch == ‘\n’) { if (state == OUT) { if (state == OUT) { // handle text outside of a word } else { // found the end of a word state = OUT; } } else { // not white space if (state == OUT) { // found the start of a word state = IN; } else { // handle text inside of a word }}

2/22/ R. Smith - University of St Thomas - Minnesota How do we count word length? When we start a word, it’s 1 char longWhen we start a word, it’s 1 char long When we’re inside a word,When we’re inside a word, –we add another char to the length When we end a word,When we end a word, –we don’t add another char –we save the result Input = White Space Input = other character State = IN Next State = OUT Next State = IN State = OUT Next State = OUT Next State = IN

2/22/ R. Smith - University of St Thomas - Minnesota How do we count word length? When we start a word, it’s 1 char longWhen we start a word, it’s 1 char long When we’re inside a word,When we’re inside a word, –we add another char to the length When we end a word,When we end a word, –we don’t add another char –we save the result Input = White Space Input = other character State = IN Next State = OUT Print the count Next State = IN Increment count State = OUT Next State = OUT do nothing Next State = IN count = 1

2/22/ R. Smith - University of St Thomas - Minnesota Printing Word Lengths – part 1 void wlengths(char in[]) { int i = 0;// loop index int state = OUT;// state variable cc = 0;// character count for a word do { if (isspace(in[i]) { // check for the end of a word if (state == IN) { printf(“ %d – “, cc); state = OUT; }

2/22/ R. Smith - University of St Thomas - Minnesota Printing Word Lengths – part 2 } else { // not white space // check for the start of a word // check for the start of a word if (state == OUT) { if (state == OUT) { cc = 1; state = IN; // handle text inside of a word // handle text inside of a word } else { } else { cc = cc + 1; }} i = i + 1; } while (in[i] != ‘\0’); printf(“ %d \n“, cc); }

2/22/ R. Smith - University of St Thomas - Minnesota Creative Commons License This work is licensed under the Creative Commons Attribution-Share Alike 3.0 United States License. To view a copy of this license, visit sa/3.0/us/ or send a letter to Creative Commons, 171 Second Street, Suite 300, San Francisco, California, 94105, USA.