General Computer Science for Engineers CISC 106 Lecture 32 Dr. John Cavazos Computer and Information Sciences 05/08/2009.

Slides:



Advertisements
Similar presentations
Lecture Computer Science I - Martin Hardwick Strings #include using namespace std; int main () { string word; cout
Advertisements

EC-111 Algorithms & Computing Lecture #7 Instructor: Jahan Zeb Department of Computer Engineering (DCE) College of E&ME NUST.
1 Arrays Chapter 9. 2 Outline  The array structure (Section 9.1)  Array declaration  Array initialization  Array subscripts  Sequential access to.
Dr. Yang, Qingxiong (with slides borrowed from Dr. Yuen, Joe) LT4: Control Flow - Loop CS2311 Computer Programming.
General Computer Science for Engineers CISC 106 Lecture 28 Dr. John Cavazos Computer and Information Sciences 04/29/2009.
1 11/3/08CS150 Introduction to Computer Science 1 Reading from and Writing to Files Section 3.12 & 13.1 & 13.5.
General Computer Science for Engineers CISC 106 Lecture 19 Dr. John Cavazos Computer and Information Sciences 04/06/2009.
General Computer Science for Engineers CISC 106 Lecture 35 Roger Craig Computer and Information Sciences 05/15/2009.
General Computer Science for Engineers CISC 106 Lecture 22 Dr. John Cavazos Computer and Information Sciences 04/13/2009.
Command-line arguments CS 201 Fundamental Structures of Computer Science.
1 10/20/08CS150 Introduction to Computer Science 1 do/while and Nested Loops Section 5.5 & 5.11.
1 9/1/06CS150 Introduction to Computer Science 1 What Data Do We Have? CS 150 Introduction to Computer Science I.
General Computer Science for Engineers CISC 106 Final Exam Review Dr. John Cavazos Computer and Information Sciences 05/18/2009.
General Computer Science for Engineers CISC 106 Lecture 31 Dr. John Cavazos Computer and Information Sciences 05/06/2009.
1 10/29/07CS150 Introduction to Computer Science 1 Reading from and Writing to Files Section 3.12 & 13.1 & 13.5.
General Computer Science for Engineers CISC 106 Lecture 08 Dr. John Cavazos Computer and Information Sciences 2/27/2009.
General Computer Science for Engineers CISC 106 Lecture 25 Dr. John Cavazos Computer and Information Sciences 04/20/2009.
1 10/9/06CS150 Introduction to Computer Science 1 for Loops.
General Computer Science for Engineers CISC 106 Lecture 34 Dr. John Cavazos Computer and Information Sciences 05/13/2009.
General Computer Science for Engineers CISC 106 Lecture 30 Dr. John Cavazos Computer and Information Sciences 05/04/2009.
General Computer Science for Engineers CISC 106 Lecture 33 Dr. John Cavazos Computer and Information Sciences 05/11/2009.
General Computer Science for Engineers CISC 106 Lecture 05 Dr. John Cavazos Computer and Information Sciences 2/20/2009.
General Computer Science for Engineers CISC 106 Lecture 23 Dr. John Cavazos Computer and Information Sciences 4/15/2009.
General Computer Science for Engineers CISC 106 Lecture 26 Dr. John Cavazos Computer and Information Sciences 04/24/2009.
1 10/25/06CS150 Introduction to Computer Science 1 Reading from and Writing to Files.
General Computer Science for Engineers CISC 106 Lecture 18 Dr. John Cavazos Computer and Information Sciences 3/27/2009.
Computer Science 1620 Lifetime & Scope. Variable Lifetime a variable's lifetime is finite Variable creation: memory is allocated to the variable occurs.
ECE 264 Object-Oriented Software Development Instructor: Dr. Honggang Wang Fall 2012 Lecture 4: Continuing with C++ I/O Basics.
CSE 2341 Honors Professor Mark Fontenot Southern Methodist University Note Set 04.
Engineering H192 - Computer Programming Gateway Engineering Education Coalition Lect 25P. 1Winter Quarter C++: I/O and Classes Lecture 25.
1 CS161 Introduction to Computer Science Topic #3.
C ++ Basics by Bindra Shrestha sce.uhcl.edu/shresthab CSCI 3333 Data Structures.
File I/O in C++ II. Open() function Open() is a member function in each classes ( fstream, ifstream, ofstream) Void fstream :: open ( const char *filename,
CSC1201: Programming Language 2 Lecture 1 Level 2 Course Nouf Aljaffan (C) CSC 1201 Course at KSU1.
A first program 1. #include 2. using namespace std; 3. int main() { 4. cout
Quiz // // The function exchanges the two parameters. // Param: ( ) // Param:
Chapter 3 Functions. 2 Overview u 3.2 Using C++ functions  Passing arguments  Header files & libraries u Writing C++ functions  Prototype  Definition.
Modular Programming – User Defined Functions. CSCE 1062 Outline  Modular programming – user defined functions  Value returning functions  return statement.
General Computer Science for Engineers CISC 106 Lecture 12 James Atlas Computer and Information Sciences 08/03/2009.
1 Manipulators manipulators are used only in input and output statements endl, fixed, showpoint, setw, and setprecision are manipulators that can be used.
C++ Programming Lecture 19 Strings The Hashemite University Computer Engineering Department (Adapted from the textbook slides)
12/14/2016CS150 Introduction to Computer Science 1 Announcements  Website is up!   All lecture slides, assignments,
Arrays Chapter 12. Overview Arrays and their properties Creating arrays Accessing array elements Modifying array elements Loops and arrays.
Arrays Chapter 7. Arrays Hold Multiple Values Array: variable that can store multiple values of the same type Values are stored in adjacent memory locations.
C++ Programming Lecture 14 Arrays – Part I The Hashemite University Computer Engineering Department (Adapted from the textbook slides)
1 Structure of Simple C++ Program Chapter 1 09/09/13.
Lecture 9 – Array (Part 2) FTMK, UTeM – Sem /2014.
ECE 264 Object-Oriented Software Development Instructor: Dr. Honggang Wang Fall 2012 Lecture 19: Container classes; strings.
General Computer Science for Engineers CISC 106 Lecture 27 Dr. John Cavazos Computer and Information Sciences 04/27/2009.
CISC220 Spring 2010 James Atlas Lecture 04: Pointers, Functions, Memory Management, ADTs, Classes, Hardware, Software, Graphics, Networking, AI, Databases,
Review 1.
Topic Pre-processor cout To output a message.
Command Line Arguments
Detailed File I/O Examples Focus on Input
Chapter 2 – Getting Started
Intro to Programming Week # 4 Control Structure Lecture # 8
C++ fundamentals Lecture 1, Chapter 2 – pp /22/2018 Y K Choi.
CS150 Introduction to Computer Science 1
Control Structures Part 2
Engineering Problem Solving with C++ An Object Based Approach
Engineering Problem Solving with C++ An Object Based Approach
Reading from and Writing to Files
Put the title here Here is the sub-title.
Put the title here Here is the sub-title.
Strings Skill Area 313 Part C
General Computer Science for Engineers CISC 106 Lecture 03
Introduction to Programming - 1
File I/O in C++ II.
Reading from and Writing to Files Part 2
Reading from and Writing to Files
Presentation transcript:

General Computer Science for Engineers CISC 106 Lecture 32 Dr. John Cavazos Computer and Information Sciences 05/08/2009

Lecture Overview More Project 2 hints C++ while loops

Project 2 Hints Several ways to read in a file High Level: textscan, tdfread, textread Low Level: fscanf An example using textread

Songs.txt file Columns separated by tabs (tab-delimited) songs.txt Title Artist Year 2WickyHooverphonic Keith 1967 …

Using textread Need to give format specifier Note: All on same line Can use ellipsis (…) to continue line on next line [title artist year] = textread('songs.txt', '%s %s %d', 'headerlines', 1, 'delimiter','\t')

Using textread [title artist year] = textread('songs.txt', '%s %s %d', 'headerlines', 1, 'delimiter','\t') Calling textread with name of songs file.

Using textread [title artist year] = textread('songs.txt', '%s %s %d', 'headerlines', 1, 'delimiter','\t') Format specifier. Expects: 1 st field → string 2 nd field → string 3 rd field → integer

Using textread [title artist year] = textread('songs.txt', '%s %s %d', 'headerlines', 1, 'delimiter','\t') 1 st line is a header line and text fields separated by tabs (delimited)

Using textread [title artist year] = textread('songs.txt', '%s %s %d', 'headerlines', 1, 'delimiter','\t') textread returns three arrays. Types of arrays based on format specifier.

Textread returns three arrays [title artist year] = … title = '2Wicky’ '98.6’ '#9 Dream’ 'ABC’ artist = 'Hooverphonic’ 'Keith’ 'John Lennon’ 'Jackson 5’ …

Looping through Title array for j = 1:length(title) title(j) end ans = '2Wicky’ ans = '98.6’ …

Put data in structure array S=struct('title',{}, 'artist',{}, 'year',{}); S(1).title = char(title(1)); S(1).artist = char(artist(1)); S(1).year = year(1); S(1).artist ans = 'Hooverphonic'

Put data in structure array S=struct('title',{}, 'artist',{}, 'year',{}); S(1).title = char(title(1)); S(1).artist = char(artist(1)); S(1).year = year(1); S(1).artist ans = 'Hooverphonic' Create an empty structure

Put data in structure array S=struct('title',{}, 'artist',{}, 'year',{}); S(1).title = char(title(1)); S(1).artist = char(artist(1)); S(1).year = year(1); S(1).artist ans = 'Hooverphonic' Put first element of each array into structure; char(…) converts the cell array of strings to a character array to work with strlexcmp.

C++ while loop … // main function int j = 1; while (j < 3) { cout << “value of j is : “ << j << endl; j=j+1; // can also use j++; }

C++ while loop … // main function int j = 1; while (j < 3) { cout << “value of j is : “ << j << endl; j=j+1; // can also use j++; } Loops while j less then 3

C++ while loop … // main function int j = 1; while (j < 3) { cout << “value of j is : “ << j << endl; j=j+1; // can also use j++; } Body of loop; executed 2 times

C++ Functions: Putting all together #include using namespace std; int main() int height = 0, maxheight = 0; cout << "Enter heights: (enter end of file to end): "; // rest on next slide

C++ Functions: Putting all together // cont’d from last slide while(cin >> height) { if( height > maxheight) maxheight = height; } cout << "Tallest person's height = " << maxheight << endl; return 0; }