Introduction to Data Structures and Software Engineering

Slides:



Advertisements
Similar presentations
Introduction to C Programming
Advertisements

Software Testing. Quality is Hard to Pin Down Concise, clear definition is elusive Not easily quantifiable Many things to many people You'll know it when.
Programming Languages and Paradigms
SOFTWARE TESTING. INTRODUCTION  Software Testing is the process of executing a program or system with the intent of finding errors.  It involves any.
The Assembly Language Level
Programming Languages Marjan Sirjani 2 2. Language Design Issues Design to Run efficiently : early languages Easy to write correctly : new languages.
Chapter 7: User-Defined Functions II
CMSC 345, Version 11/07 SD Vick from S. Mitchell Software Testing.
6/10/2015C++ for Java Programmers1 Pointers and References Timothy Budd.
1 Chapter 4 Language Fundamentals. 2 Identifiers Program parts such as packages, classes, and class members have names, which are formally known as identifiers.
Illinois Institute of Technology
Chapter 6. 2 Objectives You should be able to describe: Function and Parameter Declarations Returning a Single Value Pass by Reference Variable Scope.
Chapter 1 Principles of Programming and Software Engineering.
Testing an individual module
Guide To UNIX Using Linux Third Edition
© 2006 Pearson Addison-Wesley. All rights reserved2-1 Chapter 2 Principles of Programming & Software Engineering.
C++ fundamentals.
1 Software Testing Techniques CIS 375 Bruce R. Maxim UM-Dearborn.
1 CSC241: Object Oriented Programming Lecture No 07.
Chapter 13 & 14 Software Testing Strategies and Techniques
Software Testing Sudipto Ghosh CS 406 Fall 99 November 9, 1999.
Software Testing Verification and validation planning Software inspections Software Inspection vs. Testing Automated static analysis Cleanroom software.
System/Software Testing
1 CISC181 Introduction to Computer Science Dr. McCoy Lecture 19 Clicker Questions November 3, 2009.
Modular Programming Chapter Value and Reference Parameters t Function declaration: void computesumave(float num1, float num2, float& sum, float&
High-Level Programming Languages: C++
CMSC 345 Fall 2000 Unit Testing. The testing process.
Software Testing.
CS4311 Spring 2011 Unit Testing Dr. Guoqiang Hu Department of Computer Science UTEP.
1 Debugging and Testing Overview Defensive Programming The goal is to prevent failures Debugging The goal is to find cause of failures and fix it Testing.
CSC3315 (Spring 2009)1 CSC 3315 Programming Languages Hamid Harroud School of Science and Engineering, Akhawayn University
Software Testing Testing types Testing strategy Testing principles.
Overloading Binary Operators Two ways to overload –As a member function of a class –As a friend function As member functions –General syntax Data Structures.
Software Testing. 2 CMSC 345, Version 4/12 Topics The testing process  unit testing  integration and system testing  acceptance testing Test case planning.
Hello.java Program Output 1 public class Hello { 2 public static void main( String [] args ) 3 { 4 System.out.println( “Hello!" ); 5 } // end method main.
Unit Testing 101 Black Box v. White Box. Definition of V&V Verification - is the product correct Validation - is it the correct product.
©Ian Sommerville 2004Software Engineering, 7th edition. Chapter 22 Slide 1 Software Verification, Validation and Testing.
CPSC 252 Concrete Data Types Page 1 Overview of Concrete Data Types There are two kinds of data types: Simple (or atomic) – represents a single data item.
Chapter 12: Pointers, Classes, Virtual Functions, and Abstract Classes.
What is Testing? Testing is the process of finding errors in the system implementation. –The intent of testing is to find problems with the system.
1 CSCD 326 Data Structures I Software Design. 2 The Software Life Cycle 1. Specification 2. Design 3. Risk Analysis 4. Verification 5. Coding 6. Testing.
A13. Testing Intro Data Structures & SE Computer Science Dept Va Tech Aug., 2001 © Barnette ND, McQuain WD 1 Levels of Verification The Unreachable.
Chapter 3 Top-Down Design with Functions Part II J. H. Wang ( 王正豪 ), Ph. D. Assistant Professor Dept. Computer Science and Information Engineering National.
© 2006 Pearson Addison-Wesley. All rights reserved2-1 Chapter 2 Principles of Programming & Software Engineering.
© 2006 Pearson Addison-Wesley. All rights reserved 2-1 Chapter 2 Principles of Programming & Software Engineering.
Software Engineering1  Verification: The software should conform to its specification  Validation: The software should do what the user really requires.
 In the java programming language, a keyword is one of 50 reserved words which have a predefined meaning in the language; because of this,
CS451 Lecture 10: Software Testing Yugi Lee STB #555 (816)
1 Classes II Chapter 7 2 Introduction Continued study of –classes –data abstraction Prepare for operator overloading in next chapter Work with strings.
Chapter 1 Software Engineering Principles. Problem analysis Requirements elicitation Software specification High- and low-level design Implementation.
HNDIT23082 Lecture 09:Software Testing. Validations and Verification Validation and verification ( V & V ) is the name given to the checking and analysis.
Testing Overview Software Reliability Techniques Testing Concepts CEN 4010 Class 24 – 11/17.
SOFTWARE TESTING LECTURE 9. OBSERVATIONS ABOUT TESTING “ Testing is the process of executing a program with the intention of finding errors. ” – Myers.
Verification vs. Validation Verification: "Are we building the product right?" The software should conform to its specification.The software should conform.
Defect testing Testing programs to establish the presence of system defects.
1 Software Testing. 2 What is Software Testing ? Testing is a verification and validation activity that is performed by executing program code.
Testing Integral part of the software development process.
Chapter 6 CS 3370 – C++ Functions.
Software Testing.
C++ Plus Data Structures
Software Engineering (CSI 321)
Chapter 3: Using Methods, Classes, and Objects
About the Presentations
Chapter 13 & 14 Software Testing Strategies and Techniques
Structural testing, Path Testing
UNIT-4 BLACKBOX AND WHITEBOX TESTING
Chapter 7 Additional Control Structures
Test Case Test case Describes an input Description and an expected output Description. Test case ID Section 1: Before execution Section 2: After execution.
UNIT-4 BLACKBOX AND WHITEBOX TESTING
Chapter 13 & 14 Software Testing Strategies and Techniques 1 Software Engineering: A Practitioner’s Approach, 6th edition by Roger S. Pressman.
Presentation transcript:

Introduction to Data Structures and Software Engineering CS 1704 Introduction to Data Structures and Software Engineering

Module 1 Outline What is Software Engineering? What is Requirements Engineering What is Design? Structure Charts What is Testing? Intro to Pointers Intro to ADT’s Intro to Classes

What does Correctness Mean? “Program correctness" is not easily defined. The programmer and user of a program may interpret "correctness" quite differently and hence have different expectations of program performance. Various interpretations of correctness are listed below in order of increasing difficulty of achievement:

Correctness Continued 1. The program contains no syntax errors that can be detected during translation by the language processor. 2. The program contains no errors, either of syntax or invalid operation, that can be automatically detected during translation or execution of the program.

Correctness Continued 3. There exists some set of test data for which the program will yield the correct answer. 4. For a typical (reasonable or random) set of test data the program will yield the correct answer.

Correctness Continued 5. For deliberately difficult sets of test data the program will yield the correct answers. 6. For all possible sets of data that are valid with respect to the problem specification, the program yields the correct answers.

Correctness Continued 7. For all possible sets of valid test data, and for all likely conditions of erroneous input, the program gives a correct (or at least reasonable) answer. 8. For all possible input, the program gives correct or reasonable answers.

Correctness Continued Some programmers never mature beyond level 3 in their attitude toward correctness. From the user's point of view a reasonable definition of correctness is certainly not less than level 6. Level 7 is better and level 8 is what he would really like. The programmer may maintain that a literal interpretation of problem specifications cannot demand more than level 6, while the user will maintain that certain implied requirements do not have to be explicitly stated.

Obtaining Correctness May be Incorrect Deskchecking Code traces Walkthrough Expert Review Board: Mental execution of text cases before the review board Code Inspections Programmer explains logic of code (statement by statement) formally to a peer group Demonstrated Some Correctness

Correctness is Unobtainable Demonstrated Some Correctness Testing Case data Computer aided Proof Formal (mathematical) Proven Correct

Discovered vs Undiscovered Errors Probability Increases as Number of Errors Increases Probability of Existence of More Errors Number of Errors Found to Date

Testing 40-50% of all development time is spent in the testing process Humans (programmers) are NOT good at testing. The process of testing admits that one has produced code with errors. Successful testing can be thought of as successfully finding errors and testing failure implies not discovering any errors "Testing can establish the presence of errors, but never their absence." -Edsger Dijkstra

Testing Phases Requirements Acceptance Test Specification High Level Design Low Level Design Coding Integration Testing Deployment Maintanence Acceptance Test Function Test System Test Test Unit Test Regression Test

Testing Phases Defined Regression Testing involves fixing errors during testing and the re-execution of all previous passed tests. Unit Testing utilizes module testing techniques (white-box / black-box techniques). Integration Testing involves checking subsets of the system. Acceptance, Function and System testing is performed upon the entire system.

Integration Testing Bottom-Up Testing Top-Down Testing Unit Test (Black & White box techniques) discovers errors in individual modules requires coding (& testing) of driver routines Top-Down Testing Main module & immediate subordinate routines are tested first requires coding of routine stubs to simulate lower level routines system developed as a skeleton

Integration Testing cont’d Sandwich Integration combination of top-down & bottom-up testing Big Bang No integration testing modules developed alone All modules are connected together at once

Function Testing Proof of Correctness vs. Testing Functional Verification Testing Establishes Level of Confidence Proof of Correctness

Function Testing cont’d Checks that the system satisfies its external specification Entire system is viewed as a "Black Box" Techniques: Boundary-value Analysis Cause-Effect Graphing

Function Testing cont’d Doesn’t verify that the requirements or user documentation are correct External Specifications Program Requirements User Documentation

Acceptance Testing Tests the program against the current needs of the users and its original objectives. Usually performed by the end user (customer) Contract may require, as part of acceptance test: performance tests (throughput, statistics collection, ...) stress tests (system limits) If performed by system developers may consist of  (alpha), (beta) testing

Acceptance Testing cont’d Is the user satisfied with final product? Program Requirements User Documentation External Specifications

Testing Example Program reads 3 integer values from a line. The 3 values represent the lengths of the sides of a triangle. The program outputs whether the triangle is equilateral, isosceles, or scalene. Write a set of test cases which would adequately test this program!

Test cases Valid scalene triangle. Valid equilateral triangle. Valid Isosceles triangle. All possible permutations of Isosceles triangles (e.g. (3,3,4) (3,4,3) (4,3,3)) One side having a zero value. One side having a negative value. Degenerate Triangle (e.g. 1-Dim  (1,2,3) All possible permutations of Degenerate Triangles (e.g. (1,2,3) (3,1,2) (1,3,2)) Invalid Triangle (e.g. (1,2,4)) All possible permutations of invalid triangles. All sides = 0. Non-integer values. Incorrect number of sides … 1 2 3

Exhaustive Testing How long will it take to try all possible inputs at a rate of one test/second? 232 tests * 1 second / test = 232 seconds = 232 / (60 * 60 * 24 * 365) years > 232 / (26 * 26 * 25 * 29 ) years = 232 / 226 years = 26 years = 64 years Impractical!!!

Goal of Testing No method (Black/White Box, etc.) can be used to detect all errors. Errors may exist due to a testing error instead of a program error. A finite number of test cases must be chosen to maximize the probability of locating errors. Perform testing to ensure that the probability of program/system failure due to undiscovered errors is acceptably small.

Testing Principles New test cases must be added as new errors are discovered. The test cases must be a demanding exercise of the component under test. Tests should be carried out by a third party independent tester, developer engineers should not privatize testing due to conflict of interest Testing must be planned as the system is being developed, NOT after coding. The expected output for each test case should be defined in advance of the actual testing. The test output should be thoroughly inspected. Test cases must be written for invalid & unexpected, as well as valid and expected input conditions. Test cases should be saved and documented for use during the maintenance / modification phase of the life cycle.

Drivers vs. Stubs Driver Test Case Valid Test Inputs Outputs Routine X Component Under Testing Required by X but NOT coded

White Box Testing Structural Testing Functional Description and actual implementation Correct I/O relationships are verified using: Structural Testing Exercise of Source code and internal data structures Test cases are derived from analysis of internal module logic and external module specifications

White Box: Logic Testing Statement Coverage Every statement is executed at least once. Decision Coverage Each decision is tested for TRUE & FALSE. Correctness of conditions within the decisions are NOT tested Condition Coverage Each condition in a decision takes on all possible outcomes at least once. Does not necessarily test all decision outcomes. Test cases do not take into account how the conditions affect the decisions.

White Box: Logic Testing cont’d Decision/Condition Coverage Satisfies both decision coverage and condition coverage. Does NOT necessarily test all possible combinations of conditions in a decision. Multiple Condition Coverage Test all possible combinations of conditions in a decision Does not test all possible combinations of decision branches. Eg: if (x >= 5 && y != 7 && z= =9) { ;//2^3=8 tests! }

White Box: Path Testing Exercise a program by testing all possible execution paths through the code. Method Enumerate the paths to be tested Find the Input Domain of each Select 1 or more test cases from domains Problem: Loops (  number of paths) Paths: ABC; ABBC; AB ... BC Solution: Restrict loop to N iterations Small number of paths that yield reasonable testing A C B D

Control Flow Graph Node: sequence of statements ending in a branch Arc: transfer of control

Exhaustive Path Testing (analogue of exhaustive input testing) requires executing the total number of ways of going from the top of the graph to the bottom approx. 100 trillion, where 5 = number of unique paths assuming all decisions are independent of each other specification errors could still exist does not detect missing paths does not check data-dependent errors

Test Path Determination Independent Path any path that introduces at least one new set of processing statements (nodes), i.e. it must traverse an edge not previously covered. Independent Paths: 1 - 2 - 6 1 - 2 - 3 - 5 - 2 - 6 1 - 2 - 3 - 4 - 5 - 2 – 6 2 6 3 1 4 5

Cyclomatic Complexity Upper bound on the number of independent paths, i.e. number of tests that must be executed in order to cover all statements. CC edges - Nodes + 2 = E - N + 2 = 7 - 6 + 2 = 3 2 6 3 1 4 5

When to Stop Testing When no more errors exist. (Impossible to ascertain.) (1) How reliable is the set of test cases? Data Domain (2) How reliable is the software being developed? Time Domain

When to Stop Testing When no more errors exist. (Impossible to ascertain.) (1) How reliable is the set of test cases? Data Domain (2) How reliable is the software being developed? Time Domain RELIABILITY Data Domain Time Coverage Mutation Analysis Error Seeding Shooman Jelinski-Moranda Musa

Reliability: Time Domain Time Domain Reliability MTBF : mean time between failures MTTF : mean time to failure MTTR: mean time to repair MTBF = MTTF + MTTR Availability = MTTF / (MTTF + MTTR) * 100 Estimate Methods: Predictions based on calendar time Predictions based on CPU time

Data Domain: Mutation Analysis Tests the test data Mutate Code to determine the adequacy of the test data. Determines whether all deliberately introduced (mutant) errors are detected by the original test cases.

Mutation Analysis cont’d Mutation Testing Process Program P is executed for test case T If errors occur test case T has succeeded Errors are corrected & retested until no errors with test case T are observed. Program is Mutated P’ Mutant P’ is executed for test case T IF no errors are found { test case T is inadequate; further testing is required; new test cases are added & step 3 is repeated until all mutations are discovered; entire process is started again at step 1 with the new test cases } ELSE { all mutations located by tests T T is adequate and no further testing is required}

Error Seeding Estimate of the number of original undiscovered errors remaining in a system. Intentionally introduce (seed) errors into the source code. Execute test cases upon source code. Count the number of seeded errors & original errors (unseeded errors) discovered. Estimate the total number of original errors

Error Scattergram Graph (mutations)

Debug Error Checking assert ( (index>=0) && (index < MAXDIM) ); The assert macro pseudo-function defined in <assert.h>, and <cassert>, (new style header), is used to check a condition, (pre-condition, post-condition, etc.). If the condition is false, assert prints an error message containing the line number, the condition tested, and the file name containing the assert, calls the abort function in <stdlib.h> and <cstdlib> to halt program execution. If the condition is true execution continues normally.

Debug Error Checking Release builds and assertions assert functions need not be removed after testing is complete. Defining the preprocessor symbolic constant NDEBUG will force the preprocessor to ignore all of the assertions. NDEBUG must be defined at the beginning of the program files. #define NDEBUG

Debug Error Checking Considerations Assertions do not allow for programs to recover from errors. It is good programming practice to precede all array accesses with assertions for bounds checking.

Command Line Parameters main(int argc, char* argv[]) When a program name is typed at the Operating System Line prompt, it is treated as a command. The name of the executable program file and any other strings typed on the line, (usually file names), are considered command line parameters. C/C++ compilers provide access to command line parameters.

Command Line Parameters Cont argc gives the number of command line parameters (arguments) that the user typed on the command line. always equals at least 1 for the command itself argv[] an array of pointers to C-style strings that holds the command line arguments. argv[0] holds the name of the program (command) may hold full pathname on some systems may be capitalized on DOS systems

Command Line Parameters Cont. #include <iostream> #include <cstdlib> // for EXIT_SUCCESS using namespace std; int main (int argc, char* argv[]) { cout << "argc = " << argc << endl; for (int i =0 ; i < argc; i++) { cout << "argv[ " << i << " ] = " << argv[i] << endl; } return EXIT_SUCCESS;

Module 1 Outline What is Software Engineering? What is Requirements Engineering What is Design? Structure Charts What is Testing? Intro to Pointers Intro to ADT’s Intro to Classes

Static Variables Size is fixed throughout execution Size is known at compile time Space/memory is allocated at execution

Dynamic Variables Created during execution "dynamic allocation" No space allocated at compilation time Size may vary Structures are created and destroyed during execution. Knowledge of structure size not needed Memory is not wasted by non-used allocated space. Storage is required for addresses.

Example of Pointers Assume: Notice: Houses represent data Addresses represent the locations of the houses. Notice: To get to a house you must have an address. No houses can exist without addresses. An address can exist without a house (vacant lot / NULL pointer)

Memory and Addresses On modern computers, memory is organized in a manner similar to a one-dimensional array: memory is a sequence of bytes (8 bits) each byte is assigned a numerical address, similar to array indexing addresses are nonnegative integers; valid range is determined by physical system and OS memory management scheme

Memory and Addresses OS (should) keep track of which addresses each process (executing program) is allowed to access, and attempts to access addresses that are not allocated to a process should result in intervention by the OS OS usually reserves a block of memory starting at address 0 for its own use addresses are usually expressed in hexadecimal (base 16), typically indicated by use of a prefix: 0xF4240

Memory Organization run-time stack used for statically allocated storage heap used for dynamically allocated storage

Pointer Type Simple type of variables for storing the memory addresses of other memory locations

Pointer Declaration Pointer Variables Declarations The asterisk ‘*’ character is used for pointer variable declarations: iptr is a pointer to an integer fptr is a pointer to a real recommended form int* iptr; float* fptr, fptr2; not a pointer common declaration int* iptr1, iptr2; not a pointer

Pointer Declaration Given the equivalent declaration: † Declares iptr1 to be a pointer variable, but iptr2 is a simple integer variable. Typedef declaration: † Declare all pointer variables in separate declaration statements. int* iptr1; int iptr2; typedef int* intPtr; intPtr iptr1;

Pointers in Memory 5 y yPtr 600000 yPtr 500000 5 y 600000

Pointer References “Address Of” Operator: & (ampersand) Unary operator that returns the hardware memory location address of it’s operand. Given: Address Assignment: int* iptr1; int* iptr2; int numa, numb; numa = 1; numb = 2; iptr1 = &numa; iptr2 = &numb;

“Contents of” Operator Dereference / Indirection Operator: * (asterisk) unary ‘pointer’ operator that returns the memory contents at the address contained in the pointer variable. Pointer Output: (Possible) results: cout << iptr1 << *iptr1 << endl; cout << iptr2 << *iptr2 << endl; 0xF4240 1 0x3B9ACA00 2

NULL Pointer Pointer constant, address 0 Named constant in the <cstddef> include header (<stddef.h> old style header). Represents the empty pointer points nowhere , unique pointer/address value Illegal: NEVER dereference a pointer that equals NULL *NULL

*NULL

Module 1 Outline What is Software Engineering? What is Requirements Engineering What is Design? Structure Charts What is Testing? Intro to Pointers Intro to ADT’s Intro to Classes

Intro to ADT’s Data Type Types a collection of related data elements plus operations that can be performed upon values of the data type. Types Built-In (Language Defined) Array, Structures (Records), Classes Programmer Defined, Abstract Data Types (ADT) Lists, Stacks, Queues

ADT Views Application Abstract (Logical) Implementation (Physical) usage in a particular program (variant box view) Abstract (Logical) organization viewed by the user (black box view) Implementation (Physical) coding methods used to represent the data and the operations (open box view)

Example Two-Dimensional Array Application View: maze, surface points Logical View: table, matrix Physical View Stored sequentially (implies logical to physical mapping) Index Limits (L1 .. U1, L2 .. U2) Length = (U1 - L1 + 1)*(U2 - L2 + 1)

Accessing Column Major: all elements in a column are stored in sequence FORTRAN and Java - Column Major Row Major: all elements in a row are stored in sequence “C” , PASCAL - Row Major

Row Major Accessing: Location of [i] [j] element (Row Major) + [ (U2-L2+1) * (i-L1) + (j-L2) ] * size of element  = base address of array (U2 - L2 + 1) = Size of Column (i - L1) = number of columns to skip (j - L2) = number of rows to skip 1,1 1,2 1,3 1,4 2,1 2,2 2,3 2,4 3,1 3,2 3,3 3,4 Logical user view mappings

Row vs. Column Major 1,1 1,2 1,3 1,4 2,1 2,2 2,3 2,4 3,1 3,2 3,3 3,4 Physical (row-major) compiler programmer linear view  1,1 2,1 3,1 1,2 2,2 3,2 1,3 2,3 3,3 1,4 2,4 3,4 Physical (column-major) compiler programmer linear view 

ADT New data type defined by programmer Includes: † Set of Data Objects † Set of Abstract Operations create empty delete insert object

Data Abstraction Design of abstract data objects and operations upon those objects. Abstraction in programming separates a data type’s logical properties from its implementation.

Information Hiding Used in the design of functions and new data types. Each component should hide as much information as possible from the users of the component (function). Implementation details are hidden from the user by providing access through a well-defined communication interface.

Encapsulation the bundling of data and actions in such a way that the logical properties of the data and actions are separated from the implementation details [Dale]. access to an ADT is restricted to a specified set of supplied operations Implies: † User has no "Need to Know" † User may not directly manipulate data elements Advantages † Changes to the underlying operators or representations does not affect code in a client of the data type † Extends programming languages

Info Hiding vs Encapsulation Information Hiding a question of program design In many cases: Language Supported (functions, procedures) Encapsulation a question of language design "...an abstraction is effectively encapsulated only when the language prohibits access to information hidden within the abstraction." Ada packages C++ classes † “C” modules

Module 1 Outline What is Software Engineering? What is Requirements Engineering What is Design? Structure Charts What is Testing? Intro to Pointers Intro to ADT’s Intro to Classes

Rationale for Classes The aim of the C++ class construct is to provide the programmer with a tool for creating new types that can be used as conveniently as the built-in types. A type is a concrete representation of a concept. For example, the C++ built-in type double with its operations +, -, *, etc., provides a concrete approximation of the mathematical concept of a real number. A class is a user-defined type.

Rationale for Classes We design a new type to provide a definition of a concept that has no counterpart among the built-in types. A program that provides types that closely match the concepts of the application tends to be easier to understand and to modify than a program that does not. A well-chosen set of user-defined types makes a program more concise. In addition, it makes many sorts of code analysis feasible. In particular, it enables the compiler to detect illegal uses of objects that would otherwise remain undetected until the program is thoroughly tested.

The C++ Class Type The C++ class type provides a means to encapsulate heterogeneous data elements and the operations that can be performed on them in a single entity. A class type is like a struct type in that it may contain data elements, called data members, of any simple or structured type. A class type may also contain functions, called function members or methods, that may be invoked to perform operations on the data members.

The C++ Class Type The class type also provides mechanisms for controlling access to members, both data and function, via the use of the keywords public, private and protected. (Default access mode is private.) A variable of a class type is referred to as an object, or as an instance of the class. The struct language construct was extended to make it equivalent with a class, except its members are by default public. While structs may be used the same as classes they are rarely employed as such.

A Simple Date Class class DateType { public: void Initialize(int newMonth, int newDay, int newYear); int YearIs( ) const; // returns year int MonthIs( ) const; // returns month int DayIs( ) const; // returns day private: int Year; int Month; int Day; }; Indicates Fn is a const member and cannot change any data member values.

A Simple Date Class The DateType class incorporates three data members, Year, Month, and Day, and four function members. Note the class type declaration defines a data type — it does not declare a variable of that type. Also note that the class type declaration above includes only prototypes of the function members, not their definitions.

Simple Date Class Continued Given the class type declaration, a user may declare variables of that type in the usual way: DateType Today, Tomorrow, AnotherDay; No default initializations are performed. It is up to the user to assign values to the data members of these variables.

Simple Date Class Continued The data members of the DateType class are declared as being private. The effect is that the data members cannot be accessed in the way fields of a struct variable are accessed: Today.Month = 9; will generate a compile-time error. A user of a DateType variable may access only those members which were declared public. So, the user could initialize Today by using the public member function Initialize( ): Today.Initialize(9, 28, 1998);

Simple Date Class Continued Similarly, a user can only obtain the value of the Year member by using the public member function YearIs( ): int ThisYear = Today.YearIs( ); Note the use of the field selection operator ‘.’.

Module 1 Outline Completed What is Software Engineering? What is Requirements Engineering What is Design? Structure Charts What is Testing? Intro to Pointers Intro to ADT’s Intro to Classes