C++ Programming for Non-C Programmers. Supplement
|
|
- Stewart Wilkerson
- 5 years ago
- Views:
Transcription
1 C++ Programming for Non-C Programmers Supplement
2 C++ Programming for Non-C Programmers C++ Programming for Non-C Programmers Published by ITCourseware, 7245 S. Havana St, Suite 100, Centennial, CO Contributing Authors: Jeff Howell, Danielle Waleri Editor: Danielle Waleri Assistant Editor: Ginny Jaranowski Special thanks to: Many instructors whose ideas and careful review have contributed to the quality of this workbook, including Evans Nash, and the many students who have offered comments, suggestions, criticisms, and insights. Copyright 2011 by ITCourseware, Inc. All rights reserved. No part of this book may be reproduced or utilized in any form or by any means, electronic or mechanical, including photocopying, recording, or by an information storage retrieval system, without permission in writing from the publisher. Inquiries should be addressed to ITCourseware, Inc., 7245 South Havana Street, Suite 100, Centennial, Colorado, (303) All brand names, product names, trademarks, and registered trademarks are the property of their respective owners. ii Rev ITCourseware, Inc.
3 Table of Contents Contents Chapter 1 - Course Introduction... 7 Course Objectives... 9 Course Overview Chapter 2 - Getting Started Chapter Objectives The First Program (hello.cpp) Compile Steps How to Compile and Run a Program Exercises Chapter 3 - Data Types and Variables Chapter Objectives Fundamental Data Types Data Type Values and Sizes Data Type Values and Sizes Variable Declarations Variable names Constants Character Constants String Constants Exercises Chapter 4 - Operators and Expressions Chapter Objectives What are expressions? Arithmetic Operators Relational Operators Assignment Operator Expressions have resulting values True and False Logical Operators Increment and Decrement Operators (++ and --) Increment and Decrement Operators: Examples 'Operate-Assign' Operators (+=, *=,...) ITCourseware, Inc. Rev iii
4 C++ Programming for Non-C Programmers Conditional Expression Operator Precedence Precedence and order of evaluation Evaluation of Logical Operators Type Conversions Type conversions (cont.) The cast operator Exercises Chapter 5 - Control Flow Chapter Objectives Statements if - else if() - else if() switch() Example: Switch() switch() (cont.) while() do - while() for() The for() loop - diagram Example: for() loop The break statement The continue statement Exercises Chapter 6 - Functions Chapter Objectives What is a function? Example: findbig3() Why use functions? Anatomy of a function Example: find_big_int() Arguments passed by value When to Use the return Statement Returning Non-integer Values Example: Returning Non-integer Values Functions in Multiple Source Files The Concept of Variable Scope Automatic Variables iv Rev ITCourseware, Inc.
5 Table of Contents Global (external) variables Example: Global Variables Static Variables External Static Variables Exercises Chapter 7 - Pointers and Arrays Chapter Objectives What is a pointer? Pointer Operators Example: pointers Why use pointers? Example Arrays: Arrays (a picture) The & Operator Pointers and arrays Passing arrays to functions Initializing arrays Strings and character pointers What is char s[7]??? Arrays of pointers Arrays of pointers - diagram Command-line arguments Exercises Chapter 8 - Structures Chapter Objectives Comparison of structures and arrays Structure definitions Structure declarations Arrays of structures Exercises ITCourseware, Inc. Rev v
6 C++ Programming for Non-C Programmers vi Rev ITCourseware, Inc.
7 Chapter 1 Course Introduction Chapter 1 - Course Introduction 2011 by ITCourseware, Inc
8 C++ Programming for Non-C Programmers Notes by ITCourseware, Inc
9 Chapter 1 Course Introduction Course Objectives Write applications using the C++ programming language. Use all of the basic syntax and semantics of the C and C++ languages. Write modular programs using functions. Use pointers and arrays to maintain data. Create classes that represent real-world objects with data and functionality. Inherit classes from existing classes to gain a reuse of functionality. Properly use references and constants to maintain data integrity and minimize errors. Write your own operators to work with the new data types that you create. Create template classes to avoid redundant coding and increase code reuse. Program object-oriented applications of moderate complexity by ITCourseware, Inc
10 C++ Programming for Non-C Programmers Notes by ITCourseware, Inc
11 Chapter 1 Course Introduction Course Overview Audience: This course is designed for programmers who want to move from procedural thinking to object-oriented programming using C++. Prerequisites: This course assumes that the student is an experienced professional programmer. Student Materials: Student workbook. A C++ text. Reference sheets. Classroom Environment: One terminal per student using the UNIX operating system, or a PC with a current C++ compiler by ITCourseware, Inc
12 C++ Programming for Non-C Programmers Notes by ITCourseware, Inc
13 Chapter 6 Functions Chapter 6 - Functions 2011 by ITCourseware, Inc
14 C++ Programming for Non-C Programmers Notes by ITCourseware, Inc
15 Chapter 6 Functions Chapter Objectives Understand the use of functions in program structure. Write modular programs consisting of functions. Pass data to functions by value and by reference. "Build" a program from multiple source files. Initialize variables at definition time. Understand the scope of variables. Know when to use global variables by ITCourseware, Inc
16 C++ Programming for Non-C Programmers Notes by ITCourseware, Inc
17 Chapter 6 Functions What is a function? A function is a set of instructions. A function may operate on data passed to it. A program "calls" a function, passing it data, if required. A function can be called with different data and from different places. A function can "return" data to its caller by ITCourseware, Inc
18 C++ Programming for Non-C Programmers Notes by ITCourseware, Inc
19 Chapter 6 Functions Example: findbig3() /* findbig3.cpp */ #include <iostream> using namespace std ; int find_big_3(int, int, int); int main(void) { int x,y,z; int largest; x = 10; y = 15; z = 12; largest = find_big_3(x, y, z); cout << "Largest: " << largest << endl; return 0; } /* int main(void) */ /* --- Function find_big_3 --- */ int find_big_3(int a, int b, int c) { int big; big = a > b? a : b; /* Bigger of a and b */ big = big > c? big : c; /* Bigger of big and c */ return big; } /* int find_big_3(int a, int b, int c) */ 2011 by ITCourseware, Inc
20 C++ Programming for Non-C Programmers Notes by ITCourseware, Inc
21 Chapter 6 Functions Why use functions? To design a program into modules. To perform the same instructions on different sets of data. To create a library of reusable tools by ITCourseware, Inc
22 C++ Programming for Non-C Programmers Notes by ITCourseware, Inc
23 Chapter 6 Functions Anatomy of a function void main(void) { int arg1; float arg2; char arg3; func(arg1, arg2, arg3); /* Three arguments passed */ func(100, , 'X'); /* Constants as arguments */ } /* void main(void) */ /* Function returns a float, takes three parameters */ float func(int p1, float p2, char p3) /* Arguments in calls to func agree with */ /* parameters in number and type. */ /* They need not be of same name. */ {... define any needed local variables... operate on parameters... calculate a result (the function s "return value") return 3.14F; }/* float func(int p1, float p2, char p3) */ 2011 by ITCourseware, Inc
24 C++ Programming for Non-C Programmers Notes by ITCourseware, Inc
25 Chapter 6 Functions Example: find_big_int() /* findbigi.cpp */ #include <iostream> using namespace std ; int find_big_int(int [], int); int main(void) { int a[5]; a[0] = 985; a[1] = 255; a[2] = 868; a[3] = 1105;; a[4] = 499; cout << "Biggest: " << find_big_int(a, 5) << endl; return 0; } /* int main(void) */ /* --- Function find_big_int --- */ int find_big_int(int a[], int num_elem) /* int a[] - Tells compiler that a is an array */ /* int num_elem - Size of array passed in */ { int i; /* Automatic local variables */ int big; big = a[0]; /* To start, assume first element is biggest */ cout << big << endl; for (i = 1; i < num_elem; i++) if (a[i] > big) { /* If i'th element is bigger, */ big = a[i]; /* then update big holder */ cout << big << endl; } return big; } /* int find_big_int(int a[], int num_elem) */ 2011 by ITCourseware, Inc
26 C++ Programming for Non-C Programmers Notes by ITCourseware, Inc
27 Chapter 6 Functions Arguments passed by value The data passed to a function are copies of the caller's actual data. Functions can use passed in variables, but can't change them. /* passval.cpp */ #include <iostream> using namespace std ; int passval(int); int main(void) { int x; x=99; cout << "x before call: " << x << endl; passval(x); cout << "x after call: " << x << endl; return 0; } /* int main(void) */ /* --- Function passval --- */ int passval(int a) { a = a * 10; return a; } /* int passval(int a) */ Program will print: x before call: 99 x after call: by ITCourseware, Inc
28 C++ Programming for Non-C Programmers Notes by ITCourseware, Inc
29 Chapter 6 Functions When to Use the return Statement Typically, use return when the function calculates and returns a single value. Use pass-by-reference when multiple values will be returned. In the second case, maybe you need more than one function by ITCourseware, Inc
30 C++ Programming for Non-C Programmers Notes by ITCourseware, Inc
31 Chapter 6 Functions Returning Non-integer Values By default, functions are assumed to return type int. If return value type is non-int, there must be two declarations: 1. The function type must be declared. 2. The calling function must declare the called function (usually in a prototype) by ITCourseware, Inc
32 C++ Programming for Non-C Programmers Notes by ITCourseware, Inc
33 Chapter 6 Functions Example: Returning Non-integer Values /* max3.cpp */ #include <iostream> using namespace std ; int main(void) { float one, two,three, big, max3(float, float, float); cout << "Enter three float values: "; cin >> one >> two >> three; big = max3(one, two, three); cout << "Big = " << big << endl; return 0; } /* int main(void) */ float max3(float a, float b, float c) { float big; big = a > b? a : b ; big = big > c? big : c ; return big; } /* float max3(float a, float b, float c) */ 2011 by ITCourseware, Inc
34 C++ Programming for Non-C Programmers Notes by ITCourseware, Inc
35 Chapter 6 Functions Functions in Multiple Source Files Functions can reside in separate source files. They are compiled separately then linked together to form the executable program: On Unix: CC main.cpp func1.cpp func2.cpp -o progname In an IDE: Add main.cpp, func1.cpp and func2.cpp to your project. Each file is compiled separately and automatically linked together to create the executable by ITCourseware, Inc
36 C++ Programming for Non-C Programmers Notes by ITCourseware, Inc
37 Chapter 6 Functions The Concept of Variable Scope Variables are "written to" and "read from". The scope of a variable is all the functions in a program that can access that variable. Variables can be automatic (local), global, static or extern by ITCourseware, Inc
38 C++ Programming for Non-C Programmers Notes by ITCourseware, Inc
39 Chapter 6 Functions Automatic Variables Are local to a function (including main()). Are accessible only to the function in which they are defined. Are created "automatically" each time the function is called. Memory locations that store automatic variables are deallocated upon function exit by ITCourseware, Inc
40 C++ Programming for Non-C Programmers Notes by ITCourseware, Inc
41 Chapter 6 Functions Global (external) variables Are defined outside of any function. Are available to all functions, even those compiled separately (by using the extern keyword). Provide an alternative to function arguments and return values for communicating between functions. Local variables with same name as global will prevail by ITCourseware, Inc
42 C++ Programming for Non-C Programmers Notes by ITCourseware, Inc
43 Chapter 6 Functions Example: Global Variables /* gcount.cpp */ #include <iostream> using namespace std ; void f(void); int count; /* Global variable */ int main(void) { count = 0; f(); /* Once */ f(); /* Twice */ f(); /* Thrice */ cout << "f called " << count << " times" << endl; return 0; } /* int main(void) */ void f(void) { count++; } /* void f(void) */ 2011 by ITCourseware, Inc
44 C++ Programming for Non-C Programmers Notes by ITCourseware, Inc
45 Chapter 6 Functions Static Variables Two uses for static (We'll see the second in a minute). Within a function, static variables retain their values "for next call" when a function exits. /* statv.cpp */ #include <iostream> using namespace std ; void statfunc(int); int main(void) { statfunc(10); statfunc(20); return 0; } /* int main(void) */ void statfunc(int i) { static hold = 0; cout << "Previous hold: " << hold << endl; hold = i; cout << "Current hold: " << hold << endl; } /* void statfunc(int i) */ 2011 by ITCourseware, Inc
46 C++ Programming for Non-C Programmers Notes by ITCourseware, Inc
47 Chapter 6 Functions External Static Variables External (defined outside any function) static variables are only accessible within that source file. Useful for preventing name conflicts between separately compiled modules. Because... identically named external statics in different files are different, not the same (huh?) by ITCourseware, Inc
48 C++ Programming for Non-C Programmers Notes by ITCourseware, Inc
49 Chapter 6 Functions Exercises 1. Write a program that reads four numbers from the keyboard and prints out the minimum, maximum, and average of the numbers. Define four separate float variables for the numbers. BE SURE to modularize the program into separate tasks that input the data, perform the calculations, and report the results. Do you think that an array version of this program would be better? 2. Starting with swmenu.cpp (from the previous chapter), create a menu-driven user interface for a program. Loop till the user chooses exit, and call a function for each switched choice. For now, just confirm to the user that the program entered the function. 3. Split the program from Exercise 1 into separately compilable source files, then compile and run the executable. 4. Write a simple program that calls a function which adds two floats and returns the sum by ITCourseware, Inc
50 C++ Programming for Non-C Programmers Notes by ITCourseware, Inc
C++ Programming for Non-C Programmers. Supplement
C++ Programming for Non-C Programmers Supplement ii C++ Programming for Non-C Programmers C++ Programming for Non-C Programmers Published by itcourseware, 10333 E. Dry Creek Rd., Suite 150, Englewood,
More informationCS2141 Software Development using C/C++ C++ Basics
CS2141 Software Development using C/C++ C++ Basics Integers Basic Types Can be short, long, or just plain int C++ does not define the size of them other than short
More information1- Write a single C++ statement that: A. Calculates the sum of the two integrates 11 and 12 and outputs the sum to the consol.
1- Write a single C++ statement that: A. Calculates the sum of the two integrates 11 and 12 and outputs the sum to the consol. B. Outputs to the console a floating point number f1 in scientific format
More informationAgenda. The main body and cout. Fundamental data types. Declarations and definitions. Control structures
The main body and cout Agenda 1 Fundamental data types Declarations and definitions Control structures References, pass-by-value vs pass-by-references The main body and cout 2 C++ IS AN OO EXTENSION OF
More informationMultiple Choice (Questions 1 13) 26 Points Select all correct answers (multiple correct answers are possible)
Name Closed notes, book and neighbor. If you have any questions ask them. Notes: Segment of code necessary C++ statements to perform the action described not a complete program Program a complete C++ program
More informationo Counter and sentinel controlled loops o Formatting output o Type casting o Top-down, stepwise refinement
Last Time Let s all Repeat Together 10/3/05 CS150 Introduction to Computer Science 1 1 We covered o Counter and sentinel controlled loops o Formatting output Today we will o Type casting o Top-down, stepwise
More informationMultiple Choice (Questions 1 14) 28 Points Select all correct answers (multiple correct answers are possible)
Name Closed notes, book and neighbor. If you have any questions ask them. Notes: Segment of code necessary C++ statements to perform the action described not a complete program Program a complete C++ program
More informationReview: Exam 1. Your First C++ Program. Declaration Statements. Tells the compiler. Examples of declaration statements
Review: Exam 1 9/20/06 CS150 Introduction to Computer Science 1 1 Your First C++ Program 1 //*********************************************************** 2 // File name: hello.cpp 3 // Author: Shereen Khoja
More informationScientific Computing
Scientific Computing Martin Lotz School of Mathematics The University of Manchester Lecture 1, September 22, 2014 Outline Course Overview Programming Basics The C++ Programming Language Outline Course
More informationComputer Science II Lecture 1 Introduction and Background
Computer Science II Lecture 1 Introduction and Background Discussion of Syllabus Instructor, TAs, office hours Course web site, http://www.cs.rpi.edu/courses/fall04/cs2, will be up soon Course emphasis,
More informationBy the end of this section you should: Understand what the variables are and why they are used. Use C++ built in data types to create program
1 By the end of this section you should: Understand what the variables are and why they are used. Use C++ built in data types to create program variables. Apply C++ syntax rules to declare variables, initialize
More informationIntroduction to C++ 2. A Simple C++ Program. A C++ program consists of: a set of data & function definitions, and the main function (or driver)
Introduction to C++ 1. General C++ is an Object oriented extension of C which was derived from B (BCPL) Developed by Bjarne Stroustrup (AT&T Bell Labs) in early 1980 s 2. A Simple C++ Program A C++ program
More informationName SECTION: 12:45 2:20. True or False (12 Points)
Name SECION: 12:45 2:20 rue or False (12 Points) 1. (12 pts) Circle for true and F for false: F a) Local identifiers have name precedence over global identifiers of the same name. F b) Local variables
More informationCHAPTER 4 FUNCTIONS. 4.1 Introduction
CHAPTER 4 FUNCTIONS 4.1 Introduction Functions are the building blocks of C++ programs. Functions are also the executable segments in a program. The starting point for the execution of a program is main
More informationC++ Basics. Data Processing Course, I. Hrivnacova, IPN Orsay
C++ Basics Data Processing Course, I. Hrivnacova, IPN Orsay The First Program Comments Function main() Input and Output Namespaces Variables Fundamental Types Operators Control constructs 1 C++ Programming
More informationIntroduction to Programming using C++
Introduction to Programming using C++ Lecture One: Getting Started Carl Gwilliam gwilliam@hep.ph.liv.ac.uk http://hep.ph.liv.ac.uk/~gwilliam/cppcourse Course Prerequisites What you should already know
More informationMultiple Choice (Questions 1 13) 26 Points Select all correct answers (multiple correct answers are possible)
Name Closed notes, book and neighbor. If you have any questions ask them. Notes: Segment of code necessary C++ statements to perform the action described not a complete program Program a complete C++ program
More informationGE U111 Engineering Problem Solving & Computation Lecture 6 February 2, 2004
GE U111 Engineering Problem Solving & Computation Lecture 6 February 2, 2004 Functions and Program Structure Today we will be learning about functions. You should already have an idea of their uses. Cout
More informationMultiple Choice (Questions 1 14) 28 Points Select all correct answers (multiple correct answers are possible)
Name Closed notes, book and neighbor. If you have any questions ask them. Notes: Segment of code necessary C++ statements to perform the action described not a complete program Program a complete C++ program
More informationCPE 112 Spring 2015 Exam III (100 pts) April 8, True or False (12 Points)
Name rue or False (12 Points) 1. (12 pts) Circle for true and F for false: F a) Local identifiers have name precedence over global identifiers of the same name. F b) Local variables retain their value
More informationProgramming - 1. Computer Science Department 011COMP-3 لغة البرمجة 1 لطالب كلية الحاسب اآللي ونظم المعلومات 011 عال- 3
Programming - 1 Computer Science Department 011COMP-3 لغة البرمجة 1 011 عال- 3 لطالب كلية الحاسب اآللي ونظم المعلومات 1 1.1 Machine Language A computer programming language which has binary instructions
More informationProgramming. C++ Basics
Programming C++ Basics Introduction to C++ C is a programming language developed in the 1970s with the UNIX operating system C programs are efficient and portable across different hardware platforms C++
More informationFast Introduction to Object Oriented Programming and C++
Fast Introduction to Object Oriented Programming and C++ Daniel G. Aliaga Note: a compilation of slides from Jacques de Wet, Ohio State University, Chad Willwerth, and Daniel Aliaga. Outline Programming
More informationDistributed Real-Time Control Systems. Lecture 17 C++ Programming Intro to C++ Objects and Classes
Distributed Real-Time Control Systems Lecture 17 C++ Programming Intro to C++ Objects and Classes 1 Bibliography Classical References Covers C++ 11 2 What is C++? A computer language with object oriented
More informationSRM ARTS AND SCIENCE COLLEGE SRM NAGAR, KATTANKULATHUR
SRM ARTS AND SCIENCE COLLEGE SRM NAGAR, KATTANKULATHUR 603203 DEPARTMENT OF COMPUTER SCIENCE & APPLICATIONS QUESTION BANK (2017-2018) Course / Branch : M.Sc CST Semester / Year : EVEN / II Subject Name
More informationFunctions in C++ Problem-Solving Procedure With Modular Design C ++ Function Definition: a single
Functions in C++ Problem-Solving Procedure With Modular Design: Program development steps: Analyze the problem Develop a solution Code the solution Test/Debug the program C ++ Function Definition: A module
More informationIntroduction to Algorithms and Programming (COMP151)
Introduction to Algorithms and Programming (COMP151) A Student's Manual for Practice Exercises Dr. Mohamed Aissa m.issa@unizwa.edu.om 11i13 Summer 2014 Practice Exercises #1 Introduction Page 2 Practice
More informationBash Programming. Student Workbook
Student Workbook Bash Programming Published by ITCourseware, LLC, 7245 South Havana Street, Suite 100, Englewood, CO 80112 Contributing Authors: Julie Johnson, Rob Roselius Editor: Jeff Howell Special
More informationIntroduction to Programming Using Java (98-388)
Introduction to Programming Using Java (98-388) Understand Java fundamentals Describe the use of main in a Java application Signature of main, why it is static; how to consume an instance of your own class;
More informationChapter 2 Basic Elements of C++
C++ Programming: From Problem Analysis to Program Design, Fifth Edition 2-1 Chapter 2 Basic Elements of C++ At a Glance Instructor s Manual Table of Contents Overview Objectives s Quick Quizzes Class Discussion
More informationChapter 6: User-Defined Functions. Objectives (cont d.) Objectives. Introduction. Predefined Functions 12/2/2016
Chapter 6: User-Defined Functions Objectives In this chapter, you will: Learn about standard (predefined) functions Learn about user-defined functions Examine value-returning functions Construct and use
More informationCS242 COMPUTER PROGRAMMING
CS242 COMPUTER PROGRAMMING I.Safa a Alawneh Variables Outline 2 Data Type C++ Built-in Data Types o o o o bool Data Type char Data Type int Data Type Floating-Point Data Types Variable Declaration Initializing
More informationUnit 6. Thinking with Functions
1 Unit 6 Thinking with Functions Function Decomposition 2 Functions Overview Functions (aka procedures, subroutines, or methods) are the unit of code decomposition and abstraction Map Service ValidateInputs()
More informationCS201- Introduction to Programming Current Quizzes
CS201- Introduction to Programming Current Quizzes Q.1 char name [] = Hello World ; In the above statement, a memory of characters will be allocated 13 11 12 (Ans) Q.2 A function is a block of statements
More information(5-1) Object-Oriented Programming (OOP) and C++ Instructor - Andrew S. O Fallon CptS 122 (February 4, 2019) Washington State University
(5-1) Object-Oriented Programming (OOP) and C++ Instructor - Andrew S. O Fallon CptS 122 (February 4, 2019) Washington State University Key Concepts 2 Object-Oriented Design Object-Oriented Programming
More informationUNIT- 3 Introduction to C++
UNIT- 3 Introduction to C++ C++ Character Sets: Letters A-Z, a-z Digits 0-9 Special Symbols Space + - * / ^ \ ( ) [ ] =!= . $, ; : %! &? _ # = @ White Spaces Blank spaces, horizontal tab, carriage
More informationTutorial 13 Salary Survey Application: Introducing One- Dimensional Arrays
Tutorial 13 Salary Survey Application: Introducing One- Dimensional Arrays Outline 13.1 Test-Driving the Salary Survey Application 13.2 Introducing Arrays 13.3 Declaring and Initializing Arrays 13.4 Constructing
More informationCSI33 Data Structures
Outline Department of Mathematics and Computer Science Bronx Community College October 24, 2018 Outline Outline 1 Chapter 8: A C++ Introduction For Python Programmers Expressions and Operator Precedence
More informationCSCE 110 PROGRAMMING FUNDAMENTALS
CSCE 110 PROGRAMMING FUNDAMENTALS WITH C++ Prof. Amr Goneid AUC Part 2. Overview of C++ Prof. Amr Goneid, AUC 1 Overview of C++ Prof. Amr Goneid, AUC 2 Overview of C++ Historical C++ Basics Some Library
More informationCS 376b Computer Vision
CS 376b Computer Vision 09 / 25 / 2014 Instructor: Michael Eckmann Today s Topics Questions? / Comments? Enhancing images / masks Cross correlation Convolution C++ Cross-correlation Cross-correlation involves
More informationW3101: Programming Languages C++ Ramana Isukapalli
Lecture-6 Operator overloading Namespaces Standard template library vector List Map Set Casting in C++ Operator Overloading Operator overloading On two objects of the same class, can we perform typical
More informationA First Program - Greeting.cpp
C++ Basics A First Program - Greeting.cpp Preprocessor directives Function named main() indicates start of program // Program: Display greetings #include using namespace std; int main() { cout
More informationQUIZ. 1. Explain the meaning of the angle brackets in the declaration of v below:
QUIZ 1. Explain the meaning of the angle brackets in the declaration of v below: This is a template, used for generic programming! QUIZ 2. Why is the vector class called a container? 3. Explain how the
More informationWhat we will learn about this week: Declaring and referencing arrays. arrays as function arguments. Arrays
What we will learn about this week: Declaring and referencing arrays Arrays in memory Initializing arrays indexed variables arrays as function arguments Arrays a way of expressing many of the same variable
More informationFunctions. CS111 Lab Queens College, CUNY Instructor: Kent Chin
Functions CS111 Lab Queens College, CUNY Instructor: Kent Chin Functions They're everywhere! Input: x Function: f Output: f(x) Input: Sheets of Paper Function: Staple Output: Stapled Sheets of Paper C++
More information1 Unit 8 'for' Loops
1 Unit 8 'for' Loops 2 Control Structures We need ways of making decisions in our program To repeat code until we want it to stop To only execute certain code if a condition is true To execute one segment
More informationDHA Suffa University CS 103 Object Oriented Programming Fall 2015 Lab #01: Introduction to C++
DHA Suffa University CS 103 Object Oriented Programming Fall 2015 Lab #01: Introduction to C++ Objective: To Learn Basic input, output, and procedural part of C++. C++ Object-orientated programming language
More informationWelcome Back. CSCI 262 Data Structures. Hello, Let s Review. Hello, Let s Review. How to Review 1/9/ Review. Here s a simple C++ program:
Welcome Back CSCI 262 Data Structures 2 - Review What you learned in CSCI 261 (or equivalent): Variables Types Arrays Expressions Conditionals Branches & Loops Functions Recursion Classes & Objects Streams
More informationExercise: Inventing Language
Memory Computers get their powerful flexibility from the ability to store and retrieve data Data is stored in main memory, also known as Random Access Memory (RAM) Exercise: Inventing Language Get a separate
More informationHomework #3 CS2255 Fall 2012
Homework #3 CS2255 Fall 2012 MULTIPLE CHOICE 1. The, also known as the address operator, returns the memory address of a variable. a. asterisk ( * ) b. ampersand ( & ) c. percent sign (%) d. exclamation
More informationOBJECT ORIENTED PROGRAMMING
OBJECT ORIENTED PROGRAMMING LAB 1 REVIEW THE STRUCTURE OF A C/C++ PROGRAM. TESTING PROGRAMMING SKILLS. COMPARISON BETWEEN PROCEDURAL PROGRAMMING AND OBJECT ORIENTED PROGRAMMING Course basics The Object
More informationC++ (Non for C Programmer) (BT307) 40 Hours
C++ (Non for C Programmer) (BT307) 40 Hours Overview C++ is undoubtedly one of the most widely used programming language for implementing object-oriented systems. The C++ language is based on the popular
More informationTopics. Functions. Functions
Topics Notes #8 Functions Chapter 6 1) How can we break up a program into smaller sections? 2) How can we pass information to and from functions? 3) Where can we put functions in our code? CMPT 125/128
More informationLab 2: Pointers. //declare a pointer variable ptr1 pointing to x. //change the value of x to 10 through ptr1
Lab 2: Pointers 1. Goals Further understanding of pointer variables Passing parameters to functions by address (pointers) and by references Creating and using dynamic arrays Combing pointers, structures
More informationName Section: M/W or T/TH. True or False (14 Points)
Name Section: M/W or T/TH True or False (14 Points) 1. (14 pts) Circle T for true and F for false: T F a) In C++, a function definition should not be nested within another function definition. T F b) Static
More informationIntroduction to C++ Systems Programming
Introduction to C++ Systems Programming Introduction to C++ Syntax differences between C and C++ A Simple C++ Example C++ Input/Output C++ Libraries C++ Header Files Another Simple C++ Example Inline Functions
More informationWelcome Back. CSCI 262 Data Structures. Hello, Let s Review. Hello, Let s Review. How to Review 8/19/ Review. Here s a simple C++ program:
Welcome Back CSCI 262 Data Structures 2 - Review What you learned in CSCI 261 (or equivalent): Variables Types Arrays Expressions Conditionals Branches & Loops Functions Recursion Classes & Objects Streams
More informationFundamentals of Programming CS-110. Lecture 2
Fundamentals of Programming CS-110 Lecture 2 Last Lab // Example program #include using namespace std; int main() { cout
More informationUniversity of Toronto
University of Toronto Faculty of Applied Science and Engineering Midterm November, 2010 ECE244 --- Programming Fundamentals Examiners: Tarek Abdelrahman, Michael Gentili, and Michael Stumm Instructions:
More informationIntroduction to Programming
Introduction to Programming session 6 Instructor: Reza Entezari-Maleki Email: entezari@ce.sharif.edu 1 Spring 2011 These slides are created using Deitel s slides Sharif University of Technology Outlines
More informationTokens, Expressions and Control Structures
3 Tokens, Expressions and Control Structures Tokens Keywords Identifiers Data types User-defined types Derived types Symbolic constants Declaration of variables Initialization Reference variables Type
More information2559 : Introduction to Visual Basic.NET Programming with Microsoft.NET
2559 : Introduction to Visual Basic.NET Programming with Microsoft.NET Introduction Elements of this syllabus are subject to change. This five-day instructor-led course provides students with the knowledge
More informationTEMPLATE IN C++ Function Templates
TEMPLATE IN C++ Templates are powerful features of C++ which allows you to write generic programs. In simple terms, you can create a single function or a class to work with different data types using templates.
More informationObjectives. Chapter 2: Basic Elements of C++ Introduction. Objectives (cont d.) A C++ Program (cont d.) A C++ Program
Objectives Chapter 2: Basic Elements of C++ In this chapter, you will: Become familiar with functions, special symbols, and identifiers in C++ Explore simple data types Discover how a program evaluates
More informationObject Oriented Design
Object Oriented Design Chapter 6 Example Activity Diagram 1 Outline Chapter 6 Topics 6.6 C++ Standard Library Header Files 6.14 Inline Functions 6.16 Default Arguments 6.17 Unary Scope Resolution Operator
More informationChapter 2: Basic Elements of C++
Chapter 2: Basic Elements of C++ Objectives In this chapter, you will: Become familiar with functions, special symbols, and identifiers in C++ Explore simple data types Discover how a program evaluates
More informationInput And Output of C++
Input And Output of C++ Input And Output of C++ Seperating Lines of Output New lines in output Recall: "\n" "newline" A second method: object endl Examples: cout
More informationChapter 2: Basic Elements of C++ Objectives. Objectives (cont d.) A C++ Program. Introduction
Chapter 2: Basic Elements of C++ C++ Programming: From Problem Analysis to Program Design, Fifth Edition 1 Objectives In this chapter, you will: Become familiar with functions, special symbols, and identifiers
More informationData Structures using OOP C++ Lecture 3
References: th 1. E Balagurusamy, Object Oriented Programming with C++, 4 edition, McGraw-Hill 2008. 2. Robert L. Kruse and Alexander J. Ryba, Data Structures and Program Design in C++, Prentice-Hall 2000.
More informationPointers. Variable Declaration. Chapter 10
Pointers Chapter 10 Variable Declaration When a variable is defined, three fundamental attributes are associated with it: Name Type Address The variable definition associates the name, the type, and the
More informationChapter 1 Introduction to Computers and C++ Programming
Chapter 1 Introduction to Computers and C++ Programming 1 Outline 1.1 Introduction 1.2 What is a Computer? 1.3 Computer Organization 1.7 History of C and C++ 1.14 Basics of a Typical C++ Environment 1.20
More informationC++ for Python Programmers
C++ for Python Programmers Adapted from a document by Rich Enbody & Bill Punch of Michigan State University Purpose of this document This document is a brief introduction to C++ for Python programmers
More informationFORM 1 (Please put your name and form # on the scantron!!!!) CS 161 Exam I: True (A)/False(B) (2 pts each):
FORM 1 (Please put your name and form # on the scantron!!!!) CS 161 Exam I: True (A)/False(B) (2 pts each): 1. The basic commands that a computer performs are input (get data), output (display result),
More information5. Assuming gooddata is a Boolean variable, the following two tests are logically equivalent. if (gooddata == false) if (!
FORM 2 (Please put your name and form # on the scantron!!!!) CS 161 Exam I: True (A)/False(B) (2 pts each): 1. Assume that all variables are properly declared. The following for loop executes 20 times.
More informationCOMP322 - Introduction to C++ Lecture 01 - Introduction
COMP322 - Introduction to C++ Lecture 01 - Introduction Robert D. Vincent School of Computer Science 6 January 2010 What this course is Crash course in C++ Only 14 lectures Single-credit course What this
More informationDiscussion 1H Notes (Week 3, April 14) TA: Brian Choi Section Webpage:
Discussion 1H Notes (Week 3, April 14) TA: Brian Choi (schoi@cs.ucla.edu) Section Webpage: http://www.cs.ucla.edu/~schoi/cs31 More on Arithmetic Expressions The following two are equivalent:! x = x + 5;
More informationB.V. Patel Institute of Business Management, Computer & Information Technology, Uka Tarsadia University
Unit 1 Programming Language and Overview of C 1. State whether the following statements are true or false. a. Every line in a C program should end with a semicolon. b. In C language lowercase letters are
More informationChapter 1 INTRODUCTION
Chapter 1 INTRODUCTION A digital computer system consists of hardware and software: The hardware consists of the physical components of the system. The software is the collection of programs that a computer
More informationC++ Programming: From Problem Analysis to Program Design, Third Edition
C++ Programming: From Problem Analysis to Program Design, Third Edition Chapter 2: Basic Elements of C++ Objectives (continued) Become familiar with the use of increment and decrement operators Examine
More informationIntroduction to C ++
Introduction to C ++ Thomas Branch tcb06@ic.ac.uk Imperial College Software Society October 18, 2012 1 / 48 Buy Software Soc. s Free Membership at https://www.imperialcollegeunion.org/shop/ club-society-project-products/software-products/436/
More informationWhy C++? C vs. C Design goals of C++ C vs. C++ - 2
Why C++? C vs. C++ - 1 Popular and relevant (used in nearly every application domain): end-user applications (Word, Excel, PowerPoint, Photoshop, Acrobat, Quicken, games) operating systems (Windows 9x,
More informationAdvanced UNIX Tools. Student Workbook
Student Workbook Advanced UNIX Tools Jeff Howell Published by ITCourseware, LLC, 7245 South Havana Street, Suite 100, Centennial, Colorado 80112 Contributing Authors: Jim McNally, Rob Roselius. Special
More information1. a) What #include statement do you put at the top of a program that does uses cin, cout or endl?
Exercises with solutions. 1. a) What #include statement do you put at the top of a program that does uses cin, cout or endl? #include b) What using statement do you always put at the top of
More informationScheme G. Sample Test Paper-I. Course Name : Computer Engineering Group Course Code : CO/CD/CM/CW/IF Semester : Second Subject Tile : Programming in C
Sample Test Paper-I Marks : 25 Time:1 Hrs. Q1. Attempt any THREE 09 Marks a) State four relational operators with meaning. b) State the use of break statement. c) What is constant? Give any two examples.
More informationCE221 Programming in C++ Part 1 Introduction
CE221 Programming in C++ Part 1 Introduction 06/10/2017 CE221 Part 1 1 Module Schedule There are two lectures (Monday 13.00-13.50 and Tuesday 11.00-11.50) each week in the autumn term, and a 2-hour lab
More informationBITG 1233: Introduction to C++
BITG 1233: Introduction to C++ 1 Learning Outcomes At the end of this lecture, you should be able to: Identify basic structure of C++ program (pg 3) Describe the concepts of : Character set. (pg 11) Token
More informationThe American University in Cairo Computer Science & Engineering Department CSCE 106 Fundamentals of Computer Science
The American University in Cairo Computer Science & Engineering Department CSCE 106 Fundamentals of Computer Science Instructor: Dr. Khalil Final Exam Fall 2012 Last Name :... ID:... First Name:... Form
More informationObjectives. In this chapter, you will:
Objectives In this chapter, you will: Become familiar with functions, special symbols, and identifiers in C++ Explore simple data types Discover how a program evaluates arithmetic expressions Learn about
More informationAbout Codefrux While the current trends around the world are based on the internet, mobile and its applications, we try to make the most out of it. As for us, we are a well established IT professionals
More informationIntroduction to C++ Introduction. Structure of a C++ Program. Structure of a C++ Program. C++ widely-used general-purpose programming language
Introduction C++ widely-used general-purpose programming language procedural and object-oriented support strong support created by Bjarne Stroustrup starting in 1979 based on C Introduction to C++ also
More informationLab Instructor : Jean Lai
Lab Instructor : Jean Lai Group related statements to perform a specific task. Structure the program (No duplicate codes!) Must be declared before used. Can be invoked (called) as any number of times.
More informationAN OVERVIEW OF C++ 1
AN OVERVIEW OF C++ 1 OBJECTIVES Introduction What is object-oriented programming? Two versions of C++ C++ console I/O C++ comments Classes: A first look Some differences between C and C++ Introducing function
More informationWeek 3. Function Definitions. Example: Function. Function Call, Return Statement. Functions & Arrays. Gaddis: Chapters 6 and 7.
Week 3 Functions & Arrays Gaddis: Chapters 6 and 7 CS 5301 Fall 2015 Jill Seaman 1 Function Definitions! Function definition pattern: datatype identifier (parameter1, parameter2,...) { statements... Where
More informationGovernment Polytechnic, Muzaffarpur. Name of the Lab: OBJECT ORIENTED PROGRAMMING
Government Polytechnic, Muzaffarpur. Name of the Lab: OBJECT ORIENTED PROGRAMMING THROUGH C++ Practical: OOPS THROUGH C++ Subject Code: 1618407 PROGRAM NO.1 Programming exercise on executing a Basic C++
More informationDr. Md. Humayun Kabir CSE Department, BUET
C++ Dr. Md. Humayun Kabir CSE Department, BUET History of C++ Invented by Bjarne Stroustrup at Bell Lab in 1979 Initially known as C with Classes Classes and Basic Inheritance The name was changed to C++
More informationCS 31 Discussion 1A, Week 4. Zengwen Yuan (zyuan [at] cs.ucla.edu) Humanities A65, Friday 10:00 11:50 a.m.
CS 31 Discussion 1A, Week 4 Zengwen Yuan (zyuan [at] cs.ucla.edu) Humanities A65, Friday 10:00 11:50 a.m. Today s focus Notes from the project 2 grading Function call predefined function define a function
More informationChapter 7 Array. Array. C++, How to Program
Chapter 7 Array C++, How to Program Deitel & Deitel Spring 2016 CISC 1600 Yanjun Li 1 Array Arrays are data structures containing related data items of same type. An array is a consecutive group of memory
More informationUnit 7. Functions. Need of User Defined Functions
Unit 7 Functions Functions are the building blocks where every program activity occurs. They are self contained program segments that carry out some specific, well defined task. Every C program must have
More informationCHAPTER 1 Introduction to Computers and Programming CHAPTER 2 Introduction to C++ ( Hexadecimal 0xF4 and Octal literals 031) cout Object
CHAPTER 1 Introduction to Computers and Programming 1 1.1 Why Program? 1 1.2 Computer Systems: Hardware and Software 2 1.3 Programs and Programming Languages 8 1.4 What is a Program Made of? 14 1.5 Input,
More informationObject-oriented Programming for Automation & Robotics Carsten Gutwenger LS 11 Algorithm Engineering
Object-oriented Programming for Automation & Robotics Carsten Gutwenger LS 11 Algorithm Engineering Lecture 3 Winter 2011/12 Oct 25 Visual C++: Problems and Solutions New section on web page (scroll down)
More information