Basics of C++ C++ Overview Elements I / O Assignment and Comments Formatted Output. Dr.Hamed Bdour

Size: px
Start display at page:

Download "Basics of C++ C++ Overview Elements I / O Assignment and Comments Formatted Output. Dr.Hamed Bdour"

Transcription

1 Basics of C++ C++ Overview Elements I / O Assignment and Comments Formatted Output 1

2 History of C and C++ BCPL 1967 By Martin Richards Lang. to write OS NO Data Type + B :By Ken Thompson Used to create early Bell lab's 1970 NO Data Type C :By Dennis Bell lab s -UNIX written in C -HW Independent -many versions in late 1970 s OO Features + Standard ANSI C In 1980 was approved OO Features + + C++: By Bjarne Stroustrap Early Bell lab s Provides OO programming 2 Java: In 1995 by Sun Microsystems

3 Structure of C++ program Every C++ program must have a function named main. The programmer can choose to decompose the program into several parts (user-defined functions). Think of main as the master and the other functions are the servants. The execution always starts with main. Preprocessor Directive Type of returned value Marks the start of the main function (program) #include <iostream.h> int main( ) { Declarations ; Executable Statement_1 ; Executable Statement_2 ; : Executable Statement_n ; Header file facilitate I/O } return 0; Marks the end of the main function (program) 3 Returning 0 means every things is OK else(1,2,..) something went wrong (Exit Status)

4 1 // Fig. 1.2: fig01_02.cpp 2 // A first program in C++ 3 #include <iostream.h> 4 5 int main() 6 { 7 cout << "Welcome to C++!\n"; 8 Comments Written between /* and */ or following a //. Improve program readability and do not cause the computer to perform any action. preprocessor directive Message to the C++ preprocessor. Lines beginning with # are preprocessor directives. #include <iostream.h> tells the preprocessor to include the contents of the file <iostream.h>, which includes input/output operations (such as printing to the screen). 9 } Welcome to C++! C++ programs contain one or more functions, one of which must be main Parenthesis are used to indicate a function int means that main "returns" an integer value. 1. Comments 2. Load <iostream.h> 3. main 3.1 Print "Welcome to C++\n" exit (return 0) Prints the string of characters contained between the quotation marks. The entire line, including cout, the << operator, the string "Welcome to C++!\n" and the semicolon (;), is called a statement. All statements must end with a semicolon. A left brace { begins the body of every function and a right brace } ends it.

5 Naming Identifiers First character must be letter a-z, A-Z or _ Other characters letters (a-z, A-Z, _ ) or digits 0-9 Cannot use C++ keywords (reserved words) Cannot have blank within identifies Keep length to 31 characters Older compiler restriction Declaring Variables Variables MUST be declared List name and data type Variables of same type may be declared in same statement (separate by comma) Causes C++ compiler to know size of space to be reserved for storing variable s value 5

6 Variable Names (Identifiers) Letter + {Letters and/or Digits and/or ( _ ) _ +Letter+{Letters and/or Digits and/or ( _ ) Underscore character ( _ ) Naming Convention(Style) Variables LengthInYard, hours Functions CalcAverage, Cube(27) Constant MAX_HOUR, LIMIT Invalid Explanation? Correction 40Hours Get Date Box-22 cost_in_$ int Begin with a digit Blanks not allowed The hyphen(-) is minus Special symbols not allowed Reserved word in C++ forty_hours, hours40 get_date, getdate box_22, box22 costinusdollar int_1 6

7 Data Types short int :Range of values ( ±32,767 ). long int :Range of values ( ±2,147,483,647 ). int : Integer numbers float: floating point used for working with real numbers. double: is a floating point type much like float, but it can store a value of much greater magnitude with greater precision. Bool*: is a boolean data type can take two value TRUE or FALSE. *Note:- bool data type is provided by ANSI/ISO C++ standard. It is undefined in Borland Turbo C++. char: character data type (alpha,digit,special-symbol or space). A single character with its value quoted with single-quotation egs. A, a, $,, 8 string: for working with multiple characters including letters, numbers, special symbols and spaces its value quoted with double- quotation. egs. C++, Computer Science,. 7 Letter S.Symbol Space Digit

8 Numeric data types Decimal numbers float 4 bytes of memory, 6 digit precision double 8 bytes of memory, 15 digits precision long double 10 bytes of memory, 19 digits precision Whole numbers int, signed int, short int, signed short int 2 bytes, range: to unsigned int, unsigned short int 2 bytes, range: 0 to long int, signed long int 4 bytes, range: to unsigned long int 4 bytes, range: 0 to

9 Declaration of Variables Constant Variables Data Type Identifier1, Identifier2, ; const Data Type Identifier=value; Examples and preference: char Letter, middleint, ch; char Letter; char middleint; char ch; Examples: const string STARS= ***** ; const char ch= $ ; const float MAX_Hour=40.0 Use const qualifier const double PI = ; Cannot modify later in program 9

10 Assignment Statement Variable = Expression ; Store the value of the Expression into the variable, any previous value of the variable is destroyed. Example:Giving the declarations string firstname; char letter; int num; firstname= Sara ; num = 5; num=5*5-3; Letter= S Valid Assignment firstname=sara; firstname=; Letter=S Invalid Assignment Remark :Double or more assignment allowed and precedence from Right-to-Left eg. N1=n2=n3=5; 10

11 Output statement cout << \nwe can jump\n\ntwo lines. ; cout << endl<< we can jump ; cout << endl<< endl << two lines. ; Example: Given ch= 2 and firstname= Ali and lastname= Ahmad cout<<ch; The 2 Output cout<< ch= <<2; ch=2 cout<<firstname+ +lastname; Ali Ahmad cout<< Erorr# <<ch; Error#2 cout<< \ Hello!\ ; Hello! To print 2 words on separate lines use <<endl Example: cout<< He ; cout<< There ; Hi There 11 cout<< Hi <<endl; cout<< There <<endl; Hi There

12 Comments /*..Text... Text */ For Multiple Lines // Text For Single Line The compiler ignores comments (Not executable) C++ Preprocessor #include<iostream> :- This line known as Preprocessor Directive its not handled by C++ compiler but by a program known as Preprocessor. iostream :- Header file contains declarations of I/O facilities. Preprocessor program acts as a filter before compilation. Source program Preprocessor Expanded Source program C++ Compiler 12

13 A Simple Program: Printing a Line of Text Escape Sequence Description \n Newline. Position the screen cursor to the beginning of the next line. \t Horizontal tab. Move the screen cursor to the next tab stop. \r Carriage return. Position the screen cursor to the beginning of the current line; do not advance to the next line. \a Alert. Sound the system bell. \\ Backslash. Used to print a backslash character. \" Double quote. Used to print a double quote character. There are multiple ways to print text Following are more examples 13

14 1 // Fig. 1.4: fig01_04.cpp 2 // Printing a line with multiple statements 3 #include <iostream.h> 4 5 int main() 6 { 7 cout << "Welcome "; 8 cout << "to C++!\n"; 9 10 return 0; // indicate that program ended successfully 11 } 1. Load <iostream.h> 2. main 2.1 Print "Welcome" 2.2 Print "to C++!" 2.3 newline 2.4 exit (return 0) Welcome to C++! Program Output Unless new line '\n' is specified, the text continues on the same line. 14

15 1 // Fig. 1.5: fig01_05.cpp 2 // Printing multiple lines with a single statement 3 #include <iostream.h> 4 5 int main() 6 { 7 cout << "Welcome\nto\n\nC++!\n"; 8 9 return 0; // indicate that program ended successfully 10 } 1. Load <iostream.h> 2. main 2.1 Print "Welcome" 2.2 newline 2.3 Print "to" 2.4 newline Welcome to C++! Multiple lines can be printed with one statement. 2.5 newline 2.6 Print "C++!" 2.7 newline exit (return 0) Program Output

16 1 // Fig. 1.6: fig01_06.cpp 2 // Addition program 3 #include <iostream.h> 4 Notice how cin is used to get user input. 1. Load <iostream> 2. main 5 int main() 6 { 7 int integer1, integer2, sum; // declaration 8 9 cout << "Enter first integer\n"; // prompt 10 cin >> integer1; // read an integer 11 cout << "Enter second integer\n"; // prompt 12 cin >> integer2; // read an integer 13 sum = integer1 + integer2; // assignment of sum 14 cout << "Sum is " << sum << endl; // print sum return 0; // indicate that program ended successfully 17 } Enter first integer 45 Enter second integer 72 Sum is 117 Variables can be output using cout << variablename. endl flushes the buffer and prints a newline. 2.1 Initialize variables integer1, integer2, and sum 2.2 Print "Enter first integer" Get input 2.3 Print "Enter second integer" Get input 2.4 Add variables and put result into sum 2.5 Print "Sum is" Output sum 2.6 exit (return 0) Program Output 16

17 Formatted Output setw :can be used to specify the width of the field that the next value of output will be printed in. To use it, you must include <iomanip.h> header file. eg1:- int num=12; cout<< setw(4) << num; //num will be printed in a field width of 4 character. 1 2 eg2:- int n1=12; int n2=197; cout<<setw(5)<< n1 << setw(6) << n2; eg3:- (if the value is more than the specified setw value the compiler ignores the setw effect and print it with the minimum number of positions required.) int num=1977; cout<<setw(3)<<num;

18 Formatted Output(cont 1) Setprecision(n) for printing formatted floating point values will output decimal numbers with up to n decimal places it can be done by either setprecision stream manipulator, or precision member function. eg. num = ; cout<< num = <<setprecision(3)<<num; num = 5.34 setfill( ) Specifies character for blank space in field Single quotes required around character enclosed in parentheses num = 5.34; cout<<setw(10)<<setfill( * )<<num; //******5.34 cout<<setw(10)<<setfill('*')<<left<<num; //5.34****** setiosflags(ios:: ) Perform number of different actions based on flag that is set Example: num = 5.34; cout<<setiosflags(ios::left) << setfill( * )<<setw(10)<<num; 5.34****** // right 18

19 Formatted Output (cont 2) cout<<setw(5)<<left<<85<<"\n"; cout<<setw(5)<<right<<99<<"\n"; double a,b,c,pi; a=30.0; b= ; pi=3.1416; cout.precision (7); cout <<showpoint << a << '\t' << b << '\t' << pi << endl; cout <<noshowpoint << a << '\t' << b << '\t' << pi << endl; */ /* x= ; y= ; z= ; cout << fixed; cout << x <<"\t"<< y <<"\t"<< z << endl;

20 Input statement cin >> variable1 >> variable2 ; It needs #include<iostream> preprocessor directive that contain istream cin ostream cout. The Same Statement Data Contents after input cin>>i>>ch>>x; 25 A 16.9 i=25 ch= A x=16.9 3:- cin>>i>>j>>x; 12 8 i=12 j=8 (waits for the third number) Example:- 1:- cin>>length>>width; cin>>length; cin>>width; 2:- 4:- cin>>i>>x; i=46 j=32.4 (15 is held for later input) 20 New line character \n is considered one character eg. cout<< Hello!\n ; cout<< Hello! <<endl; The Same

21 Input statement (cont.) char c1,c2,c3,c4,c5,c6,c7,c8; cin >> c1 >> c2 >> c3; cin >> c4 >> c5; cin >> c6; cin >> c7 >> c8; c1 c2 c3 c4 a f d 3 c5 c6 c7 c8 2 h j w Keyboard Input af d32(enter) hj(tab)w (enter) k Note: All whitespace characters are ignored! 21

22 Input statement(cont.) Note :- can t input SPACE character, the >> skips white space (blank) character. Get Function(Does not skips space characters) eg. cin.get(ch1) R cin>>ch1 cin.get(ch2) cin.get(ch2) cin.get(ch3) 1 cin>>ch3 Given input: R 1 22

23 Reading, Writing using files #include <iostream> #include <fstream> #include <string> using namespace std; main() { ifstream infile; ofstream outfile; double t1,t2,t3,av; string fname,lname; infile.open("f:\\test.txt"); outfile.open("f:\\testr.txt"); infile>>fname>>lname; outfile<<"std.name: "<<fname<<" "<<lname<<endl; infile>>t1>>t2>>t3; outfile<<"test SCORES: "<<t1<<" "<<t2<<" "<<t3<<endl; av=(t1+t2+t3)/3.0; outfile<<"average TEST SCORE: "<<av<<endl; infile.close(); outfile.close(); return 0;} 23

24 Built-in (Library) Function Function Exponentiation pow (x, y) x is raised to power y; (x y ) sqrt (x) Square-root of x sin (x) جا Sine of x cos (x) جتا Cosine of x tan (x) ظا Tangent of x exp (x) Exponentiation of x, ( e x ) fabs (x) Absolute Value of x, x log (x) Logarithm of x (base e) log10 (x) Logarithm of x (base 10) floor (x) Rounding-down x, Returns the largest integral value that is not greater than x. ceil (x) Rounding-up x, Returns the smallest integral value that is not less than x. etc. {there are more} Eg.1. floor (9.2) = 9.0 Eg.2. floor (-9.8) = Remark:you need to include <math.h> to be able to use these functions. In newer versions it is #include<cmath> 24

25 Pre- and Post- Operators ++ or -- Place in front, incrementing or decrementing occurs BEFORE value assigned i = 2 and k = 1 k = ++i; i = i + 1; k = i; 3 3 k =--i; i = i - 1; k = i; 1 1 Place in back, occurs AFTER value assigned i = 2 and k = 1 k = i++; k = i; i = i + 1; 1 3 k = i--; k = i; i = i - 1;

26 Increment Decrement int k = 4; ++k; // k is 5 k++; // k is 6 cout << k << endl; int i = k++; // i is 6, k is 7 cout << i << " " << k << endl; int j = ++k; // j is 8, k is 8 cout << j << " " << k << endl; int d, t=10; d= -- t + --t; cout<<"d="<<d; ((((5 *15) + 4) == 13) && (12 < 19)) ((!false) == (5 < 24)) 26

27 Assignment Operators Assignment expression abbreviations c = c + 3; can be abbreviated as c += 3; using the addition assignment operator Statements of the form variable = variable operator expression; can be rewritten as variable operator= expression; Examples of other assignment operators include: d -= 4 (d = d - 4) e *= 5 (e = e * 5) f /= 3 (f = f / 3) g %= 9 (g = g % 9) 27

28 Increment and Decrement Operators Increment operator (++) - can be used instead of c += 1 Decrement operator (--) - can be used instead of c -= 1 Preincrement When the operator is used before the variable (++c or --c) Variable is changed, then the expression it is in is evaluated. Postincrement When the operator is used after the variable (c++ or c--) Expression the variable is in executes, then the variable is changed. If c = 5, then cout << ++c; prints out 6 (c is changed before cout is executed) cout << c++; prints out 5 (cout is executed before the increment. c now has the value of 6) 28

29 Increment & Decrement Operators Examples int c; c=5; cout<<c<<endl; 5 cout<<c- -<<endl; 5 cout<<c<<endl; 4 cout<< ===\n ; === c=5; cout<<c<<endl; 5 cout<<- -c<<endl; 4 cout<<c<<endl; 4 29

30 Operators Precedence 3x+5y+2x 2 (3*x)+(5*y)+(2*pow(x,2)) y = 2 * * Total = * 2 /

31 Operators Precedence update Operator(s) Operation(s) Order of evaluation (precedence) () Parentheses Evaluated first. If the parentheses are nested, the expression in the innermost pair is evaluated first. If there are several pairs of parentheses on the same level (i.e., not nested), they are evaluated left to right.!, +, - Logical NOT, signs Evaluated second. If there are several, they are evaluated right to left. *, /, or % Multiplication Division Modulus + or - Addition Subtraction >>, << Input steam extraction and output stream insertion Evaluated third. If there are several, they are evaluated left to right. Evaluated fourth. If there are several, they are evaluated left to right. Evaluated fifth. If there are several, they are evaluated left to right. >, <, >=, <= Relational Operators Evaluated sixth. If there are several, they are evaluated left to right. ==,!= Equality Operators Evaluated seventh. If there are several, they are evaluated left to right. && Logical AND Evaluated eighth. If there are several, they are evaluated left to right. Logical OR Evaluated nineth. If there are several, they are evaluated left to right. = Assignment Evaluated tenth. If there are several, they are evaluated right to left. 31

32 getline function The extraction operator(>>) skips any leading whitespace characters and reading stops at a whitespace character It should not be used to read strings that contain blanks The function getline reads until it reaches the end of the current line It should be used to read strings that contain blanks #include <string> //Header string str; getline (cin,str); //Badee3 Maola azzaman cout << str ; //Badee3 Maola azzaman 32

33 String Functions #include <iostream> #include <string> using namespace std; int main () { string name = "HALA SAQER BESHIR"; cout<<name<<endl; string str2 = name + " BDOUR"; cout<<str2<<endl; cout<<name.length()<<endl; cout<<name.size()<<endl; cout<<name.find("q")<<endl; cout<<name.substr(5)<<endl; string st1 = "FIRST"; string st2 = "SECOND"; st1.swap(st2); cout<<st1<<" "<<st2<<endl; } 33

Chapter 1 Introduction to Computers and C++ Programming

Chapter 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 information

Introduction to Programming

Introduction to Programming Introduction to Programming session 5 Instructor: Reza Entezari-Maleki Email: entezari@ce.sharif.edu 1 Fall 2010 These slides are created using Deitel s slides Sahrif University of Technology Outlines

More information

Introduction to C++ Programming. Adhi Harmoko S, M.Komp

Introduction to C++ Programming. Adhi Harmoko S, M.Komp Introduction to C++ Programming Adhi Harmoko S, M.Komp Machine Languages, Assembly Languages, and High-level Languages Three types of programming languages Machine languages Strings of numbers giving machine

More information

BITG 1233: Introduction to C++

BITG 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 information

CHAPTER 1.2 INTRODUCTION TO C++ PROGRAMMING. Dr. Shady Yehia Elmashad

CHAPTER 1.2 INTRODUCTION TO C++ PROGRAMMING. Dr. Shady Yehia Elmashad CHAPTER 1.2 INTRODUCTION TO C++ PROGRAMMING Dr. Shady Yehia Elmashad Outline 1. Introduction to C++ Programming 2. Comment 3. Variables and Constants 4. Basic C++ Data Types 5. Simple Program: Printing

More information

Engineering Problem Solving with C++, Etter/Ingber

Engineering Problem Solving with C++, Etter/Ingber Engineering Problem Solving with C++, Etter/Ingber Chapter 2 Simple C++ Programs C++, Second Edition, J. Ingber 1 Simple C++ Programs Program Structure Constants and Variables C++ Operators Standard Input

More information

Objectives. In this chapter, you will:

Objectives. 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 information

Chapter 3 - Notes Input/Output

Chapter 3 - Notes Input/Output Chapter 3 - Notes Input/Output I. I/O Streams and Standard I/O Devices A. I/O Background 1. Stream of Bytes: A sequence of bytes from the source to the destination. 2. 2 Types of Streams: i. Input Stream:

More information

Chapter 2: Basic Elements of C++ Objectives. Objectives (cont d.) A C++ Program. Introduction

Chapter 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 information

Objectives. 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++ 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 information

Chapter 2. Outline. Simple C++ Programs

Chapter 2. Outline. Simple C++ Programs Chapter 2 Simple C++ Programs Outline Objectives 1. Building C++ Solutions with IDEs: Dev-cpp, Xcode 2. C++ Program Structure 3. Constant and Variables 4. C++ Operators 5. Standard Input and Output 6.

More information

Introduction to C++ Programming Pearson Education, Inc. All rights reserved.

Introduction to C++ Programming Pearson Education, Inc. All rights reserved. 1 2 Introduction to C++ Programming 2 What s in a name? that which we call a rose By any other name would smell as sweet. William Shakespeare When faced with a decision, I always ask, What would be the

More information

C: How to Program. Week /Mar/05

C: How to Program. Week /Mar/05 1 C: How to Program Week 2 2007/Mar/05 Chapter 2 - Introduction to C Programming 2 Outline 2.1 Introduction 2.2 A Simple C Program: Printing a Line of Text 2.3 Another Simple C Program: Adding Two Integers

More information

Chapter 2: Basic Elements of C++

Chapter 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 information

Lab # 02. Basic Elements of C++ _ Part1

Lab # 02. Basic Elements of C++ _ Part1 Lab # 02 Basic Elements of C++ _ Part1 Lab Objectives: After performing this lab, the students should be able to: Become familiar with the basic components of a C++ program, including functions, special

More information

UNIT- 3 Introduction to C++

UNIT- 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 information

3.1. Chapter 3: Displaying a Prompt. Expressions and Interactivity

3.1. Chapter 3: Displaying a Prompt. Expressions and Interactivity Chapter 3: Expressions and Interactivity 3.1 The cin Object Copyright 2009 Pearson Education, Inc. Copyright 2009 Publishing Pearson as Pearson Education, Addison-Wesley Inc. Publishing as Pearson Addison-Wesley

More information

Chapter 2 - Introduction to C Programming

Chapter 2 - Introduction to C Programming Chapter 2 - Introduction to C Programming 2 Outline 2.1 Introduction 2.2 A Simple C Program: Printing a Line of Text 2.3 Another Simple C Program: Adding Two Integers 2.4 Memory Concepts 2.5 Arithmetic

More information

Chapter 1 & 2 Introduction to C Language

Chapter 1 & 2 Introduction to C Language 1 Chapter 1 & 2 Introduction to C Language Copyright 2007 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. Chapter 1 & 2 - Introduction to C Language 2 Outline 1.1 The History

More information

C++ Basics. Lecture 2 COP 3014 Spring January 8, 2018

C++ Basics. Lecture 2 COP 3014 Spring January 8, 2018 C++ Basics Lecture 2 COP 3014 Spring 2018 January 8, 2018 Structure of a C++ Program Sequence of statements, typically grouped into functions. function: a subprogram. a section of a program performing

More information

C++ Programming: From Problem Analysis to Program Design, Third Edition

C++ 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 information

6.096 Introduction to C++ January (IAP) 2009

6.096 Introduction to C++ January (IAP) 2009 MIT OpenCourseWare http://ocw.mit.edu 6.096 Introduction to C++ January (IAP) 2009 For information about citing these materials or our Terms of Use, visit: http://ocw.mit.edu/terms. Welcome to 6.096 Lecture

More information

I/O Streams and Standard I/O Devices (cont d.)

I/O Streams and Standard I/O Devices (cont d.) Chapter 3: Input/Output Objectives In this chapter, you will: Learn what a stream is and examine input and output streams Explore how to read data from the standard input device Learn how to use predefined

More information

Features of C. Portable Procedural / Modular Structured Language Statically typed Middle level language

Features of C. Portable Procedural / Modular Structured Language Statically typed Middle level language 1 History C is a general-purpose, high-level language that was originally developed by Dennis M. Ritchie to develop the UNIX operating system at Bell Labs. C was originally first implemented on the DEC

More information

c++ keywords: ( all lowercase ) Note: cin and cout are NOT keywords.

c++ keywords: ( all lowercase ) Note: cin and cout are NOT keywords. Chapter 1 File Extensions: Source code (cpp), Object code (obj), and Executable code (exe). Preprocessor processes directives and produces modified source Compiler takes modified source and produces object

More information

CSCE 110 PROGRAMMING FUNDAMENTALS

CSCE 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 information

The C++ Language. Arizona State University 1

The C++ Language. Arizona State University 1 The C++ Language CSE100 Principles of Programming with C++ (based off Chapter 2 slides by Pearson) Ryan Dougherty Arizona State University http://www.public.asu.edu/~redoughe/ Arizona State University

More information

LECTURE 02 INTRODUCTION TO C++

LECTURE 02 INTRODUCTION TO C++ PowerPoint Slides adapted from *Starting Out with C++: From Control Structures through Objects, 7/E* by *Tony Gaddis* Copyright 2012 Pearson Education Inc. COMPUTER PROGRAMMING LECTURE 02 INTRODUCTION

More information

2.1. Chapter 2: Parts of a C++ Program. Parts of a C++ Program. Introduction to C++ Parts of a C++ Program

2.1. Chapter 2: Parts of a C++ Program. Parts of a C++ Program. Introduction to C++ Parts of a C++ Program Chapter 2: Introduction to C++ 2.1 Parts of a C++ Program Copyright 2009 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 2-1 Parts of a C++ Program Parts of a C++ Program // sample C++ program

More information

Introduction to C Programming. Chih-Wei Tang ( 唐之瑋 ) Department of Communication Engineering National Central University JhongLi, Taiwan

Introduction to C Programming. Chih-Wei Tang ( 唐之瑋 ) Department of Communication Engineering National Central University JhongLi, Taiwan Introduction to C Programming Chih-Wei Tang ( 唐之瑋 ) Department of Communication Engineering National Central University JhongLi, Taiwan Outline Printing texts Adding 2 integers Comparing 2 integers C.E.,

More information

Chapter 2: Introduction to C++

Chapter 2: Introduction to C++ Chapter 2: Introduction to C++ Copyright 2010 Pearson Education, Inc. Copyright Publishing as 2010 Pearson Pearson Addison-Wesley Education, Inc. Publishing as Pearson Addison-Wesley 2.1 Parts of a C++

More information

Chapter 2: Special Characters. Parts of a C++ Program. Introduction to C++ Displays output on the computer screen

Chapter 2: Special Characters. Parts of a C++ Program. Introduction to C++ Displays output on the computer screen Chapter 2: Introduction to C++ 2.1 Parts of a C++ Program Copyright 2009 Pearson Education, Inc. Copyright 2009 Publishing Pearson as Pearson Education, Addison-Wesley Inc. Publishing as Pearson Addison-Wesley

More information

Creating a C++ Program

Creating a C++ Program 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 Creating a C++ Program created using an

More information

Programming - 1. Computer Science Department 011COMP-3 لغة البرمجة 1 لطالب كلية الحاسب اآللي ونظم المعلومات 011 عال- 3

Programming - 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 information

Programming. C++ Basics

Programming. 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 information

2/29/2016. Definition: Computer Program. A simple model of the computer. Example: Computer Program. Data types, variables, constants

2/29/2016. Definition: Computer Program. A simple model of the computer. Example: Computer Program. Data types, variables, constants Data types, variables, constants Outline.1 Introduction. Text.3 Memory Concepts.4 Naming Convention of Variables.5 Arithmetic in C.6 Type Conversion Definition: Computer Program A Computer program is a

More information

The C++ Language. Output. Input and Output. Another type supplied by C++ Very complex, made up of several simple types.

The C++ Language. Output. Input and Output. Another type supplied by C++ Very complex, made up of several simple types. The C++ Language Input and Output Output! Output is information generated by a program.! Frequently sent the screen or a file.! An output stream is used to send information. Another type supplied by C++

More information

ADARSH VIDYA KENDRA NAGERCOIL COMPUTER SCIENCE. Grade: IX C++ PROGRAMMING. Department of Computer Science 1

ADARSH VIDYA KENDRA NAGERCOIL COMPUTER SCIENCE. Grade: IX C++ PROGRAMMING. Department of Computer Science 1 NAGERCOIL COMPUTER SCIENCE Grade: IX C++ PROGRAMMING 1 C++ 1. Object Oriented Programming OOP is Object Oriented Programming. It was developed to overcome the flaws of the procedural approach to programming.

More information

CSc 10200! Introduction to Computing. Lecture 2-3 Edgardo Molina Fall 2013 City College of New York

CSc 10200! Introduction to Computing. Lecture 2-3 Edgardo Molina Fall 2013 City College of New York CSc 10200! Introduction to Computing Lecture 2-3 Edgardo Molina Fall 2013 City College of New York 1 C++ for Engineers and Scientists Third Edition Chapter 2 Problem Solving Using C++ 2 Objectives In this

More information

CSI33 Data Structures

CSI33 Data Structures Outline Department of Mathematics and Computer Science Bronx Community College October 22, 2018 Outline Outline 1 Chapter 8: A C++ Introduction For Python Programmers ords Data Types And Variable Declarations

More information

Chapter 15 - C++ As A "Better C"

Chapter 15 - C++ As A Better C Chapter 15 - C++ As A "Better C" Outline 15.1 Introduction 15.2 C++ 15.3 A Simple Program: Adding Two Integers 15.4 C++ Standard Library 15.5 Header Files 15.6 Inline Functions 15.7 References and Reference

More information

CPE 112 Spring 2015 Exam II (100 pts) March 4, Definition Matching (8 Points)

CPE 112 Spring 2015 Exam II (100 pts) March 4, Definition Matching (8 Points) Name Definition Matching (8 Points) 1. (8 pts) Match the words with their definitions. Choose the best definition for each word. Relational Expression Iteration Counter Count-controlled loop Loop Flow

More information

Engineering Problem Solving with C++, 3e Chapter 2 Test Bank

Engineering Problem Solving with C++, 3e Chapter 2 Test Bank 1. Match each of the following data types with literal constants of that data type. A data type can be used more than once. A. integer B 1.427E3 B. double D "Oct" C. character B -63.29 D. string F #Hashtag

More information

A First Program - Greeting.cpp

A 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 information

CS 151 Review #3. // More than one variable can be defined // in a statement. Multiple variables are // separated by a comma.

CS 151 Review #3. // More than one variable can be defined // in a statement. Multiple variables are // separated by a comma. REVIEW cout Statement The cout statement invokes an output stream, which is a sequence of characters to be displayed to the screen. cout

More information

Software Design & Programming I

Software Design & Programming I Software Design & Programming I Starting Out with C++ (From Control Structures through Objects) 7th Edition Written by: Tony Gaddis Pearson - Addison Wesley ISBN: 13-978-0-132-57625-3 Chapter 3 Introduction

More information

CS242 COMPUTER PROGRAMMING

CS242 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 information

CHAPTER 3 BASIC INSTRUCTION OF C++

CHAPTER 3 BASIC INSTRUCTION OF C++ CHAPTER 3 BASIC INSTRUCTION OF C++ MOHD HATTA BIN HJ MOHAMED ALI Computer programming (BFC 20802) Subtopics 2 Parts of a C++ Program Classes and Objects The #include Directive Variables and Literals Identifiers

More information

C++ Input/Output: Streams

C++ Input/Output: Streams C++ Input/Output: Streams Basic I/O 1 The basic data type for I/O in C++ is the stream. C++ incorporates a complex hierarchy of stream types. The most basic stream types are the standard input/output streams:

More information

Copyright 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley

Copyright 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Slide 7-1 Copyright 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Type Conversation / Casting Name Constant - const, #define X When You Mix Apples and Oranges: Type Conversion Operations

More information

Chapter 3 - Functions

Chapter 3 - Functions Chapter 3 - Functions 1 Outline 3.1 Introduction 3.2 Program Components in C++ 3.3 Math Library Functions 3.4 Functions 3.5 Function Definitions 3.6 Function Prototypes 3.7 Header Files 3.8 Random Number

More information

Introduction to C# Applications

Introduction to C# Applications 1 2 3 Introduction to C# Applications OBJECTIVES To write simple C# applications To write statements that input and output data to the screen. To declare and use data of various types. To write decision-making

More information

Intro to Computer Programming (ICP) Rab Nawaz Jadoon

Intro to Computer Programming (ICP) Rab Nawaz Jadoon Intro to Computer Programming (ICP) Rab Nawaz Jadoon DCS COMSATS Institute of Information Technology Assistant Professor COMSATS IIT, Abbottabad Pakistan Introduction to Computer Programming (ICP) What

More information

Data types, variables, constants

Data types, variables, constants Data types, variables, constants Outline 2.1 Introduction 2.2 A Simple C Program: Printing a Line of Text 2.3 Another Simple C Program: Adding Two Integers 2.4 Memory Concepts 2.5 Arithmetic in C 2.6 Decision

More information

C++ Programming: From Problem Analysis to Program. Design, Fifth Edition. Chapter 1: An Overview of Computers and Programming Languages

C++ Programming: From Problem Analysis to Program. Design, Fifth Edition. Chapter 1: An Overview of Computers and Programming Languages C++ Programming: From Problem Analysis to Program Design, Fifth Edition Chapter 1: An Overview of Computers and Programming Languages Updated by: Malak Abdullah The Evolution of Programming Languages (cont'd.)

More information

CSc Introduction to Computing

CSc Introduction to Computing CSc 10200 Introduction to Computing Lecture 2 Edgardo Molina Fall 2011 - City College of New York Thursday, September 1, 2011 Introduction to C++ Modular program: A program consisting of interrelated segments

More information

Understanding main() function Input/Output Streams

Understanding main() function Input/Output Streams Understanding main() function Input/Output Streams Structure of a program // my first program in C++ #include int main () { cout

More information

UNIT - I. Introduction to C Programming. BY A. Vijay Bharath

UNIT - I. Introduction to C Programming. BY A. Vijay Bharath UNIT - I Introduction to C Programming Introduction to C C was originally developed in the year 1970s by Dennis Ritchie at Bell Laboratories, Inc. C is a general-purpose programming language. It has been

More information

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

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 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 information

3. Except for strings, double quotes, identifiers, and keywords, C++ ignores all white space.

3. Except for strings, double quotes, identifiers, and keywords, C++ ignores all white space. Chapter 2: Problem Solving Using C++ TRUE/FALSE 1. Modular programs are easier to develop, correct, and modify than programs constructed in some other manner. ANS: T PTS: 1 REF: 45 2. One important requirement

More information

C++ Basic Elements of COMPUTER PROGRAMMING. Special symbols include: Word symbols. Objectives. Programming. Symbols. Symbols.

C++ Basic Elements of COMPUTER PROGRAMMING. Special symbols include: Word symbols. Objectives. Programming. Symbols. Symbols. EEE-117 COMPUTER PROGRAMMING Basic Elements of C++ Objectives General Questions Become familiar with the basic components of a C++ program functions, special symbols, and identifiers Data types Arithmetic

More information

Chapter 1 INTRODUCTION

Chapter 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 information

Computer Programming : C++

Computer Programming : C++ The Islamic University of Gaza Engineering Faculty Department of Computer Engineering Fall 2017 ECOM 2003 Muath i.alnabris Computer Programming : C++ Experiment #1 Basics Contents Structure of a program

More information

1. Match each of the following data types with literal constants of that data type. A data type can be used more than once. A.

1. Match each of the following data types with literal constants of that data type. A data type can be used more than once. A. Engineering Problem Solving With C++ 4th Edition Etter TEST BANK Full clear download (no error formating) at: https://testbankreal.com/download/engineering-problem-solving-with-c-4thedition-etter-test-bank/

More information

Review: Exam 1. Your First C++ Program. Declaration Statements. Tells the compiler. Examples of declaration statements

Review: 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 information

C++ Basics. Data Processing Course, I. Hrivnacova, IPN Orsay

C++ 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 information

Formatting outputs String data type Interactive inputs File manipulators. Access to a library that defines 3. instead, a library provides input

Formatting outputs String data type Interactive inputs File manipulators. Access to a library that defines 3. instead, a library provides input Input and Output Outline Formatting outputs String data type Interactive inputs File manipulators CS 1410 Comp Sci with C++ Input and Output 1 CS 1410 Comp Sci with C++ Input and Output 2 No I/O is built

More information

C++ As A "Better C" Chih-Wei Tang ( 唐之瑋 ) Department of Communication Engineering National Central University JhongLi, Taiwan.

C++ As A Better C Chih-Wei Tang ( 唐之瑋 ) Department of Communication Engineering National Central University JhongLi, Taiwan. C++ As A "Better C" Chih-Wei Tang ( 唐之瑋 ) Department of Communication Engineering National Central University JhongLi, Taiwan 2013 Fall Outline 15.2 C++ 15.3 A Simple Program: Adding Two Integers 15.5

More information

IS 0020 Program Design and Software Tools

IS 0020 Program Design and Software Tools 1 IS 0020 Program Design and Software Tools Introduction to C++ Programming Spring 2005 Lecture 1 Jan 6, 2005 Course Information 2 Lecture: James B D Joshi Tuesdays/Thursdays: 1:00-2:15 PM Office Hours:

More information

Overview. - General Data Types - Categories of Words. - Define Before Use. - The Three S s. - End of Statement - My First Program

Overview. - General Data Types - Categories of Words. - Define Before Use. - The Three S s. - End of Statement - My First Program Overview - General Data Types - Categories of Words - The Three S s - Define Before Use - End of Statement - My First Program a description of data, defining a set of valid values and operations List of

More information

Piyush Kumar. input data. both cout and cin are data objects and are defined as classes ( type istream ) class

Piyush Kumar. input data. both cout and cin are data objects and are defined as classes ( type istream ) class C++ IO C++ IO All I/O is in essence, done one character at a time For : COP 3330. Object oriented Programming (Using C++) http://www.compgeom.com/~piyush/teach/3330 Concept: I/O operations act on streams

More information

3.1. Chapter 3: The cin Object in Program 3-1. Displaying a Prompt 8/23/2014. The cin Object

3.1. Chapter 3: The cin Object in Program 3-1. Displaying a Prompt 8/23/2014. The cin Object Chapter 3: Expressions and Interactivity 3.1 The cin Object The cin Object The cin Object in Program 3-1 Standard input object Like cout, requires iostream file Used to read input from keyboard Information

More information

Chapter 3: Expressions and Interactivity

Chapter 3: Expressions and Interactivity Chapter 3: Expressions and Interactivity 3.1 The cin Object The cin Object Standard input object Like cout, requires iostream file Used to read input from keyboard Information retrieved from cin with >>

More information

c) Comments do not cause any machine language object code to be generated. d) Lengthy comments can cause poor execution-time performance.

c) Comments do not cause any machine language object code to be generated. d) Lengthy comments can cause poor execution-time performance. 2.1 Introduction (No questions.) 2.2 A Simple Program: Printing a Line of Text 2.1 Which of the following must every C program have? (a) main (b) #include (c) /* (d) 2.2 Every statement in C

More information

Chapter 2: Overview of C++

Chapter 2: Overview of C++ Chapter 2: Overview of C++ Problem Solving, Abstraction, and Design using C++ 6e by Frank L. Friedman and Elliot B. Koffman C++ Background Introduced by Bjarne Stroustrup of AT&T s Bell Laboratories in

More information

Lecture 3 The character, string data Types Files

Lecture 3 The character, string data Types Files Lecture 3 The character, string data Types Files The smallest integral data type Used for single characters: letters, digits, and special symbols Each character is enclosed in single quotes 'A', 'a', '0',

More information

Week 3: File I/O and Formatting 3.7 Formatting Output

Week 3: File I/O and Formatting 3.7 Formatting Output Week 3: File I/O and Formatting 3.7 Formatting Output Formatting: the way a value is printed: Gaddis: 3.7, 3.8, 5.11 CS 1428 Fall 2014 Jill Seaman spacing decimal points, fractional values, number of digits

More information

Getting started with C++ (Part 2)

Getting started with C++ (Part 2) Getting started with C++ (Part 2) CS427: Elements of Software Engineering Lecture 2.2 11am, 16 Jan 2012 CS427 Getting started with C++ (Part 2) 1/22 Outline 1 Recall from last week... 2 Recall: Output

More information

Definition Matching (10 Points)

Definition Matching (10 Points) Name SOLUTION Closed notes and book. If you have any questions ask them. Write clearly and make sure the case of a letter is clear (where applicable) since C++ is case sensitive. There are no syntax errors

More information

Chapter 2, Part I Introduction to C Programming

Chapter 2, Part I Introduction to C Programming Chapter 2, Part I Introduction to C Programming C How to Program, 8/e, GE 2016 Pearson Education, Ltd. All rights reserved. 1 2016 Pearson Education, Ltd. All rights reserved. 2 2016 Pearson Education,

More information

Lecture 2 Tao Wang 1

Lecture 2 Tao Wang 1 Lecture 2 Tao Wang 1 Objectives In this chapter, you will learn about: Modular programs Programming style Data types Arithmetic operations Variables and declaration statements Common programming errors

More information

2 nd Week Lecture Notes

2 nd Week Lecture Notes 2 nd Week Lecture Notes Scope of variables All the variables that we intend to use in a program must have been declared with its type specifier in an earlier point in the code, like we did in the previous

More information

Strings and Streams. Professor Hugh C. Lauer CS-2303, System Programming Concepts

Strings and Streams. Professor Hugh C. Lauer CS-2303, System Programming Concepts Strings and Streams Professor Hugh C. Lauer CS-2303, System Programming Concepts (Slides include materials from The C Programming Language, 2 nd edition, by Kernighan and Ritchie, Absolute C++, by Walter

More information

CS 241 Computer Programming. Introduction. Teacher Assistant. Hadeel Al-Ateeq

CS 241 Computer Programming. Introduction. Teacher Assistant. Hadeel Al-Ateeq CS 241 Computer Programming Introduction Teacher Assistant Hadeel Al-Ateeq 1 2 Course URL: http://241cs.wordpress.com/ Hadeel Al-Ateeq 3 Textbook HOW TO PROGRAM BY C++ DEITEL AND DEITEL, Seventh edition.

More information

Introduction to C Language

Introduction to C Language Introduction to C Language Instructor: Professor I. Charles Ume ME 6405 Introduction to Mechatronics Fall 2006 Instructor: Professor Charles Ume Introduction to C Language History of C Language In 1972,

More information

Chapter 3: Expressions and Interactivity. Copyright 2012 Pearson Education, Inc. Thursday, October 9, 14

Chapter 3: Expressions and Interactivity. Copyright 2012 Pearson Education, Inc. Thursday, October 9, 14 Chapter 3: Expressions and Interactivity 3.1 The cin Object The cin Object Standard input object Like cout, requires iostream file Used to read input from keyboard Information retrieved from cin with >>

More information

Chapter 2. C++ Basics. Copyright 2014 Pearson Addison-Wesley. All rights reserved.

Chapter 2. C++ Basics. Copyright 2014 Pearson Addison-Wesley. All rights reserved. Chapter 2 C++ Basics Overview 2.1 Variables and Assignments 2.2 Input and Output 2.3 Data Types and Expressions 2.4 Simple Flow of Control 2.5 Program Style 3 2.1 Variables and Assignments Variables and

More information

Chapter 2. C++ Basics

Chapter 2. C++ Basics Chapter 2 C++ Basics Overview 2.1 Variables and Assignments 2.2 Input and Output 2.3 Data Types and Expressions 2.4 Simple Flow of Control 2.5 Program Style Slide 2-2 2.1 Variables and Assignments Variables

More information

The sequence of steps to be performed in order to solve a problem by the computer is known as an algorithm.

The sequence of steps to be performed in order to solve a problem by the computer is known as an algorithm. CHAPTER 1&2 OBJECTIVES After completing this chapter, you will be able to: Understand the basics and Advantages of an algorithm. Analysis various algorithms. Understand a flowchart. Steps involved in designing

More information

Fundamentals of Programming CS-110. Lecture 2

Fundamentals 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 information

Chapter 4 - Notes Control Structures I (Selection)

Chapter 4 - Notes Control Structures I (Selection) Chapter 4 - Notes Control Structures I (Selection) I. Control Structures A. Three Ways to Process a Program 1. In Sequence: Starts at the beginning and follows the statements in order 2. Selectively (by

More information

C++ PROGRAMMING. For Industrial And Electrical Engineering Instructor: Ruba A. Salamh

C++ PROGRAMMING. For Industrial And Electrical Engineering Instructor: Ruba A. Salamh C++ PROGRAMMING For Industrial And Electrical Engineering Instructor: Ruba A. Salamh CHAPTER TWO: Fundamental Data Types Chapter Goals In this chapter, you will learn how to work with numbers and text,

More information

CS101: Fundamentals of Computer Programming. Dr. Tejada www-bcf.usc.edu/~stejada Week 1 Basic Elements of C++

CS101: Fundamentals of Computer Programming. Dr. Tejada www-bcf.usc.edu/~stejada Week 1 Basic Elements of C++ CS101: Fundamentals of Computer Programming Dr. Tejada stejada@usc.edu www-bcf.usc.edu/~stejada Week 1 Basic Elements of C++ 10 Stacks of Coins You have 10 stacks with 10 coins each that look and feel

More information

File I/O. File Names and Types. I/O Streams. Stream Extraction and Insertion. A file name should reflect its contents

File I/O. File Names and Types. I/O Streams. Stream Extraction and Insertion. A file name should reflect its contents File I/O 1 File Names and Types A file name should reflect its contents Payroll.dat Students.txt Grades.txt A file s extension indicates the kind of data the file holds.dat,.txt general program input or

More information

Chapter 2. C++ Basics. Copyright 2014 Pearson Addison-Wesley. All rights reserved.

Chapter 2. C++ Basics. Copyright 2014 Pearson Addison-Wesley. All rights reserved. Chapter 2 C++ Basics 1 Overview 2.1 Variables and Assignments 2.2 Input and Output 2.3 Data Types and Expressions 2.4 Simple Flow of Control 2.5 Program Style Slide 2-3 2.1 Variables and Assignments 2

More information

CSCI 1061U Programming Workshop 2. C++ Basics

CSCI 1061U Programming Workshop 2. C++ Basics CSCI 1061U Programming Workshop 2 C++ Basics 1 Learning Objectives Introduction to C++ Origins, Object-Oriented Programming, Terms Variables, Expressions, and Assignment Statements Console Input/Output

More information

Multiple Choice (Questions 1 14) 28 Points Select all correct answers (multiple correct answers are possible)

Multiple 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 information

Programming for Engineers Introduction to C

Programming for Engineers Introduction to C Programming for Engineers Introduction to C ICEN 200 Spring 2018 Prof. Dola Saha 1 Simple Program 2 Comments // Fig. 2.1: fig02_01.c // A first program in C begin with //, indicating that these two lines

More information

Full file at C How to Program, 6/e Multiple Choice Test Bank

Full file at   C How to Program, 6/e Multiple Choice Test Bank 2.1 Introduction 2.2 A Simple Program: Printing a Line of Text 2.1 Lines beginning with let the computer know that the rest of the line is a comment. (a) /* (b) ** (c) REM (d)

More information

Multiple Choice (Questions 1 13) 26 Points Select all correct answers (multiple correct answers are possible)

Multiple 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 information