CSCE 110 PROGRAMMING FUNDAMENTALS
|
|
- Godfrey Hopkins
- 5 years ago
- Views:
Transcription
1 CSCE 110 PROGRAMMING FUNDAMENTALS WITH C++ Prof. Amr Goneid AUC Part 2. Overview of C++ Prof. Amr Goneid, AUC 1
2 Overview of C++ Prof. Amr Goneid, AUC 2
3 Overview of C++ Historical C++ Basics Some Library Functions Expressions & Assignment Simple Input/Output Prof. Amr Goneid, AUC 3
4 Historical 1967: BCP language (Martin Richards, Cambridge) 1969: B language (Ken Thompson, Bell labs) Early 1970 s: C language & Unix Operating System (Dennis Ritchie, Bell Labs) Prof. Amr Goneid, AUC 4
5 Historical Mid-1980 s: Early C++ derived from C (Bjarne Stroustrup, Bell labs) 1998: Formally standardized C++, an OOP language Prof. Amr Goneid, AUC 5
6 1. C++ Basics Example Program Style, Declarations Data Types Constants Declaring Constants & variables Prof. Amr Goneid, AUC 6
7 1.1 Example Program: Sorting an Array of Integers Prof. Amr Goneid, AUC 7
8 Sorting an Array of Integers # include <iostream> using namespace std; // Functions Used void selectsort (int a[ ], int n); // Function Prototype int main() { const int MAX = 100; int a[max], k, n; // Start of main function // Data Declarations Prof. Amr Goneid, AUC 8
9 Example Program: Main Function Actions /* Begin Main Actions */ cin >> n; // Read size of data if (n > MAX) n = MAX; // to prevent array overflow for (k = 0; k < n; k++) cin >> a[k]; // Read data into array selectsort(a,n); // Call sorting module for (k = 0; k < n; k++) cout << a[k]; // Write sorted data cout << \n // Move to a new line return 0; // No errors } /* End. Main Function */ Prof. Amr Goneid, AUC 9
10 Example Program: Sorting Module (Function) void selectsort (int a[ ], int n) { // Begin Module int i, j, min, temp; // Module Local Data for (i = 0; i < n-1; i++ ) // Begin module action { min = i; for ( j = i+1; j < n; j++) if (a[j] < a[min] ) min = j; temp = a[min]; a[min] = a[i]; a[i] = temp; } } // End Module Prof. Amr Goneid, AUC 10
11 1.2 Style Lines Separators (spaces, lines, comments) Comments ( //.. Single line or /*..*/ ) Case sensitive ( e.g. MAX, max) Keywords ( e.g. for if return..) use lowercase letters User Identifiers (e.g. MAX, min, a, n, selectsort,.. etc) Prof. Amr Goneid, AUC 11
12 Style (continued) Constants (e.g. MAX,100, \n etc) Operators (e.g. <= ++ + >> etc) Punctuators (e.g. ( ) ; { } etc) Keywords, identifiers, constants, operators and punctuators are called TOKENS Compiler Directives Prof. Amr Goneid, AUC 12
13 Compiler Directives #include Compiler directive Processed at compilation time Instructs compiler on what you want in the program #include <iostream> Adds library files to program Used with < > Also user defined Prof. Amr Goneid, AUC 13
14 Some Declaration Keywords Modules (Functions): main() void <function name>(..) Data Declaration: const for constant data int, float, etc, for data types string for user defined strings Prof. Amr Goneid, AUC 14
15 1.3 A Classification of Data Types Data Type Scalar Data Structure Integer Floating Character Logical (bool) Pointer Arrays Structs Unions Classes Files Streams strings.. Prof. Amr Goneid, AUC 15
16 Some Scalar Data Types Integers: int short unsigned int long Floating: float double long double Character: char unsigned char Logical (Boolean): bool Prof. Amr Goneid, AUC 16
17 Ranges of Scalar Data Types int, short 2 bytes -32, ,767 unsigned int, unsigned short 2 bytes ,535 long 4 bytes -2G.. 2G unsigned long 4 bytes 0.. 4G float 4 bytes ~ E +/- 38 (7 digits) double 8 bytes ~ E +/- 308 (15 digits) long double 10 bytes ~ E +/ (19 digits) Prof. Amr Goneid, AUC 17
18 Ranges of Scalar Data Types char 1 byte unsigned char 1 byte bool 1 byte true / false non-zero / zero Note: Integer, character and boolean types are called Ordinal Types because their members can be listed by rank. Prof. Amr Goneid, AUC 18
19 1.4 Examples of Constants Predefined: true false SHRT_MAX (32767) Integer: 79 (decimal of type int) L (decimal of type long) Floating: e E+5 (decimal of type double) Character: A \n (type char) String Literals: Hello (class string) Prof. Amr Goneid, AUC 19
20 1.5 Declaring & Initializing Constants Syntax : const <type> <name> = <value>; Examples: const int MAX = 100; {integer} const bool says = true; {Boolean} const string message = warning! ; {String literal} const float KmperMile= F; {float} const alpha = E-15; {double} const Large = L; {long} const char Initial = H ; {char} Prof. Amr Goneid, AUC 20
21 Declaring & Initializing Variables Syntax: <type> <name>, <name>.. ; or <type> <name> = <value>; Examples: unsigned char pixel ; int k = 2197; float x, y ; char c ; bool test ; string name = Ann W. Wolf ; Prof. Amr Goneid, AUC 21
22 Assigning Constants to Variables changes initial values Examples: pixel = 212; k = ; x = ; c = H ; test = false; name = John W. Wolf ; k = SHRT_MAX; Prof. Amr Goneid, AUC 22
23 2. Some Library Functions Prof. Amr Goneid, AUC 23
24 Some Library Functions To invoke: FunctionName (x) returns value of function for argument x Examples: char(65) returns A int( A ) returns 65 sqrt(4) returns 2.0 abs(-6) returns 6 sin(1.5708) returns 1.00 Prof. Amr Goneid, AUC 24
25 Library Functions(continued) cos(0.0) returns 1.0 atan(1.0) returns pi/4 tan(0.0) returns 0.0 log(2.0) returns exp(2.0) returns pow(4,1.5) returns 8.00 = ceil(2.67) returns 3.0 floor(2.67) returns 2.0 Random(n) returns random int 0.. n-1 Prof. Amr Goneid, AUC 25
26 Using a Library Function //Computes w = (1+z) 2.6 z 1.45 / (1-z) 3.2 # include <cmath> // pow function # include <iostream> // I/O functions using namespace std; int main ( ) { float w, z ; cout << Enter z: ; cin >> z ; w = pow(1+z,2.6) * pow(z,1.45) / pow(1-z,3.2); cout << Value of w = << w << endl; return 0 ; } Prof. Amr Goneid, AUC 26
27 3. Expressions & Assignment Syntax Arithmetic Expressions Logical Expressions Relational Expressions Assignment Statement Overall Operator Precedence More on Arithmetic and Assignment Prof. Amr Goneid, AUC 27
28 3.1 Syntax Form1 Form2 U-Op operand operand B-Op operand e.g -5!found a + b x > y + 32 (c >= 65) && (c <=90) Prof. Amr Goneid, AUC 28
29 Syntax Operands: Constants e.g. 5 false Variables e.g. x a[3] Functions e.g. sqrt(7) sin(y) Expression e.g. x + y a > b Operators: Arithmetic Logical Relational Assignment Compound Prof. Amr Goneid, AUC 29
30 3.2 Arithmetic Expressions Operators: Unary Minus and Plus (-) (+) Multiplication, Division, Modulus ( * / % ) Addition, Subtraction ( + - ) Examples: -5 a*b sqrt(5)/2.0 x % m y - b (a+sqrt(y))/(6- sin(pi*y)) m / n - k Prof. Amr Goneid, AUC 30
31 Arithmetic Expressions Examples: 5 / 2 is 2 (int operands, int value) 5.0 / 2.0 (float operands, float value) 5.0 / 2 (Mixed operands, float value) 7 % 2 is 1 3 % 5 is 3 (% for int only) /3 + 5 is 9 but (2 + 6) / (3 + 5) is 1 Prof. Amr Goneid, AUC 31
32 Arithmetic Expressions Operator Precedence: ( ) Highest unary + - * / % Add (+), Subtract (-) Lowest Prof. Amr Goneid, AUC 32
33 Example How many Hours, Minutes, Seconds are in n seconds? int n, hrs, mins, secs, rem; hrs = n / 3600; rem = n % 3600; mins = rem / 60; secs = rem % 60; Prof. Amr Goneid, AUC 33
34 3.3 Logical Expressions Operators:! (unary not) (or) && (and) Operands of Boolean type Result: Boolean ( true, false ) Examples:! true is false a b! (x<y) c && d Prof. Amr Goneid, AUC 34
35 Truth Table for Logical Operators 0 false, 1 true x y!x x y x && y Prof. Amr Goneid, AUC 35
36 3.4 Relational Expressions Operators: == < > <= >=!= Result: Boolean Examples: a > b c <= 6 sqrt(x) >= y z!= w a+b == c+d A < a name1!= name2 Prof. Amr Goneid, AUC 36
37 3.5 Assignment Statement The Assignment operator ( = ) Syntax: variable = expression; Examples: int x, y ; bool a,b,c ; x = 3; y = 2*x; a = true; a = x > y; c = a b; Prof. Amr Goneid, AUC 37
38 3.6 Overall Operator Precedence Parentheses ( ) Highest Unary:! + - Multiplicative: * / % Additive: + - Relational: < > <= >= Relational: ==!= Logical: && Logical: Assignment = Lowest Example: d =!(x+y < z) && (2*b == c); Prof. Amr Goneid, AUC 38
39 3.7 More on Arithmetic and Assignment Increment and Decrement Operators: ++operand --operand (increment/decrement operand then evaluate expression) operand++ operand-- (evaluate expression then increment/decrement operand ) e.g. n++, ++n is shorthand for n = n + 1 Prof. Amr Goneid, AUC 39
40 Increment and Decrement Operators Examples: int a = 3; int b = 5; int c; c = a + b++; yields a == 3, b == 6, c == 8 c = a + ++b; yields a == 3, b == 6, c == 9 c = a + b--; yields a == 3, b == 4, c == 8 c = a + --b; yields a == 3, b == 4, c == 7 Prof. Amr Goneid, AUC 40
41 Multiple & Compound Assignment Multiple Assignment: c = a = b; d = (a = b + 3) / c; Compound Assignment: (Reassign after doing operation) e.g. a = a + b; //var = var op expr; can be written: a += b; //var compound-op expr; compound operators += -= *= /= %= e.g. c /= (x + 2); is c = c / (x + 2); Prof. Amr Goneid, AUC 41
42 4. Simple Input/Output Prof. Amr Goneid, AUC 42
43 Simple Input/Output Standard I/O Devices: cin standard input stream (keyboard) cout standard output stream (screen) Defined in #include <iostream> Extraction Operator: >> DataVariable extracts one data item from cin to a variable Insertion Operator: << DataElement inserts one data element in cout Prof. Amr Goneid, AUC 43
44 Simple Input/Output Keyboard Input: cin >> v ; cin >> v1 >> v2 ; Variables are entered with spaces between them. ENTER or RETURN end input. e.g. int a,b; float x; string name; cin >> name; cin >> a >> b >> x; A.W.Wolf Prof. Amr Goneid, AUC 44
45 Data Types and cin Don t mix types with cin int x; cin >> x; If Keyboard input is 16.6 The value placed in x would be 16 Prof. Amr Goneid, AUC 45
46 Other Characteristics of cin Leading blanks ignored (floats, int, char, bool and strings) Char read 1 at a time (1 non blank) Case issues int or float will read until space Stings same as int and float Prof. Amr Goneid, AUC 46
47 Simple Input/Output Screen Output: cout << d; cout << d1 << d2..; Examples: int a,b,c; float z; cout << Enter a,b,c: ; Enter a,b,c: cin >> a >> b >> c; cout << a << 2*b << endl; 6004 z = sqrt(a + b * c); cout << Result is ; cout << z; Result is Prof. Amr Goneid, AUC 47
48 Example Program : Hello.cpp // FILE: Hello.cpp // DISPLAYS A USER'S NAME #include <iostream> #include <string> using namespace std; int main () { Prof. Amr Goneid, AUC 48
49 Hello.cpp char letter1, letter2; string lastname; } // Enter letters and print message. cout << "Enter 2 initials and last name: "; cin >> letter1 >> letter2 >> lastname; cout << "Hello " << letter1 << ". " << letter2 << ". " << lastname << "! "; cout << "We hope you enjoy studying C++." << endl; return 0; Prof. Amr Goneid, AUC 49
50 Hello.cpp Program Input/output Enter 2 initials and last name: SAWolf Hello S. A. Wolf! We hope you enjoy studying C++. Prof. Amr Goneid, AUC 50
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 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 informationChapter 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 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 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 information6.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 informationCharacter Set. The character set of C represents alphabet, digit or any symbol used to represent information. Digits 0, 1, 2, 3, 9
Character Set The character set of C represents alphabet, digit or any symbol used to represent information. Types Uppercase Alphabets Lowercase Alphabets Character Set A, B, C, Y, Z a, b, c, y, z Digits
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 informationWeek 2: Console I/O and Operators Arithmetic Operators. Integer Division. Arithmetic Operators. Gaddis: Chapter 3 (2.14,3.1-6,3.9-10,5.
Week 2: Console I/O and Operators Gaddis: Chapter 3 (2.14,3.1-6,3.9-10,5.1) CS 1428 Fall 2014 Jill Seaman 1 2.14 Arithmetic Operators An operator is a symbol that tells the computer to perform specific
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 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 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 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 information! A program is a set of instructions that the. ! It must be translated. ! Variable: portion of memory that stores a value. char
Week 1 Operators, Data Types & I/O Gaddis: Chapters 1, 2, 3 CS 5301 Fall 2016 Jill Seaman Programming A program is a set of instructions that the computer follows to perform a task It must be translated
More informationEngineering 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 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 informationChapter 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 informationChapter 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 informationChapter 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 informationC++ 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 informationComputer 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 information1. 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 informationLECTURE 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 information3.1. Chapter 3: The cin Object. Expressions and Interactivity
Chapter 3: Expressions and Interactivity 3.1 The cin Object Copyright 2009 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 3-1 The cin Object Standard input stream object, normally the keyboard,
More informationCHAPTER 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 informationCreating 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 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 information2.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 informationChapter 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 informationEngineering 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 informationChapter 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 informationChapter 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 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 informationCSc 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 informationProgramming Fundamentals. With C++ Variable Declaration, Evaluation and Assignment 1
300580 Programming Fundamentals 3 With C++ Variable Declaration, Evaluation and Assignment 1 Today s Topics Variable declaration Assignment to variables Typecasting Counting Mathematical functions Keyboard
More informationIntroduction to C++ with content from
Introduction to C++ with content from www.cplusplus.com 2 Introduction C++ widely-used general-purpose programming language procedural and object-oriented support strong support created by Bjarne Stroustrup
More informationC++ 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 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 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 informationProgramming Language. Functions. Eng. Anis Nazer First Semester
Programming Language Functions Eng. Anis Nazer First Semester 2016-2017 Definitions Function : a set of statements that are written once, and can be executed upon request Functions are separate entities
More informationPART I. Part II Answer to all the questions 1. What is meant by a token? Name the token available in C++.
Unit - III CHAPTER - 9 INTRODUCTION TO C++ Choose the correct answer. PART I 1. Who developed C++? (a) Charles Babbage (b) Bjarne Stroustrup (c) Bill Gates (d) Sundar Pichai 2. What was the original name
More informationChapter 3. Numeric Types, Expressions, and Output
Chapter 3 Numeric Types, Expressions, and Output 1 Chapter 3 Topics Constants of Type int and float Evaluating Arithmetic Expressions Implicit Type Coercion and Explicit Type Conversion Calling a Value-Returning
More informationIntroduction. Following are the types of operators: Unary requires a single operand Binary requires two operands Ternary requires three operands
Introduction Operators are the symbols which operates on value or a variable. It tells the compiler to perform certain mathematical or logical manipulations. Can be of following categories: Unary requires
More informationFundamental Data Types. CSE 130: Introduction to Programming in C Stony Brook University
Fundamental Data Types CSE 130: Introduction to Programming in C Stony Brook University Program Organization in C The C System C consists of several parts: The C language The preprocessor The compiler
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 informationCSCI 123 Introduction to Programming Concepts in C++
CSCI 123 Introduction to Programming Concepts in C++ Brad Rippe C++ Basics C++ layout Include directive #include using namespace std; int main() { } statement1; statement; return 0; Every program
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 informationThe 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 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 informationBasic program The following is a basic program in C++; Basic C++ Source Code Compiler Object Code Linker (with libraries) Executable
Basic C++ Overview C++ is a version of the older C programming language. This is a language that is used for a wide variety of applications and which has a mature base of compilers and libraries. C++ is
More informationIntroduction to Programming EC-105. Lecture 2
Introduction to Programming EC-105 Lecture 2 Input and Output A data stream is a sequence of data - Typically in the form of characters or numbers An input stream is data for the program to use - Typically
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 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 informationCS313D: ADVANCED PROGRAMMING LANGUAGE
CS313D: ADVANCED PROGRAMMING LANGUAGE Computer Science department Lecture 2 : C# Language Basics Lecture Contents 2 The C# language First program Variables and constants Input/output Expressions and casting
More informationFeatures 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 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 informationCSCE 110 PROGRAMMING FUNDAMENTALS
CSCE 110 PROGRAMMING FUNDAMENTALS WITH C++ Prof. Amr Goneid AUC Part 15. Dictionaries (1): A Key Table Class Prof. amr Goneid, AUC 1 Dictionaries(1): A Key Table Class Prof. Amr Goneid, AUC 2 A Key Table
More informationChapter 3: Operators, Expressions and Type Conversion
101 Chapter 3 Operators, Expressions and Type Conversion Chapter 3: Operators, Expressions and Type Conversion Objectives To use basic arithmetic operators. To use increment and decrement operators. To
More informationDifferentiate Between Keywords and Identifiers
History of C? Why we use C programming language Martin Richards developed a high-level computer language called BCPL in the year 1967. The intention was to develop a language for writing an operating system(os)
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 informationDepartment of Computer Science
Department of Computer Science Definition An operator is a symbol (+,-,*,/) that directs the computer to perform certain mathematical or logical manipulations and is usually used to manipulate data and
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 informationOn a 64-bit CPU. Size/Range vary by CPU model and Word size.
On a 64-bit CPU. Size/Range vary by CPU model and Word size. unsigned short x; //range 0 to 65553 signed short x; //range ± 32767 short x; //assumed signed There are (usually) no unsigned floats or doubles.
More informationDEPARTMENT OF MATHS, MJ COLLEGE
T. Y. B.Sc. Mathematics MTH- 356 (A) : Programming in C Unit 1 : Basic Concepts Syllabus : Introduction, Character set, C token, Keywords, Constants, Variables, Data types, Symbolic constants, Over flow,
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 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 informationI Internal Examination Sept Class: - BCA I Subject: - Principles of Programming Lang. (BCA 104) MM: 40 Set: A Time: 1 ½ Hrs.
I Internal Examination Sept. 2018 Class: - BCA I Subject: - Principles of Programming Lang. (BCA 104) MM: 40 Set: A Time: 1 ½ Hrs. [I]Very short answer questions (Max 40 words). (5 * 2 = 10) 1. What is
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 informationOutline. Performing Computations. Outline (cont) Expressions in C. Some Expression Formats. Types for Operands
Performing Computations C provides operators that can be applied to calculate expressions: tax is 8.5% of the total sale expression: tax = 0.085 * totalsale Need to specify what operations are legal, how
More information2 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 informationUnit 3. Operators. School of Science and Technology INTRODUCTION
INTRODUCTION Operators Unit 3 In the previous units (unit 1 and 2) you have learned about the basics of computer programming, different data types, constants, keywords and basic structure of a C program.
More informationTutorial-2a: First steps with C++ programming
Programming for Scientists Tutorial 2a 1 / 18 HTTP://WWW.HEP.LU.SE/COURSES/MNXB01 Introduction to Programming and Computing for Scientists Tutorial-2a: First steps with C++ programming Programming for
More informationOperators and Expressions:
Operators and Expressions: Operators and expression using numeric and relational operators, mixed operands, type conversion, logical operators, bit operations, assignment operator, operator precedence
More informationChapter Overview. C++ Basics. Variables and Assignments. Variables and Assignments. Keywords. Identifiers. 2.1 Variables and Assignments
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 Copyright 2011 Pearson Addison-Wesley. All rights
More informationDeclaration and Memory
Declaration and Memory With the declaration int width; the compiler will set aside a 4-byte (32-bit) block of memory (see right) The compiler has a symbol table, which will have an entry such as Identifier
More informationChapter 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 informationBoolean Algebra Boolean Algebra
What is the result and type of the following expressions? Int x=2, y=15; float u=2.0, v=15.0; -x x+y x-y x*v y / x x/y y%x x%y u*v u/v v/u u%v x * u (x+y)*u u / (x-x) x++ u++ u = --x u = x -- u *= ++x
More informationADARSH 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 informationSECTION II: LANGUAGE BASICS
Chapter 5 SECTION II: LANGUAGE BASICS Operators Chapter 04: Basic Fundamentals demonstrated declaring and initializing variables. This chapter depicts how to do something with them, using operators. Operators
More informationLecture 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 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 informationLesson 3 Introduction to Programming in C
jgromero@inf.uc3m.es Lesson 3 Introduction to Programming in C Programming Grade in Industrial Technology Engineering This work is licensed under a Creative Commons Reconocimiento-NoComercial-CompartirIgual
More informationSummary of basic C++-commands
Summary of basic C++-commands K. Vollmayr-Lee, O. Ippisch April 13, 2010 1 Compiling To compile a C++-program, you can use either g++ or c++. g++ -o executable_filename.out sourcefilename.cc c++ -o executable_filename.out
More information7/8/10 KEY CONCEPTS. Problem COMP 10 EXPLORING COMPUTER SCIENCE. Algorithm. Lecture 2 Variables, Types, and Programs. Program PROBLEM SOLVING
KEY CONCEPTS COMP 10 EXPLORING COMPUTER SCIENCE Lecture 2 Variables, Types, and Programs Problem Definition of task to be performed (by a computer) Algorithm A particular sequence of steps that will solve
More information3.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 informationBinghamton University. CS-120 Summer Introduction to C. Text: Introduction to Computer Systems : Chapters 11, 12, 14, 13
Introduction to C Text: Introduction to Computer Systems : Chapters 11, 12, 14, 13 Problem: Too Many Details For example: Lab 7 Bubble Sort Needed to keep track of too many details! Outer Loop When do
More informationCSC 307 DATA STRUCTURES AND ALGORITHM ANALYSIS IN C++ SPRING 2011
CSC 307 DATA STRUCTURES AND ALGORITHM ANALYSIS IN C++ SPRING 2011 Date: 01/18/2011 (Due date: 01/20/2011) Name and ID (print): CHAPTER 6 USER-DEFINED FUNCTIONS I 1. The C++ function pow has parameters.
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 informationOperators. Lecture 3 COP 3014 Spring January 16, 2018
Operators Lecture 3 COP 3014 Spring 2018 January 16, 2018 Operators Special built-in symbols that have functionality, and work on operands operand an input to an operator Arity - how many operands an operator
More informationCOMPUTER SCIENCE HIGHER SECONDARY FIRST YEAR. VOLUME II - CHAPTER 10 PROBLEM SOLVING TECHNIQUES AND C PROGRAMMING 1,2,3 & 5 MARKS
COMPUTER SCIENCE HIGHER SECONDARY FIRST YEAR VOLUME II - CHAPTER 10 PROBLEM SOLVING TECHNIQUES AND C PROGRAMMING 1,2,3 & 5 MARKS S.LAWRENCE CHRISTOPHER, M.C.A., B.Ed., LECTURER IN COMPUTER SCIENCE PONDICHERRY
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 informationUNIT - 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 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 information- Developed by Bjarne Stroustrup at AT&T Bell Laboratories
Background 1 C++ is based on C; in fact, C is almost a subset of C++ - Developed by Bjarne Stroustrup at AT&T Bell Laboratories Standard C++ - Was formally adopted by American National Standards Institute
More informationc++ 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 informationCourse Outline Introduction to C-Programming
ECE3411 Fall 2015 Lecture 1a. Course Outline Introduction to C-Programming Marten van Dijk, Syed Kamran Haider Department of Electrical & Computer Engineering University of Connecticut Email: {vandijk,
More informationBasics of Programming
Unit 2 Basics of Programming Problem Analysis When we are going to develop any solution to the problem, we must fully understand the nature of the problem and what we want the program to do. Without the
More informationBASIC ELEMENTS OF A COMPUTER PROGRAM
BASIC ELEMENTS OF A COMPUTER PROGRAM CSC128 FUNDAMENTALS OF COMPUTER PROBLEM SOLVING LOGO Contents 1 Identifier 2 3 Rules for naming and declaring data variables Basic data types 4 Arithmetic operators
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 informationBasic memory model Using functions Writing functions. Basics Prototypes Parameters Return types Functions and memory Names and namespaces
Basic memory model Using functions Writing functions Basics Prototypes Parameters Return types Functions and memory Names and namespaces When a program runs it requires main memory (RAM) space for Program
More information