Note: Some of the slides are repeated from Introduction to C++

Slides:



Advertisements
Similar presentations
C Language.
Advertisements

Introduction to C Programming
1 Chapter 2 Introduction to Java Applications Introduction Java application programming Display ____________________ Obtain information from the.
CMPUT 101 Lab # 5 October 22, :00 – 17:00.
Introduction: C Pointers Day 2 These Slides NOT From Text.
1 Gentle Introduction to Programming Tirgul 1: Shell and Scala “hands on” in the lab.
 2002 Prentice Hall. All rights reserved. 1 Chapter 2 – Introduction to Python Programming Outline 2.1 Introduction 2.2 First Program in Python: Printing.
1 Lab Session-III CSIT-120 Spring 2001 Revising Previous session Data input and output While loop Exercise Limits and Bounds GOTO SLIDE 13 Lab session.
C++ Introduction. Why Learn C++? Very powerful and respected prog. Lang. Very powerful and respected prog. Lang. Highly respected in Academics Highly.
Copyright 2003 Scott/Jones Publishing Brief Version of Starting Out with C++, 4th Edition Chapter 1 Introduction to Computers and Programming.
1 Chapter One A First Program Using C#. 2 Objectives Learn about programming tasks Learn object-oriented programming concepts Learn about the C# programming.
A First Program Using C#
Modular Programming Chapter Value and Reference Parameters t Function declaration: void computesumave(float num1, float num2, float& sum, float&
1 Documenting Your Project. 2 Documenting your Project Insert Banner Comments in your code Comment - coding statement used by humans not the compiler.
Copyright © 2012 Pearson Education, Inc. Publishing as Pearson Addison-Wesley C H A P T E R 2 Input, Processing, and Output.
Modular Programming Chapter Value and Reference Parameters computeSumAve (x, y, sum, mean) ACTUALFORMAL xnum1(input) ynum2(input) sumsum(output)
Chapter 3: Completing the Problem- Solving Process and Getting Started with C++ Introduction to Programming with C++ Fourth Edition.
Program A computer program (also software, or just a program) is a sequence of instructions written in a sequence to perform a specified task with a computer.
1 CS 101 Lecture 2. 2 Input from the Keyboard Here is a program to accept input from the keyboard and put into into two variables. #include main(){ cout.
Rossella Lau Lecture 1, DCO10105, Semester B, DCO10105 Object-Oriented Programming and Design  Lecture 1: Introduction What this course is about:
© Copyright 1992–2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. Chapter 2 Chapter 2 - Introduction to C Programming.
 Pearson Education, Inc. All rights reserved Introduction to Java Applications.
Dynamic Memory. We will follow different order from Course Book We will follow different order from Course Book First we will cover Sect The new.
An Introduction to Programming with C++ Sixth Edition Chapter 14 Sequential Access Files.
Control Structures (B) Topics to cover here: Sequencing in C++ language.
Agenda Perform Quiz #1 (20 minutes) Loops –Introduction / Purpose –while loops Structure / Examples involving a while loop –do/while loops Structure /
CSC 143A 1 CSC 143 Introduction to C++ [Appendix A]
Chapter 8 Arrays. A First Book of ANSI C, Fourth Edition2 Introduction Atomic variable: variable whose value cannot be further subdivided into a built-in.
© Copyright 1992–2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 1 Chapter 2 - Introduction to C Programming Outline.
The Hashemite University Computer Engineering Department
1 Project 3 String Methods. Project 3: String Methods Write a program to do the following string manipulations: Prompt the user to enter a phrase and.
Chapter 10: Working with Large Data Spreadsheet-Based Decision Support Systems Prof. Name Position (123) University Name.
Std Library of C++ Part 2. vector vector is a collection of objects of a single type vector is a collection of objects of a single type Each object in.
Inheritance - 3. Virtual Functions Functions defined as virtual are ones that the base expects its derived classes may redefine. Functions defined as.
CHAPTER 3 COMPLETING THE PROBLEM- SOLVING PROCESS AND GETTING STARTED WITH C++ An Introduction to Programming with C++ Fifth Edition.
Linux Administration Working with the BASH Shell.
CPSC 233 Tutorial January 21 st /22 nd, Linux Commands.
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.
C++ Programming: From Problem Analysis to Program Design, Fourth Edition Chapter 3: Input/Output Samples.
Introduction to Programming
Introduction to C Topics Compilation Using the gcc Compiler
Basic concepts of C++ Presented by Prof. Satyajit De
C++ Exceptions.
UMBC CMSC 104 – Section 01, Fall 2016
User-Written Functions
Chapter 2 Introduction to C++ Programming
Chapter 3 Assignment and Interactive Input.
Chapter 2 - Introduction to C Programming
Java Primer 1: Types, Classes and Operators
C++ Standard Library.
Chapter 2 Assignment and Interactive Input
CS314 – Section 5 Recitation 1
Algorithms Problem: Write pseudocode for a program that keeps asking the user to input integers until the user enters zero, and then determines and outputs.
Chapter 2 - Introduction to C Programming
Chapter 2 - Introduction to C Programming
CIS16 Application Development Programming with Visual Basic
Chapter 2 - Introduction to C Programming
Structured COBOL Programming
Programming Funamental slides
Introduction to C Topics Compilation Using the gcc Compiler
Introduction Paul Flynn
Chapter 2 - Introduction to C Programming
CIS16 Application Development and Programming using Visual Basic.net
Introduction to C Topics Compilation Using the gcc Compiler
Chapter 2 - Introduction to C Programming
C++ Introduction - 3.
Introduction to Programming and JavaScript
Std Library of C++.
Running a Java Program using Blue Jay.
C++ for Engineers and Scientists Second Edition
Presentation transcript:

Note: Some of the slides are repeated from Introduction to C++ Classes in C++ Introduction Note: Some of the slides are repeated from Introduction to C++

C++ Classes Covered in Section 1.5, 1.6, 2.8 We will do parts of section 2.8 first

C++ class C++ allows programmers (us) to define our own types (in addition to built-in types like int) These types are known as classes Variables can be defined for these classes just like variables for built-in data types like int

Variable/Object int v1; v1 is a variable of type int v1 is an object of type int

Sales_item class Provides the following operations: >> input operator to read a Sales_item object << output operator to write a Sales_item object + addition operator to add two Sales_item objects = assignment operator to assign one Sales_item object to another same_isbn() member function

Sales_item class - 2 These operations/functions of Sales_item are defined elsewhere and accessible to us using header file Sales_item.h Sales_item book; See 1/item_io.cc book is a variable of type Sales_item book is an object of type Sales_item book is an object of class Sales_item (common usage)

Sales_item Multiple objects can be defined of Sales_item Sales_item item1, item2, item3; 3 Sales_item objects have been created Each object will have its own data Similar to multiple variables/objects of built-in types.

struct vs class C++ class has all functionality of ‘C’ struct And has more functionality than struct Note that struct is supported in C++ also and further note that C++ struct is more powerful that C struct.

Type Safety C and C++ are type-safe languages Compiler knows data type of variables/objects and disallows inappropriate operations E.g. Passing a character pointer where a float argument is expected Type-safe languages force some amount of discipline on the programmer (otherwise – lots of compiler error and warning messages).

Object jargon Sales_item item; Based on the above code the following jargon can be used: item is an object of type Sales_item item is a Sales_item object item is a Sales_item This is similar to jargon used for variables/objects of built-in types

Member Functions See add_item2.cc in folder 1 A member function is a function defined (provided) by a class Member functions a.k.a. Methods Dot operator used to invoke member function in the context of an object item1.same_isbn(item2) same_isbn() method of item1 is called.

Addition operator Adding two Sales_item objects creates a new Sales_item object whose: ISBN is that of the operands Number sold and revenue reflects the sum of the corresponding values of the operands For input: [ISBN, no. sold, price of each] 0-201-78345 3 20.00 0-201-78345 2 25.00 Output is: [ISBN, no. sold, total revenue, average price] 0-201-78345 5 110 22

Running add_item2.exe Build programs in folder 1 by using command make Run add_item2.exe by: $ ./add_item2.exe Will prompt you for Sales_item data (ISBN, no. sold and price of each) Will print out sum

Running add_item2.exe - 2 You can run programs which use standard input (cin) against a data file by redirection Data file for add_item2.exe is data/add_item2 ./add_item2.exe < data/add_item2 Runs add_item2.exe with input taken from file data/add_item2

Redirecting output ./add_item2.exe < data/add_item2 > data/xyzsum Also redirects output to file data/xyzsum Be careful to choose file names different from that already in data Can copy folder 1 to a working directory and safely experiment cp –R src-folder dest-folder Command for recursive (folders and contained sub-folders) copy

Linux User Level Knowledge What are the commonly used Linux text based commands? How to become a power user? What are the commonly used GUI programs on Linux? Check out the Internet for the above

Exercises Copy folder 1 to a working directory ‘make’ the executables in that directory Run program add_item2 with keyboard data and file data Save output of program into a data file and view it. Read add_item2.cc and understand it Go through Linux reference guides for newbies

Think About - Exercise Exercise 1.24 (Section 1.5.2) Program reads several transactions For each new transaction determine if it is the same ISBN as previous transaction Keep a count of how many transactions there are for each ISBN Test program with test data (file) Test data should have multiple transactions with transactions for same ISBN grouped together

Exercise 1.24 & Assignment See avg_price.cc Assignment: Modify avg_price.cc to print individual transactions followed by total sales info (total sales info is as is already given by avg_price.cc) Test your solution with existing data (data/book_sales). If there are bugs in your program mention it as comments in your source code.

Read Course Book Chapters 1 and 2 of course book have been covered (barring few exceptions) Please read chapters 1 and 2 of course book

Book Source Code Copyright Note The course book is C++ Primer, 4th Edition by Lippman, Lajoie and Moo. Any references in earlier files to source files, and use of code within those files, are of example code given in and/or along with the book. As these slides are freely accessible on the Internet, not-for-profit, and for educational purposes, based on the permission related statements in the source code, I have considered that permission has been granted to use them in these slides.