1. 2 2 Make a Copy Of File Main.cpp (of Student-Class). Place It On Your Desktop. Open it With A Text Editor 3.

Slides:



Advertisements
Similar presentations
Tutorial 12: Enhancing Excel with Visual Basic for Applications
Advertisements

Copyright © 2008 Pearson Addison-Wesley. All rights reserved. Chapter 12A Separate Compilation and Namespaces For classes this time.
Copyright © 2008 Pearson Addison-Wesley. All rights reserved. Chapter 12 Separate Compilation Namespaces Simple Make Files (Ignore all class references.
Unix Continuum of Tools Do something once: use the command line Do something many times: –Use an alias –Use a shell script Do something that is complex.
CS100A, Fall 1997, Lectures 221 CS100A, Fall 1997 Lecture 22, Tuesday 18 November Introduction To C Goal: Acquire a reading knowledge of basic C. Concepts:
Guide To UNIX Using Linux Third Edition
C Programming. C vs C++ C syntax and C++ syntax are the same but... C is not object oriented * There is no string class * There are no stream objects.
Using Visual C++ and Pelles C
C - Input & Output When we are saying Input that means to feed some data into program. This can be given in the form of file or from command line. C programming.
An Introduction to C Programming Geb Thomas. Learning Objectives Learn how to write and compile a C program Learn what C libraries are Understand the.
1 Software John Sum Institute of Technology Management National Chung Hsing University.
(c) Bob McKillop, 2006Tutorial #1 T1-1 Tutorial #1 - your first compiled code  the learning objectives for this tutorial are very modest q compile and.
1 Chapter One A First Program Using C#. 2 Objectives Learn about programming tasks Learn object-oriented programming concepts Learn about the C# programming.
Unix Primer. Unix Shell The shell is a command programming language that provides an interface to the UNIX operating system. The shell is a “regular”
Review C++ exception handling mechanism Try-throw-catch block How does it work What is exception specification? What if a exception is not caught?
chap13 Chapter 13 Programming in the Large.
Files COP3275 – PROGRAMMING USING C DIEGO J. RIVERA-GUTIERREZ.
Intro to C++. Getting Started with Microsoft Visual Studios Open Microsoft Visual Studios 2010 Click on file Click on New Project Choose Visual C++ on.
Shell Scripting Introduction. Agenda What is Shell Scripting? Why use Shell Scripting? Writing and Running a Shell Script Basic Commands -ECHO - REM.
Separate Compilation. A key concept in programming  Two kinds of languages, compilation (C, Pascal, …) and interpretation (Lisp, …, Matlab, Phython,
Tutorial 111 The Visual Studio.NET Environment The major differences between Visual Basic 6.0 and Visual Basic.NET are the latter’s support for true object-oriented.
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.
© 2005 Pearson Education, Inc., Upper Saddle River, NJ. All rights reserved. Data Structures for Java William H. Ford William R. Topp Appendix E The EZJava.
Creating your first C++ program
Introduction to C Programming CE Lecture 7 Compiler options and makefiles.
C Tutorial Session #2 Type conversions More on looping Common errors Control statements Pointers and Arrays C Pre-processor Makefile Debugging.
CS 450 MPX P ROJECT A Quick C Review. P OINTERS AND ADDRESSES IN C Check Manual I2 from Dr. Mooney’s website for a complete review of C topics you will.
Getting started: Basics Outline: I.Connecting to cluster: ssh II.Connecting outside UCF firewall: VPN client III.Introduction to Linux IV.Intoduction to.
UNIT 13 Separate Compilation.
CECS 121 Test 1. Functions allow you to group program statements under one name C and C++ are case-sensitive so main(), MAIN(), and Main() are all different.
CPS120: Introduction to Computer Science Lecture 14 Functions.
CSE 232: C++ debugging in Visual Studio and emacs C++ Debugging (in Visual Studio and emacs) We’ve looked at programs from a text-based mode –Shell commands.
Lecture 3: Getting Started & Input / Output (I/O) “TRON” Copyright 1982 (Walt Disney Productions)
Information and Communication Technology Sayed Mahbub Hasan Amiri Dhaka Residential Model College Higher Secondary.
CSE 332: C++ debugging Why Debug a Program? When your program crashes –Finding out where it crashed –Examining program memory at that point When a bug.
11 Introduction to Object Oriented Programming (Continued) Cats.
1 Getting Started with C++. 2 Objective You will be able to create, compile, and run a very simple C++ program on Windows, using Visual Studio 2008.
I Power Higher Computing Software Development Development Languages and Environments.
Lecture 13: Working with Multiple Programmers. Headers Header files: Each standard library has a corresponding header. The function prototype for all.
Makefiles. Multiple Source Files (1) u Obviously, large programs are not going to be contained within single files. u C provides several techniques to.
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;
Lecture 10: Modular Programming (functions) B Burlingame 13 April 2015.
Separate Compilation Bryce Boe 2013/10/09 CS24, Fall 2013.
Fall 2015CISC/CMPE320 - Prof. McLeod1 CISC/CMPE320 Managers and “mentors” identified on projects page. All member accounts created and projects populated.
Chapter 9 Separate Compilation and Namespaces. Copyright © 2005 Pearson Addison-Wesley. All rights reserved. Slide 2 Overview Separate Compilation (9.1)
Copyright © 2008 Pearson Addison-Wesley. All rights reserved. Chapter 12 Separate Compilation and Namespaces.
Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 12 Separate Compilation and Namespaces.
11 Introduction to Object Oriented Programming (Continued) Cats.
C:\Temp\Templates 4 5 Use This Main Program 6.
1 2 2 Call The Project Dynamic-Memory 4 4 # include "Utilities.hpp" int main(int argc, char * argv[]) { short int *PtrNo; (*PtrNo) = 5; printf ("(*PtrNo)
CSE 332: C++ expressions Expressions: Operators and Operands Operators obey arity, associativity, and precedence int result = 2 * 3 + 5; // assigns 11.
C Programming Day 2. 2 Copyright © 2005, Infosys Technologies Ltd ER/CORP/CRS/LA07/003 Version No. 1.0 Union –mechanism to create user defined data types.
Chapter 1 slides1 What is C? A high-level language that is extremely useful for engineering computations. A computer language that has endured for almost.
Chapter 2 Build Your First Project A Step-by-Step Approach 2 Exploring Microsoft Visual Basic 6.0 Copyright © 1999 Prentice-Hall, Inc. By Carlotta Eaton.
Unit 10 Code Reuse. Key Concepts Abstraction Header files Implementation files Storage classes Exit function Conditional compilation Command-line arguments.
Lecture 3: Getting Started & Input / Output (I/O)
Appendix 1 - Packages Jim Fawcett copyright (c)
Introduction to C++ Systems Programming.
Separate Compilation and Namespaces
OOP-4-Templates, ListType
CS1010 Programming Methodology
CS1010 Programming Methodology
Separate Compilation and Namespaces
Software John Sum Institute of Technology Management
Advanced Programming Lecture 02: Introduction to C# Apps
Comments, Prototypes, Headers & Multiple Source Files
Classes.
CSCI N317 Computation for Scientific Applications Unit 1 – 1 MATLAB
Appendix F C Programming Environment on UNIX Systems
SPL – PS1 Introduction to C++.
Presentation transcript:

1

2 2

Make a Copy Of File Main.cpp (of Student-Class). Place It On Your Desktop. Open it With A Text Editor 3

I Am Going To Use Programmers Notepad 2 (freeware) I Am Going To Grab Code From This File Throughout This Tutorial. I Would Be More Apt To Confuse The Files If Both Were Open In Visual Studio. 4

5 5

////////////////////////////////////////////////////////////////////////////////// // // main.cpp // // // Purpose : Learn To Partition A Class Into A Good Interface -.hpp &.cpp // // // Written By : Dr. Thomas E. Hicks Environment : Windows 7 // // Date : xx/xx/xxxx Compiler : Visual C++ // ////////////////////////////////////////////////////////////////////////////////// Add The Following Documentation I Have Enabled You To Copy/Paste This, & Many Of The Other Documentation Boxes; Come Back & Do It After Lecture! 6

7

Right-Mouse Click On Project  Select Add  Select New Item 8

Select A Visual C++ Header File  Call It Student.hpp 9

Add The Following Documentation Block (you may copy from next slide) 10

Add The Student.hpp Documentation Block ////////////////////////////////////////////////////////////////////////////////// // // Student.hpp // // // Purpose : Create the Interface for the Student Class. The interface // // shall include the includes, defines, class description and // // prototypes that the compiler needs in order to compile // // and execute Student objects. // // // Written By : Dr. Thomas E. Hicks Environment : Windows 7 // // Date : xx/xx/xxxx Compiler : Visual C++ // ////////////////////////////////////////////////////////////////////////////////// 11

12

Major Class Components Of.hpp (in order) 1] All Includes essential to the class 2] All Defines essential to the class 3] All Struct and Class definitions 4] Prototypes for all Non-Class Functions 5] All Template Functions 13

About Interfaces An Interface (.hpp &.cpp) Should Contain A Logical Collection Of Related Information. Creating An Interface For Students Is Both Logical & Appropriate. This Interface Will Include All Of The Data & Functions Related To Students. An Application Often Involves Combining Hundreds/Thousands Of Interface Files. 14

Potential Problem int x = 5, y = 2; if (x > 3) { int x = y * 2; … This Code Breaks! WHY? Multiple Declaration Of Same Variable. Could Also Have A Problem If Wrote Code For The Same Function Twice! This Is Exactly What Can Happen With An Application That Is Comprised Of Many Interfaces. It Might Be The Case That Several Of The Interfaces Include Utilities.hpp (or Some Other Interface) ; We Have To Avoid The Duplication Of Variables & Functions! (or we can't compile!) 15

# ifndef PART_CLASS //================================================== # define PART_CLASS # endif // PART_CLASS ================================================= To Start The.hpp Interface For Class Part If I Were To Ask You Why Each.hpp File Should 1] begin the compiler directive # ifndef [if not defined] ? 2] & end with compiler directive # endif [end if] ? The #ifndef, #define, and #endif help to prevent multiple redefinitions of variables, classes, constants, & functions. 16

# ifndef STUDENT_CLASS //=============================================== # define STUDENT_CLASS # endif //STUDENT_CLASS ============================================= Start The.hpp Interface For Class Student 17

# ifndef STUDENT_CLASS //========================================================= // Includes # include "utilities.hpp # define STUDENT_CLASS # endif //STUDENT_CLASS //======================================================= Add All Of The Includes For Class Student 18

# ifndef STUDENT_CLASS //========================================================= // Includes # include "utilities.hpp // Defines # define STUDENT_CLASS # define MALE false # define FEMALE true # endif //STUDENT_CLASS //======================================================= Add All Of The Defines For Class Student # define STUDENT_DIAGNOSTIC_LEVEL 2 19

# ifndef STUDENT_CLASS //========================================================= // Includes # include "utilities.hpp // Defines # define STUDENT_CLASS # define STUDENT_DIAGNOSTIC_LEVEL 2 # define MALE false # define FEMALE true ////////////////////////////////////////////////////////////////////////////////// // Class Student // ////////////////////////////////////////////////////////////////////////////////// class Student { … }; # endif //STUDENT_CLASS //======================================================= Add The Class Definition 20

# ifndef STUDENT_CLASS //========================================================= // Includes # include "utilities.hpp // Defines # define STUDENT_CLASS # define STUDENT_DIAGNOSTIC_LEVEL 2 # define MALE false # define FEMALE true ////////////////////////////////////////////////////////////////////////////////// // Class Student // ////////////////////////////////////////////////////////////////////////////////// class Student { }; # endif //STUDENT_CLASS //======================================================= There Are No Template Methods We Will Get To Template Methods Within The Next Week 21

What is in the.h or.hpp Interface? 1] All includes essential to the class 2] All defines essential to the class 3] All struct and class definitions 4] Prototypes for all Functions/Procedures 5] All Template Functions/ Procedures/ Methods 22

23

Right-Mouse Click On Project  Select Add  Select New Item 24

Select A Visual C++ File  Call It Student.cpp 25

Add The Following Documentation Block (you may copy from next slide) 26

Add The Student.cpp Documentation Block ////////////////////////////////////////////////////////////////////////////////// // // Student.cpp // // // Purpose : Create the Student Class that will contain all Student // // methods and all non-template functions. // // // Written By : Dr. Thomas E. Hicks Environment : Windows 7 // // Date : xx/xx/xxxx Compiler : Visual C++ // ////////////////////////////////////////////////////////////////////////////////// 27

28

1] An Include Statement for the Interface File 2] All Non-Template Functions/Methods 29 Major Class Components Of.cpp (in order)

Add An Include For This Interface (.hpp) # include "Student.hpp" 30

Add All Of The Student Methods # include "Student.hpp" more 31

Add All Of The Non-Template Functions # include "Student.hpp" more 32

What is in the.c or.cpp Interface? 1] Include the interface file 2] All Non-Template Functions/ Procedures/ Methods 33

Program Should Compile! 34

35

Add A Function Call To TestStudent Even Though Files In Project - Will Not Work! 36

Add The Include for Student.hpp Required For Every File That Uses Students! 37

38

39 Why Partition Classes Into.hpp &.cpp Files? When a program is interfaced properly into.hpp and.cpp files: 1] Compilation Is Faster – compilers only compile those components that have been altered since the last compilation 2] Easier To Partition A Project For Teams 3] Reuse Opportunities Reduces Project Time/Cost - reuse opportunities increase when one develops and tests the class so well so general/generic that it can used in other projects 4] Assists In Better Design – it is difficult, if not impossible, to keep all of the details of a large system in mind at one time – by creating one self contained student class interface that has all of the functionality necessary for students, one can more easily abstract the Student object.

40

class Name { public: Name (char NewFirst[]="", char NewLast[]=""); private: char *First, *Last; long No; }; Indigenous Data - Data that is completely contained by the structure. (i.e. No) Exogenous Data - Data that is not part of the structure, but accessed through pointers that are in the structure. (i.e. First & Last) 41

42

Place A Copy Of Your Project Folder In C:\Temp Name The Folder Test! 43

This Should Be Your Main 44

Copy-Paste Copy ////////////////////////////////////////////////////////////////////////////////// // // File Main.cpp // // // Purpose : // // // Written By : Dr. Thomas E. Hicks Environment : Windows 7 // // Date : xx/xx/xxxx Compiler : Visual C++ // ////////////////////////////////////////////////////////////////////////////////// # include "Utilities.hpp" int main(int argc, char * argv[]) { int x = 5, y = 6; printf ("x = %d\n", x); printf ("y = %d\n", y); printf ("My Name Is %s\n\n", "Tom"); getchar(); return(0); } 45

Program Output - Not Real Impressive! 46

47

Open The Project Debug Folder Double-Click On The Executable Project.exe 48

Open The Project Debug Folder Double-Click On The Executable Project.exe 49

Program Output Outside Visual Studio Environment! - Not Real Impressive! 50

51

Copy The Executable File Location To The Clipboard CTRL-C 52

Launch A Command Window! 53

Enter cd (change directory) Right-Mouse-Click On Desktop - Select Paste cd Exactly Like Linux 54

We Are Now In Folder Housing Project.exe Type Project  Hit Enter Key 55

You Could Path To The Executable From Any Directory Location On The Binary Executable, Entering The.exe Extension Is Optional! Hit Return Key A Couple Times! 56

We Are Now In Folder Housing Project.exe Type Project  Hit Enter Key 57

58

Exactly Like Linux 59 Redirecting The Output Is Just Like We Do With C

Open The Output File 60

There Will Be Times I Want You To Print The Output From A Program. 61

62

Change Your Main To Include I/O 63

Copy-Paste Copy int main(int argc, char * argv[]) { int x, y; printf ("\nEnter x: "); scanf("%d", &x); fflush(stdin); printf ("\nEnter y: "); scanf("%d", &y); fflush(stdin); printf("\n"); printf ("x = %d\n", x); printf ("y = %d\n", y); printf ("My Name Is %s\n\n", "Tom"); getchar(); return(0); } 64

I Start The Program  But Where Is My Prompt for x? Going To The Output File Of Course! 65

Trickier! I have to know my program well enough to enter x & y without being asked! 66

Don't See Input & Output Together! "Type" is windows equivalent of Linux "cat" 67

Clearing The Console Window "cls" is windows equivalent of Linux "clear" 68

69

Matrix - Two dimensional array int X [5][2]; int x [NoRows] [NoCols]; STL - Standard Template Library - Has Libraries For String, Vector, Stacks, etc. 70

71