Program style. Global area Place comment s at beginning of the program: 1.purpose 2.author 3.the date the program was written 4.the data and description.

Slides:



Advertisements
Similar presentations
Etter/Ingber Engineering Problem Solving with C Fundamental Concepts Chapter 4 Modular Programming with Functions.
Advertisements

C++ Statements represent the lowest-level building blocks of a program and it may be like:. A simple statement is a computation terminated by a semicolon.
Functions ROBERT REAVES. Functions  Interface – the formal description of what a subprogram does and how we communicate with it  Encapsulation – Hiding.
1 CS 161 Introduction to Programming and Problem Solving Chapter 9 C++ Program Components Herbert G. Mayer, PSU Status 10/20/2014.
1 Lecture-4 Chapter 2 C++ Syntax and Semantics, and the Program Development Process Dale/Weems/Headington.
Structure of a C program
1 9/1/06CS150 Introduction to Computer Science 1 What Data Do We Have? CS 150 Introduction to Computer Science I.
1 Chapter 2 C++ Syntax and Semantics, and the Program Development Process Dale/Weems/Headington.
Chapter 2: Introduction to C++.
Computer Science 1620 Lifetime & Scope. Variable Lifetime a variable's lifetime is finite Variable creation: memory is allocated to the variable occurs.
Chapter 3: Introduction to C Programming Language C development environment A simple program example Characters and tokens Structure of a C program –comment.
C++ PROGRAMMING Dr. Parvis Partow CSULA Revised by Mr. Dave Clausen La Cañada High School.
Basic Elements of C++ Chapter 2.
CSC 125 Introduction to C++ Programming Chapter 2 Introduction to C++
Chapter 3 Getting Started with C++
CECS 121 EXAM 1. /* C Programming for the Absolute Beginner */ // by Michael Vine #include main() { printf(“\nC you later\n”); system(“pause”); }
Modular Programming Chapter Value and Reference Parameters t Function declaration: void computesumave(float num1, float num2, float& sum, float&
CH Programming An introduction to programming concepts.
Do … while ( continue_cond ) Syntax: do { stuff you want to happen in the loop } while (continue_condition);
Modular Programming Chapter Value and Reference Parameters computeSumAve (x, y, sum, mean) ACTUALFORMAL xnum1(input) ynum2(input) sumsum(output)
C++ Basics Structure of a Program. C++ Source Code Plain text file Typical file extension .CPP Must compile the C++ source code without errors before.
M. Taimoor Khan #include void main() { //This is my first C++ Program /* This program will display a string message on.
1 Programs Composed of Several Functions Syntax Templates Legal C++ Identifiers Assigning Values to Variables Declaring Named Constants String Concatenation.
Copyright © 2009 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 2-1 Copyright © 2009 Pearson Education, Inc. Publishing as Pearson Addison-Wesley.
/* Documentations */ Pre process / Linking statements Global declarations; main( ) { Local Declarations; Program statements / Executable statements; }
COMPUTER PROGRAMMING. Functions What is a function? A function is a group of statements that is executed when it is called from some point of the program.
/* C Programming for the Absolute Beginner */ // by Michael Vine #include main() { printf(“\nC you later\n”); system(“pause”); }
Copyright © 2012 Pearson Education, Inc. Chapter 2: Introduction to C++
1 CS161 Introduction to Computer Science Topic #3.
Documentation and Programming Style Appendix A © 2015 Pearson Education, Inc., Hoboken, NJ. All rights reserved.
Copyright © 2015, 2012, 2009 Pearson Education, Inc., Publishing as Addison-Wesley All rights reserved. Chapter 2: Introduction to C++
COMPUTER PROGRAMMING. Functions’ review What is a function? A function is a group of statements that is executed when it is called from some point of.
1 Chapter 2 C++ Syntax and Semantics, and the Program Development Process.
1 Remember: Examination is a chance not ability. By ILTAF MEHDI, IT LECTURER, MIHE, KATR-E-PARWAN BRANCH, KABUL.
CECS 130 EXAM 1. To declare a constant (read only) value: const int x = 20; const float PI = 3.14; Can we do this? const int x;
/* C Programming for the Absolute Beginner */ // by Michael Vine #include main() { printf(“\nC you later\n”); system(“pause”); }
Arithmetic Expressions Addition (+) Subtraction (-) Multiplication (*) Division (/) –Integer –Real Number Mod Operator (%) Same as regular Depends on the.
Chapter 2: Introduction to C++. Outline Basic “Hello World!!” Variables Data Types Illustration.
Chapter 3 Functions. 2 Overview u 3.2 Using C++ functions  Passing arguments  Header files & libraries u Writing C++ functions  Prototype  Definition.
Functions Chapter 6. Modular Programming Modular programming: breaking a program up into smaller, manageable functions or modules Function: a collection.
L what are predefined functions? l what is? n function name n argument(s) n return value n function call n function invocation n nested function call l.
1 What is a Named Constant? A named constant is a location in memory that we can refer to by an identifier, and in which a data value that cannot be changed.
April 11, 2005 More about Functions. 1.Is the following a function call or a function header? calcTotal(); 2.Is the following a function call or a function.
1 Scope Lifetime Functions (the Sequel) Chapter 8.
Variables  A piece of memory set aside to store data  When declared, the memory is given a name  by using the name, we can access the data that sits.
Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 2 Introduction to C++
Functions in C++ Top Down Design with Functions. Top-down Design Big picture first broken down into smaller pieces.
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 8/30/06CS150 Introduction to Computer Science 1 Your First C++ Program.
1 Functions Part 1 Prototypes Arguments Overloading Return values.
Copyright © 2009 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 2-1 Copyright © 2009 Pearson Education, Inc. Publishing as Pearson Addison-Wesley.
2.1 The Part of a C++ Program. The Parts of a C++ Program // sample C++ program #include using namespace std; int main() { cout
STRUCTURED PROGRAMMING Complete C++ Program. Content 2  Main Function  Preprocessor directives  User comments  Escape characters  cout statement.
Chapter 1.2 Introduction to C++ Programming
Chapter Topics The Basics of a C++ Program Data Types
Topic Pre-processor cout To output a message.
Chapter 1.2 Introduction to C++ Programming
CSE 220 – C Programming C Fundamentals.
Chapter 2: Introduction to C++
Predefined Functions Revisited
Basic Elements of C++.
Basic Elements of C++ Chapter 2.
Repetition Statements
2.1 Parts of a C++ Program.
Chapter 2: Introduction to C++.
Fundamental Programming
Predefined Functions Revisited
FOR statement a compact notation for a WHILE e.g. sumgrades = 0;
CSCE-221 C++ Coding Standard/Guidelines
Presentation transcript:

Program style

Global area Place comment s at beginning of the program: 1.purpose 2.author 3.the date the program was written 4.the data and description of all cahnges Preprocessor commands: 1.all includes 2.defined constants 3.macros

Global area Prototype Structure /* this program … written by: date: change history: mm / dd / yy : */ #include … // constants //prototype declarations //marcos //interprogram communication varibales

Program main line The only statements found in main are: 1.a start-of-program message 2.function calls 3.an end-of-program message. Int main(void) { // local definitions // statements cout<<“ begin program …”<<endl; count<<“end of program…”<<endl; return 0; } //main

General coding standards Don’t crowd your code 1.at least one space before and after every operator. 2.at least one space beginning and end of every expression. 3.align the operator and second operand in a series of assignment statement.

General coding standards Only one declaration or definition may be coded on a line. Group variable declarations by type. order them alphabetically by type and place a blank line between types. Abbreviate only when identifiers become long: 1.remove all vowels unless they start a word 2.represent double consonants by a consonant.

General coding standards Minimize the number of statement within a function. The statement portion of a function should fit on a screen. All blocks are terminated with a comment. 1.end a function block with a comment that contains the name of the function. ex: //main 2.end if statements with // if or // if 3.end else statement with // else or // else

General coding standards 4.end while statement with //while 5.end for statements with //for 6.cooment intrafucntion blocks at the beginning and at the end

Variable and structures Use intelligent identifier names. 1 avoid single-character identifiers except for loop counters in a for statement. 2.identifiers should clearly convey their contents and use.

Function definition Always explicitly code the return type. Begin each function with comments: 1.identify its purpose 2.explain its parameters and return value. Place the parameters within a function prototype statement on multiple lines only when there are to many. Clearly document the declarative portion of all functions (general coding standards)

Function definition Within a function. use comments only to explain a block of code. Place comments at the beginning of the code that need explanation, Do not place comments on lines. Terminate all functions with a return a statement. Avoid multiple return statement within a function. Clearly mark the end of the program.

Function definition /* ================ ======================== pre post */ Int doIt ( int p1, float p2) { // Local Definitions // statements return 0; } // //=====================end of program=======================

Question?