Programming Basics.


134 views
Uploaded on:
Category: Fashion / Beauty
Description
Programming Essentials. ECE573: Information Structures and Calculations Electrical and PC Building Dept. Rutgers College http://www.cs.rutgers.edu/~vchinni/dsa/. Course Diagram. Target To show you how to program productively Requirements
Transcripts
Slide 1

Programming Fundamentals ECE573: Data Structures and Algorithms Electrical and Computer Engineering Dept. Rutgers University http://www.cs.rutgers.edu/~vchinni/dsa/

Slide 2

Course Overview Objective To show you how to program productively Prerequisites You know the nuts and bolts of programming in C, C++ or Java Can compose, investigate and run basic projects in C/C++/Java, and Have some straightforward comprehension of item arranged configuration

Slide 3

What is a Good Program? Run accurately Run as per the particulars Run productively In least time? Different limitations: Memory utilization? How? Utilization fitting information structures and calculations Algorithm: A definitely indicated method for taking care of an issue Easy to peruse and see Easy to troubleshoot Easy to adjust (simple to look after) Portability? Center Software Engineering Building vast SW frameworks Reliable & simple to look after

Slide 4

Programming Strategies Modularity Decompose a system into suitable little modules Test them before consolidating them into bigger modules Management is less difficult How to parcel a huge errand? Deliberation An abnormal state perspectives of articles or capacities  Enables us to disregard low level subtle elements and focus on issues within reach

Slide 5

Example Truck Manufacturer Computer to control motor operation Load Sensors Computer CPU Sensor interface Fuel Control Engine Speed Interrupt Handler Memory Air Flow Pedal Position I/O Interface ROM Clock Air Temperature SW

Slide 6

Example Truck Manufacturer Computer to control motor operation Load Sensors Computer CPU Sensor interface Fuel Control Engine Speed Interrupt Handler Memory Air Flow Pedal Position I/O Interface ROM Clock Air Temperature “When the quickening agent pedal is half discouraged, air and fuel valves ought to be opened until the motor velocity comes to 2500 rpm”

Slide 7

Example Transportation Company Abstract perspective of a truck Just a method for transporting merchandise from point A to point B in the min time permitted by the street activity and so forth. Determinations? “The truck, when weighed down with 10 tons, should require close to 2 Gallons of fuel to travel100 miles when going at 60mph” How it is accomplished is superfluous. Does not make a difference whether there is a control PC or different contraptions.

Slide 8

Types of Abstraction Functional Abstraction Specify a capacity for a module, i.e., “This module will sort the things in its information stream into rising request in light of a requesting standard for the things and spot them on its yield stream” Structural Abstraction Known as Object Orientation Construct programming models of the conduct of true things Truck producer: To break down execution of his vehicle, utilizes SW model of the control PC He is just worried with outside conduct of the PC

Slide 9

Objects Abstract Data Types Collection of information structure and an accumulation of capacities or methodology which work on the information structure Functions & Procedures  Methods Data structure and its routines  Class Instance of a class  Object Objects speak to questions in this present reality and show up in projects as variables of a sort characterized by the class OO extra: Inheritance and so on. Object introduction is an outline approach! Conceivable: OO projects utilizing C, Pascal and so forth. C++ give extra compiler backing to OO outline This bolster must be given by the developer in non-OO dialects OO Terminology

Slide 10

Example: Collections may be sorted out from numerous points of view May utilize distinctive system structures to speak to them Yet, from a unique perspective basic operations may incorporate Create Create another gathering Add Add another thing to an accumulation Delete Delete a thing from an accumulation Find Find a thing coordinating some basis in the gathering Destroy Destroy the accumulation

Slide 11

Constructors and Destructors Constructors and destructors The make and crush techniques –often called constructors and destructors-regularly actualized for any theoretical information sort Specific applications may require extra routines: Ex: join two accumulations “One of the points of good program configuration would be to guarantee that extra necessities are effortlessly handled”

Slide 12

Data Structure Name of an information sort – kind of articles that have a place with the accumulation class; typedef struct collection_struct * gathering We are characterizing pointer to a structure We have not determined subtle elements of the structure\'s traits We will have the capacity to substitute diverse information structures for the genuine usage of the gathering We can proclaim objects of sort gathering

Slide 13

Methods gathering ConsCollection (int max_items, int item_size) void AddToCollection (accumulation c, void *item) void DeleteFromCollection ( gathering c, void * itme); void * FindInCollection (accumulation c, void *key); C is not precisely the most secure programming dialect in the bolster\'s feeling it accommodates the designing of value programming As we expected that our accumulation article is a pointer to a structure, we accept the article which has a place with the accumulation are additionally spoken to by pointers to information structures Void * will coordinate any pointer Void * highlights the inadequacies of C: it doesn’t give the ability to make bland articles .

Slide 14

Pre-and Post-conditions Formal determination obliges pre-and post-conditions It is an agreement between the item and its customer Pre-conditions: State of the system which the customer assurances will be valid before calling any strategy Post-conditions: State of the project that the object’s technique will promise to make for you when it returns C gives NO FORMAL SUPPORT to this Use attest capacity Express pre-and post conditions as remarks with the strategy definition

Slide 15

Assert: man pages NAME affirm - program check SYNOPSIS #include <assert.h> assert(expression) DESCRIPTION declare() is a full scale that demonstrates expression is relied upon to be valid as of right now in the project. In the event that expression is false (0), it shows an indicative message on the standard yield and ways out.

Slide 16

/* Specification for Collection */typedef struct t_Collection *Collection; Collection ConsCollection( int max_items, int item_size );/* Construct another Collection Pre-condition: max_items > 0 Post-condition: gives back a pointer to a vacant Collection */void AddToCollection( Collection c, void *item );/* Add a thing to a Collection Pre-condition: (c is a Collection made by a call to ConsCollection) && (existing thing check < max_items) && (thing != NULL) Post-condition: thing has been added to c */

Slide 17

void DeleteFromCollection( Collection c, void *item );/* Delete a thing from a Collection Pre-condition: (c is a Collection made by a call to ConsCollection) && (existing thing number >= 1) && (thing != NULL) Post-condition: thing has been erased from c */void *FindInCollection( Collection c, void *key );/* Find a thing in a Collection Pre-condition: c is a Collection made by a call to ConsCollection key != NULL Post-condition: gives back a thing recognized by key if one exists, generally returns NULL */

Slide 18

More formal pre-and post-conditions No copies: things with same key can\'t be added to the accumulation

Slide 19

/* Specification of a gathering which contains one of a kind things just; Assumes that the things of which the gathering is made supply an ItemKey technique which gives back the pointer to a distinguishing key for the thing */typedef struct u_collection_struct *u_collection; u_collection ConsUCollection( int max_items );/* Construct another accumulation Pre-condition: None Post-condition: gives back a pointer to a vacant accumulation */void AddToUCollection( u_collection c, void *item );/* Add a thing to an accumulation Pre-condition: (c was made by a call to ConsUCollection) && (thing != NULL) && (FindInUCollection(c, ItemKey (item))==NULL) Post-condition: FindInUCollection(c, ItemKey (thing)) != NULL */

Slide 20

void DeleteFromUCollection( u_collection c, void *item );/* Delete a thing from a gathering Pre-condition: (c was made by a call to ConsUCollection) && (thing != NULL) && (FindInUCollection(c, ItemKey (thing)) != NULL) Post-condition: FindInUCollection(c, ItemKey (thing)) == NULL */void *FindInUCollection( u_collection c, void *key );/* Find a thing in an accumulation Pre-condition: c is an accumulation made by a call to ConsCollection key != NULL Post-condition: gives back a thing distinguished by key if one exists, generally returns NULL */

Slide 21

C traditions .h document Specifications which a client or customer of the article needs to see – are regularly put in this record with .h addition to its name For the gathering, we would put the specs in records called collection.h and Ucollection.h Use Cs #include office to import them into projects which expected to utilize them. .c document The usage or body of the class is put in a record with a .c addition

Slide 22

Error Handling Unexpected system disappointments are a debacle If a mistake is deadly  i.e., if the project can\'t sensibly proceed with, then the system must have the capacity to “ bite the dust effortlessly ” Inform its client why it passed on, and Save however much of the system state as could be expected What is a slip? Watchful particular of every product segment is a necessity Pre-states of a strategy will determine the conditions of a framework which a technique has the capacit

Recommended
View more...