1 Compiler directive: #define, usage 1 #include using namespace std; #define TAX 0.075 //double TAX=0.08; #define LAST_NAME "Li" #define FIRST_NAME "Dennis"

Slides:



Advertisements
Similar presentations
Lecture Computer Science I - Martin Hardwick Strings #include using namespace std; int main () { string word; cout
Advertisements

Chapter 12 Separate Compilation and Namespaces. Abstract Data Type (ADT) ADT: A data type consisting of data and their behavior. The abstraction is that.
Chapter 6 Advanced Function Features Pass by Value Pass by Reference Const parameters Overloaded functions.
Class Scope class Student { private: string id; string firstName, lastName; float gpa; public: void Read() { cin >> id >> firstName >> lastName >> gpa;
第三次小考. #include using namespace std; int aaa(int *ib,int a1,int a2) { int u,v; int m=(a1+a2)/2; if(a1==a2)return ib[a1]; u=aaa(ib,a1,m); cout
C++ Basics March 10th. A C++ program //if necessary include headers //#include void main() { //variable declaration //read values input from user //computation.
String in C++. String Series of characters enclosed in double quotes.“Philadelphia University” String can be array of characters ends with null character.
Enumeration Data Type enum Day {SUN, MON, TUE, WED, THU, FRI, SAT}; Day today; today = WED; if (today == FRI) cout
Tinaliah, S. Kom.. * * * * * * * * * * * * * * * * * #include using namespace std; void main () { for (int i = 1; i
Approfondimento Classi - Esempi1 // Argomento: Oggetti membri di altre classi // Declaration of the Date class. // Member functions defined in date1.cpp.
Triana Elizabeth, S.Kom. #include using namespace std; void main () { for (int i = 1; i
Esempio Polimorfismo1 // Definition of abstract base class Shape #ifndef SHAPE_H #define SHAPE_H class Shape { public: virtual double area() const { return.
PASSING PARAMETERS 1. 2 Parameter Passing (by Value) Parameters Formal Parameters – parameters listed in the header of the function Variables used within.
C++ Data Type String A string is a sequence of characters enclosed in double quotes. Examples of strings: “Hello” “CIS 260” “Students” The empty string.
// Functions that take no arguments #include using namespace std; void function1(); void function2( void ); int main() { function1(); function2(); return.
Computer Science 1620 Function Scope & Global Variables.
Pointers: Part I. Why pointers? - low-level, but efficient manipulation of memory - dynamic objects  Objects whose memory is allocated during program.
Review on pointers and dynamic objects. Memory Management  Static Memory Allocation  Memory is allocated at compiling time  Dynamic Memory  Memory.
1 Classes Separating interface from implementation Place the class declaration in a header file (.h) to be included (via #include) in each file that uses.
PRINCIPLES OF PROGRAMMING Revision. A Computer  A useful tool for solving a great variety of problems.  To make a computer do anything (i.e. solve.
 Review structures  Program to demonstrate a structure containing a pointer.
Chapter 1 Quiz Questions (CGS-3464) Mahendra Kumar
C++ function call by value The call by value method of passing arguments to a function copies the actual value of an argument into the formal parameter.
Functions Pass by Reference Alina Solovyova-Vincent Department of Computer Science & Engineering University of Nevada, Reno Fall 2005.
Current Assignments Homework 3 is due tonight. Iteration and basic functions. Exam 1 on Monday.
ITEC 320 C++ Examples.
Multiple Files. Monolithic vs Modular  one file before  system includes  main driver function  prototypes  function.
C++ Functions. Objectives 1. Be able to implement C++ functions 2. Be able to share data among functions 2.
Lecture 3: The parts of a C++ program (Cont’d) Professor: Dr. Miguel Alonso Jr. Fall 2008 CGS2423/COP1220.
Finding Memory Leaks. The new operator and operator new When allocating memory using new, e.g. –Student *ps = new Student(“Yossi Cohen”); –int *pi = new.
Object-Oriented Programming. Procedural Programming All algorithms in a program are performed with functions and data can be viewed and changed directly.
11 Introduction to Object Oriented Programming (Continued) Cats.
Tracing through E01, question 9 – step 1 // p02.cc P. Conrad, for CISC181 07S // Exam question for E01 #include using namespace std; void mysteryFunction(int.
1 Cannon_Chapter9 Strings and the string Class. 2 Overview  Standards for Strings  String Declarations and Assignment  I/O with string Variables 
1 More Operator Overloading Chapter Objectives You will be able to: Define and use an overloaded operator to output objects of your own classes.
FUNCTIONS - What Is A Function? - Advantages Function Declaration
February 28, 2005 Introduction to Classes. Object Oriented Programming An object is a software bundle of related variables and methods. Software objects.
Functions & Strings CIS Feb-06. Quiz 1.Write a function Prototype for the function findSmallest that takes three integers and returns an integer.
11 Introduction to Object Oriented Programming (Continued) Cats.
 Memory setup  Pointer declaration  Address operator  Indirection  Printing addresses or pointers.
3/6/2016Chung-Chih ISU IT 2791 Spec of the program outputs: What's your name? Dennis Hi! Dennis! Input the price for 10% discount: 200 Input the quantity:
Chapter 2 Creating a C++ Program. Elements of a C++ Program Four basic ways of structuring a program Four basic ways of structuring a program 1.Sequencing.
3/18/2016IT 2791 Scopes of Variables int main() { int i=0; cout
Current Assignments Project 3 has been posted, due next Tuesday. Write a contact manager. Homework 6 will be posted this afternoon and will be due Friday.
#define #include<iostream> using namespace std; #define GO
Command Line Arguments
Programmer-Defined Functions, Call-by-Value, Multiple Files Lab 5
Dynamic Memory Allocation Reference Variables
Learning Objectives What else in C++ Bitwise operator
Variables with Memory Diagram
Name: Rubaisha Rajpoot
אבני היסוד של תוכנית ב- C++
Programming -2 برمجة -2 المحاضرة-7 Lecture-7.
Creation and Use of Namespaces
Screen output // Definition and use of variables
הרצאה 03 אבני היסוד של תוכנית ב- C
Starting Out with C++: From Control Structures through Objects
Pointers & Functions.
Code::Block vs Visual C++
Dynamic Memory A whole heap of fun….
C++ Compilation Model C++ is a compiled language
Function “Inputs and Outputs”
foo.h #ifndef _FOO #define _FOO template <class T> class foo{
Pointers & Functions.
(Dreaded) Quiz 2 Next Monday.
The Stack.
Instructor: Dr. Michael Geiger Spring 2019 Lecture 4: Functions in C++
CMSC 341 C++ and OOP.
Spec of the program outputs:
EECE.3220 Data Structures Instructor: Dr. Michael Geiger Spring 2019
Presentation transcript:

1 Compiler directive: #define, usage 1 #include using namespace std; #define TAX //double TAX=0.08; #define LAST_NAME "Li" #define FIRST_NAME "Dennis" #define GO #define SKIP void main() { cout << FIRST_NAME << " " << LAST_NAME << endl; cout << "TAX = " << TAX << endl; #ifdef GO cout << "GO\n"; cout << "and GO\n"; #endif #ifndef SKIP cout << "NO SKIP\n"; #endif cout << endl; }

2 Compiler directive: #define, usage 2 #define now_define_add(type)\ type add(type a, type b)\ { return a+b; }\ now_define_add(int) now_define_add(double) void main() { int a=1,b=2; double r=1, s=2; cout << a / add(a,b) << endl; cout << a / add(r,s) << endl; } continue to the next line

3 Name space: A pace for definitions. i.e., variables and function definition. #include using namespace std; namespace room201 { char *instructor = "Osborne"; char *teach() { return "NetWorking"; } namespace room69 { char *instructor = "Li"; char *teach() { return "Cryptography"; }

4 Using Name space (1): Tell in which room.. #include using namespace std; namespace room201 {...} namespace room69 {...} void main() { cout << room201::instructor << " teaches " << room201::teach() << endl; cout << room69::instructor << " teaches " << room69::teach() << endl;.... } Osborne teaches NetWorking Li teaches Cryptography

5 Using Name space (2): Tell which room to use.. #include using namespace std; namespace room201 {...} namespace room69 {...} void main() { { using namespace room201; cout << instructor << " teaches "; cout << teach() << endl; } using namespace room69; cout << instructor << " teaches " << teach() << endl; } Osborne teaches NetWorking Li teaches Cryptography