Vervolg C Hogeschool van Utrecht / Institute for Computer, Communication and Media Technology 1 Onderwerpen voor vandaag functie definitions;.h files;

Slides:



Advertisements
Similar presentations
Lecture 3 Some commonly used C programming tricks. The system command Project No. 1: A warm-up project.
Advertisements

Katholieke Hogeschool Kempen VHDL package 1 Package Basic functions in library.
Computertechniek Hogeschool van Utrecht / Institute for Computer, Communication and Media Technology 1  LCD aansturen  een scrollende text laten zien.
Vervolg C Hogeschool van Utrecht / Institute for Computer, Communication and Media Technology 1 Onderwerpen voor vandaag Dallas one-wire interface Opgave:
Computertechniek Hogeschool van Utrecht / Institute for Computer, Communication and Media Technology 1  herhaling ARM assembler instructies  geindexeerde.
Good morning :) Please write your name on your hand-out!
User Defined Functions
Overview of programming in C C is a fast, efficient, flexible programming language Paradigm: C is procedural (like Fortran, Pascal), not object oriented.
STRING AN EXAMPLE OF REFERENCE DATA TYPE. 2 Primitive Data Types  The eight Java primitive data types are:  byte  short  int  long  float  double.
CS 240 Computer Programming 1
Starting Out with C++, 3 rd Edition 1 Chapter 10 – Characters, Strings, and the string Class.
Chapter 12 Separate Compilation and Namespaces. Abstract Data Type (ADT) ADT: A data type consisting of data and their behavior. The abstraction is that.
Starting Out with C++, 3 rd Edition 1 Chapter 14 – More About Classes.
Engineering H192 - Computer Programming The Ohio State University Gateway Engineering Education Coalition Lect 12P. 1Winter Quarter User-Written Functions.
Chapter Five Functions
Onderwerpen voor vandaag
Je gebruikt will of going to als je het over de toekomst hebt. I will phone you tonight. Next week we will know the results.
1 Lecture 16:User-Definded function I Introduction to Computer Science Spring 2006.
Templated Functions. Overloading vs Templating  Overloaded functions allow multiple functions with the same name.
C++ Basics March 10th. A C++ program //if necessary include headers //#include void main() { //variable declaration //read values input from user //computation.
Lab 8 User Defined Function.
Programming III SPRING 2015 School of Computer and Information Sciences Francisco R. Ortega, Ph.D. McKnight Fellow and GAANN Fellow LECTURE #3 Control.
Computertechniek Hogeschool van Utrecht / Institute for Computer, Communication and Media Technology 1  pak het project tint.zip.
Esempio Polimorfismo1 // Definition of abstract base class Shape #ifndef SHAPE_H #define SHAPE_H class Shape { public: virtual double area() const { return.
BBS514 Structured Programming (Yapısal Programlama)1 Functions and Structured Programming.
Specification and Implementation Separating the specification from implementation makes it easier to modify programs. Changes in the class’s implementation.
C and Data Structures Baojian Hua
Wordpress Hoe doe je dat bij DSE Bloggen met. Log in op de homepage, klik in mijn account op Wordpress installeren.
CSC 107 – Programming For Science. Science Means Solving Problems  Physics – How does an atom work?
 2000 Prentice Hall, Inc. All rights reserved. Chapter 12 - The Preprocessor Directives (Macros)
Functions and More. Homework 1 Due September 11:59pm return a string count characters in a string call functions in a function.
CSC 107 – Programming For Science. Today’s Goal  Discuss writing & using functions  How to declare them, use them, & trace them  Could write programs.
Computertechniek 2 – ARM assembler Hogeschool van Utrecht / Institute for Computer, Communication and Media Technology 1  Herhaling ARM assembler instructies.
Multiple Files. Monolithic vs Modular  one file before  system includes  main driver function  prototypes  function.
Separating Definition & Implementation Headers and Comments.
Functions Modules in C++ are called functions and classes Functions are block of code separated from main() which do a certain task every C++ program must.
Functions CIS Feb-06. Summary Slide Using Functions Mathematical Functions Misc. Functions Naming Conventions Writing Functions –Function Prototype.
Engineering Computing I Chapter 4 Functions and Program Structure.
Compilation & Linking Computer Organization I 1 November 2009 © McQuain, Feng & Ribbens The Preprocessor When a C compiler is invoked, the.
Object Oriented Programming (OOP) Lecture No. 10.
CGS 3460 Preprocessor n All preprocessor directives or commands begin with a #. lE.g. #include C program → Modified C program → Object Code n Can appear.
Khalid Rasheed Shaikh Computer Programming Theory 1.
Week 11 Multi-file Programs and Scope of Variables.
Further Programming Concepts in C++ Ce Lecture 1 About the module Lectures plus Q&A sessions Tutorials The Assessment Assignment Class Test (Multi.
15. WRITING LARGE PROGRAMS. Source Files A program may be divided into any number of source files. Source files have the extension.c by convention. Source.
1 More Operator Overloading Chapter Objectives You will be able to: Define and use an overloaded operator to output objects of your own classes.
Quiz // // The function exchanges the two parameters. // Param: ( ) // Param:
Object-Oriented Paradigm The Concept  Bundled together in one object  Data Types  Functionality  Encapsulation.
Separate Compilation Bryce Boe 2013/10/09 CS24, Fall 2013.
4.3 Functions. Functions Last class we talked about the idea and organization of a function. Today we talk about how to program them.
PHY 107 – Programming For Science. Science Means Solving Problems  Physics – How does an atom work?
Introduction to Programming Lecture 6. Functions – Call by value – Call by reference Today's Lecture Includes.
Classes Classes are a major feature of C++. They support – – Abstraction – Data hiding – Encapsulation – Modularity – Re-use through inheritance.
Function PrototypetMyn1 Function Prototype We can declare a function before we use or define it by means of a function prototype. A function prototype.
1 Compiler directive: #define, usage 1 #include using namespace std; #define TAX //double TAX=0.08; #define LAST_NAME "Li" #define FIRST_NAME "Dennis"
Lesson xx Why use functions Program that needs a function Function header Function body Program rewritten using a function.
Silberschatz and Galvin  C Programming Language Kingdom of Saudi Arabia Ministry of Higher Education Al-Majma’ah University College of Education.
Functions, Part 2 of 2 Topics Functions That Return a Value
Functions Separate Compilation
Programmer-Defined Functions, Call-by-Value, Multiple Files Lab 5
User Defined Functions
C Preprocessor(CPP).
Separating Definition & Implementation
Code Organization Classes
Andy Wang Data Structures, Algorithms, and Generic Programming
Comments, Prototypes, Headers & Multiple Source Files
C++ Compilation Model C++ is a compiled language
Scope of variables class scopeofvars {
What Is? function predefined, programmer-defined
Code Organization Classes
Presentation transcript:

vervolg C Hogeschool van Utrecht / Institute for Computer, Communication and Media Technology 1 Onderwerpen voor vandaag functie definitions;.h files; #ifndef Oefening hiermee

vervolg C Hogeschool van Utrecht / Institute for Computer, Communication and Media Technology 2 float pow2( float x ){ // function definition return x * x; // (== body) } // also declaration int main( void ){ float x; x = pow2( 5.7 ); // function call } 1: define before use

vervolg C Hogeschool van Utrecht / Institute for Computer, Communication and Media Technology 3 float pow2( float x ); // function declaration // (== prototype) int main( void ){ float x; x = pow2( 5.7 ); // function call } float pow2( float x ){ // function definition return x * x; // (== body) } 2: declare before use, define later

vervolg C Hogeschool van Utrecht / Institute for Computer, Communication and Media Technology 4 // main.c int main( void ){ float x; x = pow2( 5.7 ); } Body in separate file (1) // pow2.c float pow2( float x ){ return x * x; } Compiler error (of warning)

vervolg C Hogeschool van Utrecht / Institute for Computer, Communication and Media Technology 5 // main.c float pow2( float x ); // main.c int main( void ){ float x; x = pow2( 5.7 ); } Body in separate file (2) // pow2.c float pow2( float x ){ return x * x; }

vervolg C Hogeschool van Utrecht / Institute for Computer, Communication and Media Technology 6 // main.c float pow2( float x ); int main( void ){ float x; x = pow2( 5.7 ); } Body in separate file (3) // pow2.c double pow2( double x ){ return x * x; } Dit gaat helemaal mis! Float was niet nauwkeurig genoeg, dus

vervolg C Hogeschool van Utrecht / Institute for Computer, Communication and Media Technology 7 // main.c #include ”pow.h” int main( void ){ float x; x = pow2( 5.7 ); } Declaration in separate header file // pow2.c #include ”pow.h” float pow2( float x ){ return x * x; } // pow2.h float pow2( float x );

vervolg C Hogeschool van Utrecht / Institute for Computer, Communication and Media Technology 8 // cos.h #include ”pow2.h” float cos( float x ); repeated.h inclusion problem // sin.h #include ”pow2.h” float sin( float x ); // pow2.h float pow2( float x ); // main.c #include ”cos.h” #include ”sin.h” int main( void ){ float x; x = sin( 0.5 ) + cos( 0.5 ); }

vervolg C Hogeschool van Utrecht / Institute for Computer, Communication and Media Technology 9 repeated.h inclusion problem // #include ”cos.h” float pow2( float x ); float cos( float x ); // #include ”sin.h” float pow2( float x ); float sin( float x ); main.c na preprocessing: Compiler error (of warning)

vervolg C Hogeschool van Utrecht / Institute for Computer, Communication and Media Technology 10 Oplossing: gebruik #ifndef // pow2.h #ifndef pow2_h #define pow2_h float pow2( float x ); #endif

vervolg C Hogeschool van Utrecht / Institute for Computer, Communication and Media Technology 11 repeated.h inclusion met #ifndef // #include ”cos.h” #ifndef pow2_h #define pow2_h float pow2( float x ); #endif float cos( float x ); // #include ”sin.h” #ifndef pow2_h #define pow2_h float pow2( float x ); #endif float sin( float x ); // #include ”cos.h” #define pow2_h float pow2( float x ); float cos( float x ); // #include ”sin.h” float sin( float x ); // main.c #include ”cos.h” #include ”sin.h”

vervolg C Hogeschool van Utrecht / Institute for Computer, Communication and Media Technology 12 Hogeschool van Utrecht / Institute for Computer, Communication and Media Technology 12 Schrijf (en test) de C de functie int count( char s[], char c ); Deze functie geeft als return het aantal keren dat het char c voor komt in de string s. Schrijf 3 files: count.h, count.c, main.c (= een simpele test). Gebruik #ifndef zoals uitgelegd.