Chap 0: Overview. Overview of basic C++ syntax Refresh programming basics C++ Vs. Java differences Coding conventions used. EECS 268 Programming II 1

Similar documents
Aryan College. Fundamental of C Programming. Unit I: Q1. What will be the value of the following expression? (2017) A + 9

CPE Summer 2015 Exam I (150 pts) June 18, 2015

Chapter 2. Procedural Programming

C-LANGUAGE CURRICULAM

CSI33 Data Structures

Euclid s algorithm, 133

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

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

Creating a C++ Program

6.096 Introduction to C++ January (IAP) 2009

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

UNIT- 3 Introduction to C++

Fundamental of Programming (C)


Object-Oriented Programming

C programming basics T3-1 -

PIC 10A Pointers, Arrays, and Dynamic Memory Allocation. Ernest Ryu UCLA Mathematics

Model Viva Questions for Programming in C lab

Long Questions. 7. How does union help in storing the values? How it differs from structure?

Introduction to Programming Using Java (98-388)

Laboratory 2: Programming Basics and Variables. Lecture notes: 1. A quick review of hello_comment.c 2. Some useful information

C++ Quick Guide. Advertisements

B.V. Patel Institute of Business Management, Computer & Information Technology, Uka Tarsadia University

Fundamentals of Programming

CS 115 Exam 3, Spring 2010

COMP322 - Introduction to C++ Lecture 02 - Basics of C++

Tokens, Expressions and Control Structures

C-String Library Functions

This exam is to be taken by yourself with closed books, closed notes, no calculators.

Computer Programming. C Array is a collection of data belongings to the same data type. data_type array_name[array_size];

Name Section: M/W T/TH Number Definition Matching (6 Points)

Lecture 2: C Programming Basic

CS201- Introduction to Programming Latest Solved Mcqs from Midterm Papers May 07,2011. MIDTERM EXAMINATION Spring 2010

7/8/10 KEY CONCEPTS. Problem COMP 10 EXPLORING COMPUTER SCIENCE. Algorithm. Lecture 2 Variables, Types, and Programs. Program PROBLEM SOLVING

Short Notes of CS201

CS201 - Introduction to Programming Glossary By

CSCI 171 Chapter Outlines

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

Welcome 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. Hello, Let s Review. Hello, Let s Review. How to Review 8/19/ Review. Here s a simple C++ program:

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

Chapter 8 Arrays and Strings. Objectives. Objectives (cont d.) Introduction. Arrays 12/23/2016. In this chapter, you will:

Write a C program using arrays and structure

LOGO BASIC ELEMENTS OF A COMPUTER PROGRAM

Introduction to Algorithms and Data Structures. Lecture 6 - Stringing Along - Character and String Manipulation

Chapter 2: Introduction to C++

WHAT POINTERS REALLY ARE

CSC209H Lecture 4. Dan Zingaro. January 28, 2015

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

ONE DIMENSIONAL ARRAYS

Scheme G. Sample Test Paper-I. Course Name : Computer Engineering Group Course Code : CO/CD/CM/CW/IF Semester : Second Subject Tile : Programming in C

CS150 Intro to CS I. Fall Fall 2017 CS150 - Intro to CS I 1

Programming. C++ Basics

Programming Fundamentals. With C++ Variable Declaration, Evaluation and Assignment 1

Objectives. Chapter 4: Control Structures I (Selection) Objectives (cont d.) Control Structures. Control Structures (cont d.) Relational Operators

COMP322 - Introduction to C++

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

Review for COSC 120 8/31/2017. Review for COSC 120 Computer Systems. Review for COSC 120 Computer Structure

Makefiles Makefiles should begin with a comment section of the following form and with the following information filled in:

CSCI 1061U Programming Workshop 2. C++ Basics

UNIT 6. STRUCTURED DATA TYPES PART 1: ARRAYS

INTRODUCTION 1 AND REVIEW

Name Section: M/W T/TH Number Definition Matching (8 Points)

mith College Computer Science CSC270 Spring 2016 Circuits and Systems Lecture Notes, Week 11 Dominique Thiébaut

ARRAYS(II Unit Part II)

Chapter 4: Control Structures I (Selection) Objectives. Objectives (cont d.) Control Structures. Control Structures (cont d.

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

CS 326 Operating Systems C Programming. Greg Benson Department of Computer Science University of San Francisco

COMP 202 Java in one week

Simple File I/O.

The C++ Language. Arizona State University 1

LECTURE 02 INTRODUCTION TO C++

Lecture 2 Tao Wang 1

Pace University. Fundamental Concepts of CS121 1

! A program is a set of instructions that the. ! It must be translated. ! Variable: portion of memory that stores a value. char

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

Chapter 2: Basic Elements of C++

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

C Fundamentals & Formatted Input/Output. adopted from KNK C Programming : A Modern Approach

PRINCIPLES OF OPERATING SYSTEMS

CS3157: Advanced Programming. Outline

Variables Data types Variable I/O. C introduction. Variables. Variables 1 / 14

CSE 5A Final Fall 2006

C: How to Program. Week /Mar/05

C# Fundamentals. Hans-Wolfgang Loidl School of Mathematical and Computer Sciences, Heriot-Watt University, Edinburgh

C BOOTCAMP DAY 2. CS3600, Northeastern University. Alan Mislove. Slides adapted from Anandha Gopalan s CS132 course at Univ.

Variables in C. Variables in C. What Are Variables in C? CMSC 104, Fall 2012 John Y. Park

PES INSTITUTE OF TECHNOLOGY (BSC) I MCA, First IA Test, November 2015 Programming Using C (13MCA11) Solution Set Faculty: Jeny Jijo

Chapter 2 Basic Elements of C++

Binghamton University. CS-211 Fall Syntax. What the Compiler needs to understand your program

cs3157: c++ lecture #2 (mon-11-apr-2005) chronology of some programming languages... C++ vs Java identifiers.

Engineering Problem Solving with C++, Etter

AN OVERVIEW OF C, PART 3. CSE 130: Introduction to Programming in C Stony Brook University

Intro to Programming & C Why Program? 1.2 Computer Systems: Hardware and Software. Why Learn to Program?

Compiling and Running a C Program in Unix

Input and Output File (Files and Stream )

Model Viva Questions for Programming in C lab

Pointers, Dynamic Data, and Reference Types

Introduction to string

Chapter 2 - Introduction to C Programming

Transcription:

Chap 0: Overview Overview of basic C++ syntax Refresh programming basics C++ Vs. Java differences Coding conventions used EECS 268 Programming II 1

Basics - 1 Comments single line: // multi-line: /* */ Identifiers and keywords {_a-za-z}{_a-za-z0-9}* keywords are reserved words Fundamental data types bool, char, int, float, double modifiers: signed/unsigned, short/long EECS 268 Programming II 2

Basics - 2 Variables double radius; int count, i; Constants literal: A, 2 named: const double PI = 3.14159; typedef statement typedef double Real; EECS 268 Programming II 3

Basics - 3 Assignments and expressions arithmetic expressions relational and logical expressions Implicit type conversion automatic type conversion with no loss of precision Explicit type conversion static_cast<type>(expression) int ivol = static_cast<int>(volume); EECS 268 Programming II 4

Basics - 4 Input int a; cin >> a; int a; scanf( %d, &a); Output cout << Output is: << a << \n ; printf( Output is: %d\n, a); EECS 268 Programming II see A1-basics.cpp 5

Basics - 5 Functions type name (formal argument list) { body } Selection statements if, if-else, if-elseif-else, switch-case Iteration statements while, do-while, for break, continue EECS 268 Programming II 6

Basics - 6 Arrays one dimensional: int arr[100]; arr[i] = 10; multi-dimensional: int arr[100][10]; arr[i][j] = 10; arrays are passed to functions by reference C++ strings string str = EECS 268 ; size(), length(), compare, concatenate, index, etc. C strings char str[100]; Null character \0 terminates the string strlen(), strcpy(), strcmp(), strcat(), index, etc. EECS 268 Programming II 7

Basics - 7 Structures to group data items struct Person{ string name; int age; double gpa; }; struct Person students[100]; students[0].name = Adam Smith ; students[0].age = 20; structs are passed by value to another function EECS 268 Programming II see A1-CppJava.cpp 8

Basics - 8 File input / output provide persistent storage ifstream, ofstream, fstream ifstream infile; infile.open( file.txt ); infile >> ch; infile.get(ch); ch = infile.peek(); infile.ignore(n); ofstream ofile; ofile.open(filename); ofile << ch; ofile.put(ch); ofile.open( file, ios::app); EECS 268 Programming II 9 see A1-fcopy.cpp

C++ (Compared to Java) structs used to group data variables. C++ uses preprocessor for macros, file-inclusion. C++ can have stand-alone functions. Constants/variables can be defined globally, in classes, or methods. bool (vs. boolean) Explicit memory deallocation (delete) See: http://people.eecs.ku.edu/~miller/courses/javatoc++.html Appendix A.12 in textbook EECS 268 Programming II see A1-BookStoreCustomer.cpp 10

Examples See A1-basics.cpp See A1-fcopy.cpp See A1-CppJava --.cpp /.java See A1-BookStoreCustomer --.cpp /.java EECS 268 Programming II 11

Coding Conventions Used Need to make it easier to read and maintain code very important for large code bases when multiple contributors Multiple coding styles are prevalent people have differing tastes and preferences We impose some common coding practices for this class EECS 268 Programming II 12

Coding Conventions Used Make Files to keep list of dependencies and to build all your project files discussed further in Lab-1 Header (.h) and implementation (.cpp) files ADT interface (class definition) should be in.h file Comments /* */ -- for block (multi-line) comments // -- for single-line comments EECS 268 Programming II 13

Coding Conventions Used Indentation 2 or 4 spaces For function definitions open/close brace should be on its own line block comment before each function tells what it does For braces within functions (loops/branches) open brace should be on same line as construct close brace should be on its own line Line width a maximum of 80 characters on a single line EECS 268 Programming II 14

Coding Conventions Used Vertical white space and comments blank line between consecutive code constructs comments before important code constructs Horizontal white space make it readable! if((a==b) (c<a)) over if( ( a == b ) ( c < a ) ) and if((a==b) (c<a)) EECS 268 Programming II 15