// FileName.cpp // Written by Max Fomitchev (mif10) // This is a sample program // #include using namespace std; void main() { } Sample Program.

Slides:



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

Variables in C Amir Haider Lecturer.
Spring Semester 2013 Lecture 5
Starting Out with C++, 3 rd Edition 1 Chapter 10 – Characters, Strings, and the string Class.
Single Variable and a Lot of Variables The declaration int k; float f; reserve one single integer variable called k and one single floating point variable.
Coding Standard: General Rules 1.Always be consistent with existing code. 2.Adopt naming conventions consistent with selected framework. 3.Use the same.
Algorithms Series of mathematical or variable manipulations Integer a,b,c a = 12 b = 22 c = a * b (what is c?) 12 * 22 = 264.
Communicating in Code: Layout and Style Programming Studio Spring 2009 Note: several examples in this lecture taken from The Practice of Programming by.
Chapter 14: Overloading and Templates C++ Programming: Program Design Including Data Structures, Fifth Edition.
Lecture 3: Topics If-then-else Operator precedence While loops Static methods Recursion.
Command-line arguments CS 201 Fundamental Structures of Computer Science.
Chapter3: Language Translation issues
1 Lab Session-XIV CSIT121 Spring 2002 b Namespaces b First Class Travel b Lab Exercise 14 (Demo) b Lab Exercise b Practice Problem.
Pointers. Topics Pointers Pointer Arithmetic Pointers and Arrays.
A simple C++ program /* * This program prints the phrase "Hello world!" * on the screen */ #include using namespace std; int main () { cout
Chapter Objectives You should be able to describe: Object-Based Programming Classes Constructors Examples Common Programming Errors.
1 The first step in understanding pointers is visualizing what they represent at the machine level. In most modern computers, main memory is divided into.
Chapter 15: Operator Overloading
Basic Elements of C++ Chapter 2.
VARIABLES, TYPES, INPUT/OUTPUT, ASSIGNMENT OPERATION Shieu-Hong Lin MATH/CS Department Chapel.
Modular Programming Chapter Value and Reference Parameters t Function declaration: void computesumave(float num1, float num2, float& sum, float&
Elements of a C++ program 1. Review Algorithms describe how to solve a problem Structured English (pseudo-code) Programs form that can be translated into.
Introduction to C++ Programming Introduction to C++ l C is a programming language developed in the 1970's alongside the UNIX operating system. l C provides.
Chapter 1: A First Program Using C#. Programming Computer program – A set of instructions that tells a computer what to do – Also called software Software.
Variables, Functions & Parameter Passing CSci 588 Fall 2013 All material not from online sources copyright © Travis Desell, 2011.
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.
Chapter 06 (Part I) Functions and an Introduction to Recursion.
JAVA Tokens. Introduction A token is an individual element in a program. More than one token can appear in a single line separated by white spaces.
Chapter 02 (Part III) Introduction to C++ Programming.
Style Guidelines. Why do we need style?  Good programming style helps promote the readability, clarity and comprehensibility of your code.
Introduction to C++ // Program description #include directives int main() { constant declarations variable declarations executable statements return.
A Review of C++ Dr. Nancy Warter-Perez June 16, 2003.
Array in C++ / review. An array contains multiple objects of identical types stored sequentially in memory. The individual objects in an array, referred.
Chapter 0 Getting Started. Objectives Understand the basic structure of a C++ program including: – Comments – Preprocessor instructions – Main function.
Lecture 22: Reviews for Exam 2. Functions Arrays Pointers Strings C Files.
C Functions Three major differences between C and Java functions: –Functions are stand-alone entities, not part of objects they can be defined in a file.
Code Conventions Tonga Institute of Higher Education.
A first program 1. #include 2. using namespace std; 3. int main() { 4. cout
Topic 3: C Basics CSE 30: Computer Organization and Systems Programming Winter 2011 Prof. Ryan Kastner Dept. of Computer Science and Engineering University.
C++ Programming: From Problem Analysis to Program Design, Third Edition Chapter 14: Pointers.
Liang, Introduction to C++ Programming, (c) 2007 Pearson Education, Inc. All rights reserved X 1 Chapter Array Basics.
CSC 143A 1 CSC 143 Introduction to C++ [Appendix A]
More About Data Types & Functions. General Program Structure #include statements for I/O, etc. #include's for class headers – function prototype statements.
© Oxford University Press All rights reserved. CHAPTER 10 THE PREPROCESSOR DIRECTIVE.
Characters and Strings
FUNCTIONS. Midterm questions (1-10) review 1. Every line in a C program should end with a semicolon. 2. In C language lowercase letters are significant.
Variables in C Topics  Naming Variables  Declaring Variables  Using Variables  The Assignment Statement Reading  Sections
CMSC 104, Version 8/061L09VariablesInC.ppt Variables in C Topics Naming Variables Declaring Variables Using Variables The Assignment Statement Reading.
Advanced BioPSE NCRR Programming Conventions and Standards J. Davison de St. Germain Chief Software Engineer SCI Institute December 2003 J.
1 A more complex example Write a program that sums a sequence of integers and displays the result. Assume that the first integer read specifies the number.
OPERATORS IN C CHAPTER 3. Expressions can be built up from literals, variables and operators. The operators define how the variables and literals in the.
Windows Programming Lecture 03. Pointers and Arrays.
CCSA 221 Programming in C CHAPTER 3 COMPILING AND RUNNING YOUR FIRST PROGRAM 1 ALHANOUF ALAMR.
Introduction to C++ Programming
Chapter 2 Introduction to C++ Programming
Variables A variable is a placeholder for a value. It is a named memory location where that value is stored. Use the name of a variable to access or update.
Mr. Shaikh Amjad R. Asst. Prof in Dept. of Computer Sci. Mrs. K. S
Communicating in Code: Layout and Style
Chapter 2 – Getting Started
Variables In programming, we often need to have places to store data. These receptacles are called variables. They are called that because they can change.
C++ fundamentals Lecture 1, Chapter 2 – pp /22/2018 Y K Choi.
Introduction to C++ Programming
Introduction to C++ Programming
Topics Introduction to Functions Defining and Calling a Function
Programming Introduction to C++.
Variables in C Topics Naming Variables Declaring Variables
CSCE-221 C++ Coding Standard/Guidelines
Introduction to Programming - 1
Variables in C Topics Naming Variables Declaring Variables
Controlling Program Flow
Presentation transcript:

// FileName.cpp // Written by Max Fomitchev (mif10) // This is a sample program // #include using namespace std; void main() { } Sample Program

// Never hard code constants // Use macro declarations instead #define MAX_LENGTH 255 // String of 255 ASCII characters (char-array) char [MAX_LENGTH]; // Uninitialized string (pointer) char* another ; // Single character char aCharacter; [0] – first character [i] – i th character [MAX_LENGTH-1] – last character; character string arrays are zero-terminated! char* name = “MAX”; [‘M’ ‘A’ ‘X’ ‘\0’] [ ] ‘\0’ is equivalent to 0, however ‘\0’ should be used with strings. Character Strings

#include string class (STL)

Read Chapter 8 from “Enterprise Application Development with Visual C ” * Simplicity * Clarity * Discipline Name your project in a meaningful way (e.g. Checker, not test1 or assignment1) Comment your code! Add a header describing each file. Project, Source Code Organization

Project Structure

Visual Studio solution provides a way to organize projects by grouping them together. Create a solution and give it a name of your PennState ID. Add all your projects to the same solution. Make sure that your project files reside in a single location, which in with in the main solution foldr. Visual Studio Solutions

Project Structure

Solution Structure

Header File Structure

Spaces, Not Tabs

General Rules: White Space and Comment Placement When used consistently white space can greatly enhance the appearance of your source and facilitate recognition and comprehension of the coded logic. To achieve optimal appearance follow these rules when writing your code. Always Indent Your Code! Code Formatting

Insert a Single Space Between Function / Method Arguments Use spaces to separate function arguments for improved readability, e.g.: // Good DoSomething(a, b, c); // Bad DoSomething(a,b,c); Function Parameters

Use a Single Spade Before and After Parenthesis in for, if, while and switch Statements Use spaces to separate arguments of statements requiring arguments in parenthesis: // Good if ( a ) … for ( int i = 0; i < count; i++ ) … while ( a ) … switch ( a ) … // Bad if(a) … for(int i = 0; i < count; i++) … while(a) … switch(a) … If, for, while

Insert a Single Space Between Operator Arguments Use spaces to separate operator arguments for improved readability, e.g.: // Good a = b + c - d; // Bad a=b+c-d; Exception: Arguments of operators depending higher degree of precedence (such as * and / operators) should be placed without spaces in order to provide visual indication of seniority and therefore order of operators in expression, e.g.: // Good a = b*c + d/e; // Bad a = b * c + d / e;Operators

Use Parenthesis for Explicit Grouping in Logical Expressions Order of operations in logical expressions is a frequent source of errors due to confusion over precedence of operations. Explicit grouping of operations in logical expressions by means of parenthesis will help you avoid such errors, e.g.: if ( (a || b) && (c || d) ) … // Good a = (b == c); a = (b < c); // Bad a = b == c; a = b < c; Logical Expressions