lecture32-apr19 - Lecture 32 Announcements Read the rest of...

Info iconThis preview shows pages 1–2. Sign up to view the full content.

View Full Document Right Arrow Icon
1 Lecture 32 A nnouncements • Read the rest of Chapter 19 • Assignment 6 – Q&A; due Thursday – Checksum bytes might be swapped on your machine • Topics of the day – more C++ – Overloaded functions – C++ strings – Introduction to OO thinking – Classes 101 See www.cppreference.com for more info Introduction to C ++ Invented in the 1980’s to support modern programming principles - e.g. abstract data types It incorporates Standard C, but has additional capabilities Big differences – Class based – Object oriented – Templates – Overloaded operators – Exception handling Little differences – Keywords – IO – Strings – Booleans and wide characters – Call by reference – Explicit namespaces – Different way of doing dynamic storage allocation – One line comments // this for example Overloaded Function Names #include <iostream> using namespace std; // abs is overloaded three ways int abs(int i); double abs(double d); long abs(long l); int main() { cout << abs(-10) << endl; cout << abs(-11.0) << endl; cout << abs(-9L) << endl; return 0; } •Two or more functions can share the same name as long as their parameters are different •This makes the function call context sensitive int abs(int i) { cout << "Using integer abs()\n"; if ( i<0) return -i; else return i; } double abs(double d) { cout << "Using double abs()\n"; if ( d<0) return -d; else return d; } long abs(long l) { cout << "Using long abs()\n"; if ( l<0) return -l; else return l; } Strings About strings • An object is composed of values, and has associated functions that can operate on it • A string is an immutable object in C++. • A string literal is 0 or more characters enclosed in double quotes. "" is the empty or null string. • E.g. the string literal "Spanish Inquisition" The quotes are not a part of the string, they delineate the string. If the string is output the double quotes do not appear cout << "Spanish Inquisition"; Spanish Inquisition shows up on the std output device • string variables are declared and may be initialized, such as: string name = “Ned Logan”;
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Image of page 2
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 08/30/2010 for the course EE 312 taught by Professor Shafer during the Spring '08 term at University of Texas at Austin.

Page1 / 3

lecture32-apr19 - Lecture 32 Announcements Read the rest of...

This preview shows document pages 1 - 2. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online