Data Structure Introduction Dr. Bernard Chen Ph.D. University of Central Arkansas Spring 2009 Software Development Hardware: actual physical components (such as CPU, memory, hard drive…) Software: refers to programs used to control the operation of the hardware. Software Development Phases Problem Analysis and Specification Design Coding Testing, Execution, and Debugging Maintenance Software Development Model One of the earliest strategies for development software is known as the Waterfall Model Waterfall Model Realistic Waterfall Model Software Development Phases Problem Analysis and Specification Design Coding Testing, Execution, and Debugging Maintenance Problem Analysis and Specification Problem Analysis and Specification: The problem is analyzed and a specification for the problem is formulated For example: if we obtain a job request looks like: Task Example Because of new government regulations, we must keep more accurate record of all students currently receiving financial aid and submit regular report to FFAO (Federal Financial Aid Office). Could we get the computer to do this for us??? Task Analysis Purpose Pre-condition (input): describe the state of processing before the program is executed Post-condition (output): describe the state of processing after the program is executed Software Development Phases Problem Analysis and Specification Design Coding Testing, Execution, and Debugging Maintenance Design Design: A plan for solving the problem is formulated Various design methods have been developed, two of major designs we describe here: top-down design and object-oriented design Top-down design 1. 2. 3. The original problem is partitioned into simpler sub-problems For example, the problem we just had can be obviously divided into: Get the student records Process the records Prepare the reports One level partition Two level partition Three level partition OOD:Object-Oriented Design Identify the objects in the problem's specification and their types. Identify the operations or tasks to manipulate the objects Program=Algorithm + Data Structure Algorithm: “a step by step procedure for solving a problem or accomplishing some end” In computer science, algorithm must be: 1. 2. 3. Definite, unambiguous Simple Finite Software Development Phases Problem Analysis and Specification Design Coding Testing, Execution, and Debugging Maintenance Coding 1. 2. 3. There’s not much we can talk in coding, you all know what it is. After you select the language, three major principles you need to follow: Programs and Subprograms should be well structured All source code should be documented It should be formatted in a style that enhances its readability Software Development Phases Problem Analysis and Specification Design Coding Testing, Execution, and Debugging Maintenance Testing, Execution, and Debugging 1. 2. 3. Errors happen all the time!!! There are three different points at which errors can be introduced: Syntax errors Run-time errors Logic errors The "V" Life Cycle Model Two major types of testing Black box testing: Outputs produced for various inputs Checked for correctness Do not consider structure of program component itself. (so basically, it just test a lot of different inputs and match with the expected outputs ) Two major types of testing White box testing: examine code’s internal structure (Test for every loop, if statement, functions…) Test data is carefully selected Software Development Phases Problem Analysis and Specification Design Coding Testing, Execution, and Debugging Maintenance Maintenance After the software has been used for several years, they will require modifications Studies show that a higher percentage of computing budgets and programmer time are devoted to software maintenance 1970s 35-40% 1980s 40-60% 1990s 70-80% 2000s 80-90% Chapter 1 Arrays, Pointers, and Structures Dr. Bernard Chen Ph.D. University of Central Arkansas Spring 2009 Outline Arrays (first-class arrays, using vector) Strings (using string) Pointers Dynamic allocation Reference variables and parameter passing mechanisms Structures 1.1 What are Arrays, Pointers, and Structures? Aggregate: collection of objects stored in one unit Arrays: indexed collections of identical-type objects. (aggregate) Pointers: objects are used to access other objects. Structures: collections of objects that need not be of the same type. (aggregate) 1.2 Arrays and Strings Arrays: indexed collections of identical-type objects. Array always start on 0 Arrays can be used in two different ways: primitive arrays and vectors. Vectors vs. Primitive Arrays Vector has variable size and supports many manipulation functions Primitive Array has fixed size, and support only a few of manipulation functions. Vectors #include <vector> Declaration: vector<type> identifiers(size); Example: vector<int> a(3); Vector can be indexed as an array, using [ ] Vectors Vector member functions: vector<int> v(10); v.at() v.size() v.front() v.back() v.clear() v.empty() v.resize( val ) v.pop_back() v.push_back( val ) v.capacity() // equal to v[ ] // return the number of elements in v // return the first element in v // return the last element in v // delete all the element in v // return 1 if v is empty; else return 0 // change size of v to val // remove the last element in v // appends val to the end of v // return the number of element that vector can hold before it will need to allocate more space How to do Vector’s resize Example: vector<int> arr(10); arr.resize(12); Vector example #include <iostream> #include <vector> using namespace std; int main() { vector<int> aa(3); cout<<"Hellow World!!!!!!!"<<endl; aa[0]=0; aa[1]=1; aa[2]=2; for(int i=0; i<aa.size(); i++) cout<<aa[i]<<endl; } char myLine[100]; cin.getline(myLine,100); Strings #include<string> string s=“Hello World!”; Int size=s.length(); cout<< s[4] <<endl; // result:“o” cout<< s <<endl; s.c_str() returns a ‘\0’ terminated primitive character array. +, +=: concatenation
© Copyright 2024 Paperzz