What have we learned so far… Preprocessor directives Introduction to C++ Variable Declaration Display Messages on Screen Get Information from User Performed.

Slides:



Advertisements
Similar presentations
Lecture 2 Introduction to C Programming
Advertisements

Introduction to C Programming
Introduction to C Programming
 Pearson Education, Inc. All rights reserved Introduction to Classes and Objects.
 2006 Pearson Education, Inc. All rights reserved Introduction to Classes and Objects.
 2006 Pearson Education, Inc. All rights reserved Introduction to Classes and Objects.
Classes and Objects Systems Programming.
 2006 Pearson Education, Inc. All rights reserved Midterm review Introduction to Classes and Objects.
 2007 Pearson Education, Inc. All rights reserved Introduction to C Programming.
 2008 Pearson Education, Inc. All rights reserved Introduction to Classes and Objects.
 2008 Pearson Education, Inc. All rights reserved Introduction to Classes and Objects.
 2006 Pearson Education, Inc. All rights reserved Introduction to Classes and Objects.
Chapter Objectives You should be able to describe: Object-Based Programming Classes Constructors Examples Common Programming Errors.
 2006 Pearson Education, Inc. All rights reserved Introduction to Classes and Objects.
Introduction to Classes and Objects CS-2303, C-Term Introduction to Classes and Objects CS-2303 System Programming Concepts (Slides include materials.
Chapter 7. 2 Objectives You should be able to describe: The string Class Character Manipulation Methods Exception Handling Input Data Validation Namespaces.
Introduction to C Programming
1 Classes and Objects. 2 Outlines Class Definitions and Objects Member Functions Data Members –Get and Set functions –Constructors.
CSCI 1730 January 17 th, 2012 © by Pearson Education, Inc. All Rights Reserved.
CSM-Java Programming-I Spring,2005 Introduction to Objects and Classes Lesson - 1.
 2003 Prentice Hall, Inc. All rights reserved. 1 Introduction to Classes and Objects Outline Introduction Classes, Objects, Member Functions and Data.
Reformatted slides from the textbook, C++ How to Program, 6/e Pearson Education, Inc. All rights reserved Chapter 3. [Lecture 01] Introduction to.
Nirmalya Roy School of Electrical Engineering and Computer Science Washington State University Cpt S 122 – Data Structures Introduction to C++ Part II.
You gotta be cool. Introduction to Classes, Objects and Strings Introduction Defining a Class with a Member Function Defining a Member Function with a.
1.  A method describes the internal mechanisms that actually perform its tasks  A class is used to house (among other things) a method ◦ A class that.
C++ How to Program, 7/e © by Pearson Education, Inc. All Rights Reserved.
C++ How to Program, 7/e © by Pearson Education, Inc. All Rights Reserved.
ECE 264 Object-Oriented Software Development Instructor: Dr. Honggang Fall 2012 Lecture 8: File I/O; Introduction to classes.
Reformatted slides from the textbook, C++ How to Program, 6/e Pearson Education, Inc. All rights reserved Chapter 3. [Lecture 02] Introduction to.
Java™ How to Program, 10/e © Copyright by Pearson Education, Inc. All Rights Reserved.
Classes In C++ 1. What is a class Can make a new type in C++ by declaring a class. A class is an expanded concept of a data structure: instead of holding.
Built-In and user-Defined functions Software Design Concepts Lecture IV Dr. Sothy Vignarajah.
Chapter 4 Introduction to Classes, Objects, Methods and strings
Chapter 3 Part I. 3.1 Introduction Programs written in C ◦ All statements were located in function main Programs written in C++ ◦ Programs will consist.
Chapter 3 (B) 3.5 – 3.7.  Variables declared in a function definition’s body are known as local variables and can be used only from the line of their.
1 CSC241: Object Oriented Programming Lecture No 02.
 2006 Pearson Education, Inc. All rights reserved Introduction to Classes and Objects.
 2008 Pearson Education, Inc. All rights reserved Introduction to Classes and Objects.
 2008 Pearson Education, Inc. All rights reserved Introduction to Classes and Objects.
ECE 264 Object-Oriented Software Development Instructor: Dr. Honggang Wang Fall 2012 Lecture 9: Continuing with classes.
2 Objectives You should be able to describe: Object-Based Programming Classes Constructors Examples Common Programming Errors.
Chapter 3 Functions. 2 Overview u 3.2 Using C++ functions  Passing arguments  Header files & libraries u Writing C++ functions  Prototype  Definition.
 2008 Pearson Education, Inc. All rights reserved Introduction to Classes and Objects.
Classes Methods and Properties. Introduction to Classes and Objects In object-oriented programming terminology, a class is defined as a kind of programmer-defined.
計算機程式語言 Lecture 03-1 國立台灣大學生物機電系 林達德 3 3 Introduction to Classes and Objects.
 2005 Pearson Education, Inc. All rights reserved. 1 Introduction to Classes and Objects.
 2005 Pearson Education, Inc. All rights reserved Introduction to Classes and Objects.
A FIRST BOOK OF C++ CHAPTER 14 THE STRING CLASS AND EXCEPTION HANDLING.
 2003 Prentice Hall, Inc. All rights reserved Basics of a Typical C++ Environment C++ systems –Program-development environment –Language –C++
Class & Objects C++ offers another user-defined data type known class which is the most important feature of the object-oriented programming. A class can.
C++ How to Program, 8/e © by Pearson Education, Inc. All Rights Reserved.
 2005 Pearson Education, Inc. All rights reserved Introduction to Classes and Objects.
C++ How to Program, 8/e © by Pearson Education, Inc. All Rights Reserved. Note: C How to Program, Chapter 16 is a copy of C++ How to Program Chapter.
Chapter 3 Introduction to Classes, Objects and Strings C++ How to Program, 9/e ©2016 by Pearson Education, Inc., Hoboken, NJ. All Rights Reserved. Instructor.
Introduction to Classes and Objects CS-2303, C-Term C++ Program Structure Typical C++ Programs consist of:– main –A function main –One or more classes.
1 Lecture 2 - Introduction to C Programming Outline 2.1Introduction 2.2A Simple C Program: Printing a Line of Text 2.3Another Simple C Program: Adding.
Introduction to Classes and Objects
3 Introduction to Classes and Objects.
Chapter 3 Introduction to Classes, Objects and Strings
Yanal Alahmad Java Workshop Yanal Alahmad
Chapter 3 Introduction to Classes, Objects Methods and Strings
Chapter 3 Introduction to Classes, Objects Methods and Strings
Introduction to Classes and Objects
Classes, Objects, Methods and Strings
7 Arrays.
Object Oriented Programming in java
Introduction to Classes and Objects
EECE.3220 Data Structures Instructor: Dr. Michael Geiger Spring 2019
Classes and Objects Systems Programming.
Introduction to Classes and Objects
Presentation transcript:

What have we learned so far… Preprocessor directives Introduction to C++ Variable Declaration Display Messages on Screen Get Information from User Performed Calculations Made decisions

From now on, our programs will include not only a main function, but also one or more classes, each containing data members and member functions. Now we enter object- oriented programming

Our code, when fully developed will represent a grade book that a teacher can use to record and organize student test scores. Our main function will create the GradeBook object which is a class. The member function of the GradeBook class we will use today is called displayMessage Before the main function can create a GradeBook object, the member functions and data members that belong to the GradeBook class must be defined. Class definition is accomplished the keyword, class, followed by the class name, GradeBook. Data members are the objects kept track of inside the class. Every class’s body is enclosed in a pair of left and right French braces. {} The class definition ends with a semicolon ; NOTE: this is a common syntax error – forgetting the semicolon!

Naming conventions: User-defined class begins with a capital letter and each following word in the class name is capitalized -> GradeBook Member function names begin with a lowercase first letter, with following words capitalized -> displayMessage Access specifiers -> always followed by a colon : public /*member functions appearing after this specifier can be called by other functions */ private /* only accessible to member functions of the class in which they are declared, also called “data hiding”*/ protected Return types -> void //function does not return a value int // function returns an integer value

Defining a Member Function with a Parameter Let’s talk about cars…

A function call needs values, called arguments, for each of the parameters, the function will use! Each function header needs both a type and a name. New class, a variable type called string, is actually a class defined in #include This class is also part of namespace std! The initial value of a string is the empty string.

Why getline instead of cin?? cin reads characters until the first white- space character is reached. The function call from getline(cin, nameOfCourse) reads characters including spaces until the newline character is found. (The newline character is not stored in nameOfCourse.)

Function Parameter list: Can be no parameters at all, or several! Each parameter specifies a type and an identifier. For our example, type string and identifier courseName. The parameter variable’s name (courseName) can be the same or different from the argument variable’s name (nameOfCourse).

Variables declared in a function definition’s body are known as local variables, and can only be used in the function! When the function terminates, the local variables’ values are lost. A class normally has one or more member functions that manipulate the attributes of that class’s objects. These attributes are called data members and are declared inside a classes definition. The :: operator is called the binary scope resolution operator. A local variable is declared in the body of a function and can only be used inside that function. A data member is declared in a class, but not in the body of any of the class’s member functions. Every object of a class has a separate copy of the class’s data members. Data members are accessible to all member functions of the class. A parameter represents more information that the function needs to do its work! Each parameter that a function needs is stated in the function header. An argument is the value supplied to the function call. When the function is called, the argument value is passed into the function parameter so that the function can do its thing.