C++ File Structure and Intro to the STL

Slides:



Advertisements
Similar presentations
. STL: C++ Standard Library (continued). STL Iterators u Iterators are allow to traverse sequences u Methods  operator*  operator->  operator++, and.
Advertisements

Current Assignments Homework 5 will be available tomorrow and is due on Sunday. Arrays and Pointers Project 2 due tonight by midnight. Exam 2 on Monday.
Lesson 10 Characters, C-Strings, and the string Class CS1 Lesson John Cole1.
Chapter 10.
CS31: Introduction to Computer Science I Discussion 1A 4/2/2010 Sungwon Yang
C++ crash course Class 3 designing C++ programs, classes, control structures.
C++ Programming Language Day 1. What this course covers Day 1 – Structure of C++ program – Basic data types – Standard input, output streams – Selection.
Input & Output: Console
Rossella Lau Lecture 1, DCO10105, Semester B, DCO10105 Object-Oriented Programming and Design  Lecture 1: Introduction What this course is about:
CECS 121 Test 1. Functions allow you to group program statements under one name C and C++ are case-sensitive so main(), MAIN(), and Main() are all different.
C ++ Basics by Bindra Shrestha sce.uhcl.edu/shresthab CSCI 3333 Data Structures.
COP 3530 Data Structures & Algorithms Discussion Session 3.
L function n predefined, programmer-defined l arguments, (formal) parameters l return value l function call, function invocation l function definition.
An Introduction to STL. The C++ Standard Template Libraries  In 1990, Alex Stepanov and Meng Lee of Hewlett Packard Laboratories extended C++ with a.
CSC1201: Programming Language 2 Lecture 1 Level 2 Course Nouf Aljaffan (C) CSC 1201 Course at KSU1.
C++ Basics. Compilation What does compilation do? g++ hello.cpp g++ -o hello.cpp hello.
Chapter 15 Strings as Character Arrays
Chapter Characters, Strings, and the string class 10.
CSE 332: C++ template examples Today: Using Class and Function Templates Two examples –Function template for printing different types –Class template for.
Lecturer: Nguyen Thi Hien Software Engineering Department Home page: hienngong.wordpress.com Chapter 2: Language C++
1 ENERGY 211 / CME 211 Lecture 3 September 26, 2008.
1 Chapter 12 Classes and Abstraction. 2 Chapter 12 Topics Meaning of an Abstract Data Type Declaring and Using a class Data Type Using Separate Specification.
Bill Tucker Austin Community College COSC 1315
Introduction to olympic programming
Chapter 12 Classes and Abstraction
C++ CSCE 343.
C++ Lesson 1.
Chapter 13 Introduction to C++ Language
A CLASS CONSISTS OF VARIABLES,
What Is? function predefined, programmer-defined
Template Classes and Functions
Introduction to C++ Systems Programming.
C++ in 90 minutes.
Characters, C-Strings, and More About the string Class
CMPE Data Structures and Algorithms in C++ February 22 Class Meeting
Standard Version of Starting Out with C++, 4th Edition
Multiple Files Revisited
C++ Functions, Classes, and Templates
C Stuff CS 2308.
CS 2308 Exam I Review.
Chapter 9 One-Dimensional Arrays
Chapter 11 - Templates Outline Introduction Function Templates Overloading Function Templates Class Templates Class.
10.1 Character Testing.
Standard Input/Output Stream
C++ Testing and Classes
Summary Two basic concepts: variables and assignments Basic types:
Classes.
Chapter 11 - Templates Outline Introduction Function Templates Overloading Function Templates Class Templates Class.
Standard Template Library (STL)
C++ Pointers and Strings
Lecture 8-2 : STL Iterators and Algorithms
Standard Version of Starting Out with C++, 4th Edition
COP 3330 Object-oriented Programming in C++
Fundamental Programming
C++ File Structure and Intro to the STL
Chapter 11 - Templates Outline Introduction Function Templates Overloading Function Templates Class Templates Class.
C++ Programming Lecture 20 Strings
C++ Testing and Classes
STL and Example.
What Is? function predefined, programmer-defined
Today’s Objectives 28-Jun-2006 Announcements
Chapter 11 - Templates Outline Introduction Function Templates Overloading Function Templates Class Templates Class.
An Introduction to STL.
C++ Pointers and Strings
COP 3330 Object-oriented Programming in C++
SPL – PS1 Introduction to C++.
Chapter 12: More on C-Strings and the string Class
More on C++ G Carl Evans.
Presentation transcript:

C++ File Structure and Intro to the STL G Carl Evans

C Variable Definitions int i = 0; double radius = 6.5; const double kPi = 3.14159; int students_per_lecture[] = {155,121}; char *program_name = argv[0]; std::vector<double> grade_cutoffs = {0.9,0.8,0.7}; Monster cs126_prof; Room dcl_1320;

C++ Bool and Bool Experssion fundamental type this will hold either true or false true This has the value of 1 false This has the value of 0 A nonzero value will be coerced to true A zero value will be coerced to false

Standard Loops in C++ while(boolexpr){ body } for(intitialize; boolexpr; reloop){ for(range_decl : range_expr){ do{ }while(boolexpr)

Standard Branching if(boolexpr) { } else if (boolexpr) { } else { }

How hard was third code review assignment? Easy Moderate Challenging Unreasonable

How long did third assignment take? Less than 3 hours 3 to 6 hours 6 to 9 hours 9 to 12 hours More than 12 hours

C++ function definitions and declarations Function Declarations Function Definitions int TimesTwo(int x); int TimesTwo(int x) { return x * 2; }

C++ File Stucture Two file types .cpp .h This is the file type that contains the definitions and code. .h This is the file type that contains declarations.

Using header files #include <iostream> #include <vector> #include <stdlib.h> #include "libmult.h"

Writing Header Files #ifndef LIBMULT_H #define LIBMULT_H //declarations here #endif

C++ Strings C – strings <string> C++ being based on C supports C style strings using char * A pointer to an array of bytes terminated by a null byte <string> This class provides a modern string interface to replace the C style stings string1 == string2 compares strings not pointers via overloading Supports modification using methods including insert, erase, and push_back Supports STL interfaces

C++ Libraries – I/O <iostream> cout << "thing to print"; Prints all the fundamental types Prints string variables Can be extended to print other types cin >> variable; Reads input from standard input Parses all fundamental types Spaces separate different inputs Will read words into string variables White space separates inputs and input is read with enter

C++ STL The Standard Template Library C++ library parameterized by types similar to Java generics Containers Iterators Algorithms Functions

C++ Libraries – Variable Length Arrays <vector>

C++ Libraries – Dictionary or Associative Array <map> or <unorderd_map>

Things start doing Get C++ (Xcode/Visual Studio/gcc) Make a helloworld.cpp program and build it.