PROGRAMMING IN C++ CVIČENÍ

Similar documents
Programmazione. Prof. Marco Bertini

Lab 1: First Steps in C++ - Eclipse

CS2141 Software Development using C/C++ C++ Basics

Announcements. CSCI 334: Principles of Programming Languages. Lecture 18: C/C++ Announcements. Announcements. Instructor: Dan Barowy

C++ Namespaces, Exceptions

CS 376b Computer Vision

CS242 COMPUTER PROGRAMMING

Communication With the Outside World

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

A506 / C201 Computer Programming II Placement Exam Sample Questions. For each of the following, choose the most appropriate answer (2pts each).

CE221 Programming in C++ Part 1 Introduction

CSE 333. Lecture 10 - references, const, classes. Hal Perkins Paul G. Allen School of Computer Science & Engineering University of Washington

Basic program The following is a basic program in C++; Basic C++ Source Code Compiler Object Code Linker (with libraries) Executable

Computer Science II Lecture 1 Introduction and Background

ECE 462 Object-Oriented Programming using C++ and Java Design Issues and Multiple Inheritance in C++

Computer Programming : C++

Lecture 5 Files and Streams

Your first C++ program

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

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

Exceptions. CS162: Introduction to Computer Science II. Exceptions. Exceptions. Exceptions. Exceptions. Exceptions

Java Basic Syntax. Java vs C++ Wojciech Frohmberg / OOP Laboratory. Poznan University of Technology

Outline. Introduction. Arrays declarations and initialization. Const variables. Character arrays. Static arrays. Examples.

Exercise 1.1 Hello world

BIL 104E Introduction to Scientific and Engineering Computing. Lecture 14

2 2

Introduction to C++ Professor Hugh C. Lauer CS-2303, System Programming Concepts

Lecture Notes CPSC 224 (Spring 2012) Today... Java basics. S. Bowers 1 of 8

Programming in C. Pointers and Arrays

Biostatistics 615/815 - Lecture 2 Introduction to C++ Programming

Biostatistics 615/815 - Lecture 2 Introduction to C++ Programming

C++ Lab 03 - C++ Functions

C++ Basics. Brian A. Malloy. References Data Expressions Control Structures Functions. Slide 1 of 24. Go Back. Full Screen. Quit.

Introduction to C++ Systems Programming

Call-by-Type Functions in C++ Command-Line Arguments in C++ CS 16: Solving Problems with Computers I Lecture #5

GCC : From 2.95 to 3.2

C++ Constructor Insanity

Introduction to Programming

Lab 8. Follow along with your TA as they demo GDB. Make sure you understand all of the commands, how and when to use them.

Introduction. Lecture 5 Files and Streams FILE * FILE *

Computer Science II Lecture 2 Strings, Vectors and Recursion

CSE 333 Final Exam June 6, 2017 Sample Solution

Midterm Exam 5 April 20, 2015

CSCI-1200 Data Structures Spring 2015 Lecture 2 STL Strings & Vectors

CSE 333 Lecture 9 - intro to C++

Biostatistics 615/815 Implementing Fisher s Exact Test

UEE1303(1070) S 12 Object-Oriented Programming in C++

Lab 2: ADT Design & Implementation

More on Func*ons Command Line Arguments CS 16: Solving Problems with Computers I Lecture #8

Physics 234: Computational Physics

OpenCV. Basics. Department of Electrical Engineering and Computer Science

HW3a solution. L1 implies there must be an f1 in Base L2 implies there must be an f2 in Base. So we know there is an f1 and f2 in Base

Unified Modeling Language a case study

Program Organization and Comments

Agenda. The main body and cout. Fundamental data types. Declarations and definitions. Control structures

EMBEDDED SYSTEMS PROGRAMMING Language Basics

CS

Bruce Merry. IOI Training Dec 2013

Object Oriented Design

Overloading Functions & Command Line Use in C++ CS 16: Solving Problems with Computers I Lecture #6

Intermediate Programming, Spring 2017*

PROGRAMMING IN C++ KAUSIK DATTA 18-Oct-2017

Lab#5 Due Wednesday, February 25, at the start of class. Purpose: To develop familiarity with C++ pointer variables

Why C++ is much more fun than C (C++ FAQ)?

eingebetteter Systeme

More Functions. Pass by Value. Example: Exchange two numbers. Storage Classes. Passing Parameters by Reference. Pass by value and by reference

CSCI-1200 Data Structures Fall 2017 Lecture 2 STL Strings & Vectors

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:

Scientific Computing

Use the dot operator to access a member of a specific object.

CSE au Midterm Exam Nov. 2, 2018 Sample Solution

This chapter introduces the notion of namespace. We also describe how to manage input and output with C++ commands via the terminal or files.

Fast Introduction to Object Oriented Programming and C++

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

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:

AN OVERVIEW OF C++ 1

Content. Input Output Devices File access Function of File I/O Redirection Command-line arguments

COMP322 - Introduction to C++

CS3157: Advanced Programming. Outline

Fundamentals of Programming. Lecture 19 Hamed Rasifard

CE221 Programming in C++ Part 2 References and Pointers, Arrays and Strings

Direct Memory Access. Lecture 2 Pointer Revision Command Line Arguments. What happens when we use pointers. Same again with pictures

Financial computing with C++

SU2017. LAB 1 (May 4/9) Introduction to C, Function Declaration vs. Definition, Basic I/O (scanf/printf, getchar/putchar)

PROGRAMOVÁNÍ V C++ CVIČENÍ. Michal Brabec

This chapter groups some modelling exercises, only some of which involve UML.

Chapter 2. Procedural Programming

W3101: Programming Languages C++ Ramana Isukapalli

Looping and Counting. Lecture 3 Hartmut Kaiser hkaiser/fall_2012/csc1254.html

Tutorial-2a: First steps with C++ programming

CSE 12 Spring 2016 Week One, Lecture Two

Programming in C. What is C?... What is C?

Programming in C UVic SEng 265

Fundamental File Processing Operations 2. Fundamental File Processing Operations

Looping and Counting. Lecture 3. Hartmut Kaiser hkaiser/fall_2011/csc1254.html

PIC 10A Objects/Classes

APPENDIX A : KEYWORDS... 2 APPENDIX B : OPERATORS... 3 APPENDIX C : OPERATOR PRECEDENCE... 4 APPENDIX D : ESCAPE SEQUENCES... 5

BSc (Hons) Computer Science. with Network Security. Examinations for / Semester1

Programming in C. What is C?... What is C?

Introduction to Programming

Transcription:

PROGRAMMING IN C++ CVIČENÍ

INFORMACE Michal Brabec http://www.ksi.mff.cuni.cz/ http://www.ksi.mff.cuni.cz/~brabec/ brabec@ksi.mff.cuni.cz gmichal.brabec@gmail.com

REQUIREMENTS FOR COURSE CREDIT Basic requirements are the same for all groups Successful completion of final credit test 1. and 2. attempt during the exam period... 3. in april 2-3 hour work in lab, successful completion an application Completion and presentation of a credit application Specification of requirements end of November Presentation of an alpha version do 29.3.2015 Finished implementation and documentation do 24.5.2015 Additional requirements defined by the teacher Succesfull completion of one homework (application) It is possible to specify individual requirements if there is a reason and they must be agreed upon at the beginning of the course

INTRODUCTION TO C++ Introduction to basics of C++ programming language Visual studio basics

BASIC TYPES Native types: Integral numbers int, long, unsinged, unsigned long Real numbers float, double Characters char, unsigned char, (wchar_t) Complex types (user defined): Structures Classes Special types (renamed) Declared using typedef

VARIABLES Definition of a variable: Data_type var_name = initial_value; Type can be any known data type Initial value must be convertible to the data type Member variables Same definition Belong to a class (structure) Initialization in a constructor

FUNCTIONS AND METHODS Definition of a function: Return_type fun_name (parameters) { code } Parameters are defined the same way as variables Parameters can be treated as local variables The main function int main() {} int main(int argc, char** argv) {} void main() {} (Visual studio) Return value 0 (successful completion) or error code (!= 0)

DECLARATION VS. DEFINITION Declaration Informs the compiler about a data type, function or variable Does not create anything Useless without definition Definition Creates variable including its initialization Defines the body for a function Defines the content of a data type (methods and members) Two different definition cause compilation error

DECLARATION & DEFINITION Declaration int intvar; int converttoint(float f); class UserData; Definition int intvar = 10; int converttoint(float f) { return 0; } class UserData { int intmember; };

DECLARATION AND INCLUDE Data types, functions and variables can be defined in separate files Every file should contain a single data type or a small set of similar functions, but the language does not forbid other solutions Data types and functions declared in other files must be included into a file where they are used Declarations from standard library #include <header.h> Local declaration #include header.h

INPUT & OUTPUT Input and output done by streams Streams are special classes in standard library Streams can be used for input and out to command line and file (network) They support general optimization (buffering, binary files ) Command line stream declaration #include <iostream> Other types in different files All classes are in the namespace std

HELLO WORLD Basic application Contains many important constructs All classes from standard are fully qualified (prevents conflicts in names) #include <iostream> void main() { std::cout << "Hello world!" << std::endl; } getchar(); // forces the program to wait for user input at the end;

APPLICATION PARAMETERS Parameters passed to main as standard parameters Parameters can be passed from command line, shortcut or development environment Parameters can be specified in Visual studio for faster debugging int argc contains the number of all application parameters char** argv parameters passed as an array of strings

PARAMETERS EXAMPLE > \program.exe Hello world Paremeters of the main function are: argc: 3 argv: \program.exe (not in standard) Hello World The first parameter contains the name of the application but this is not specified in C++ standard and this parameter can be omitted

HELLO WORLD REVISITED Second version of the basic application It prints the number of parameters and the alue of the second parameter The verification of parameter count is important! #include <iostream> int main(int argc, char** argv) { // argument[0] is the application file name (+path) std::cout << argc << std::endl; if(argc > 1) std::cout << argv[1] << std::endl; // writes only a single word } getchar(); return 0;

LOCAL VARIABLES Variables defined in function Can be used only inside the function and they exist only while the function is executed Initialized immediately after declaration #include <iostream> int main(int argc, char** argv) { // argument[0] is the application file name (+path) std::cout << argc << std::endl; int count = argc; if(count > 1) std::cout << argv[1] << std::endl; // writes only a single word } getchar(); return 0;

DECLARATION OF A CLASS class Name { private: member <= variable protected: member public: metoda <= function };